rott/kf_sources/AcediaCore/Classes/EntityRef.uc
2026-07-14 20:27:09 +07:00

65 lines
2.3 KiB
Ucode

/**
* Author: dkanus
* Home repo: https://www.insultplayers.ru/git/AcediaFramework/AcediaCore
* License: GPL
* Copyright 2024 Anton Tarasenko
*------------------------------------------------------------------------------
* This file is part of Acedia.
*
* Acedia is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License, or
* (at your option) any later version.
*
* Acedia is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Acedia. If not, see <https://www.gnu.org/licenses/>.
*/
class EntityRef extends AcediaObject
abstract;
var private Text templateName;
var private Entity entityReference;
/// Destroys the currently referred to entity and attempts to create a new one
/// from the provided template.
///
/// This function's main purpose is to make [`EntityRef`] usable for automating
/// creation of sub-entities for a component.
/// Indeed, when an entity is created from a template, following happens:
///
/// 1. All components from the template are copied into the new entity as-is,
/// i.e. like [`Component::Copy`] would.
/// 2. If any of these components contain [`EntityRef`] objects, then
/// [`EntityRef::Recreate`] is called for them, therefore creating and
/// storing sub-entities.
///
/// Main example where this is necessary is a weapon component.
/// It contains arrays with references to firing entities, which must be
/// created anew for each new weapon.
public function Recreate();
/// Returns template for creating an entity when [`EntityRef::Recreate`]
/// method is called.
public final function Text GetDefaultTemplate() {
if (templateName != none) {
return templateName.Copy();
}
return none;
}
/// Returns reference to stored [`Entity`], if any is stored.
public final function Entity Get() {
if (entityReference != none) {
entityReference.NewRef();
return entityReference;
}
return none;
}
defaultproperties {
}