Add launchable
This commit is contained in:
@@ -5,7 +5,7 @@ let instanceCounter = 0;
|
||||
export class Instance {
|
||||
constructor(className = "Instance") {
|
||||
this.ClassName = className;
|
||||
this.Name = `${className}${instanceCounter++}`;
|
||||
this.Name = `${className}`;
|
||||
this.Parent = null;
|
||||
this.Children = [];
|
||||
this.InstanceId = guidGenerator(); // Unique identifier, used for replication
|
||||
@@ -120,4 +120,21 @@ export class Instance {
|
||||
console.warn("Destroy: No DataModel found in ancestry. Are you destroying an unparented instance?");
|
||||
}
|
||||
} // Garbage collected after this
|
||||
|
||||
LuaBridge(exclude, visited = new Set()) { // Convert to a plain object for LuaBridge. Should be overridden in subclasses to add properties.
|
||||
if (visited.has(this.InstanceId)) {
|
||||
// Already visited, avoid circular reference
|
||||
return null;
|
||||
}
|
||||
visited.add(this.InstanceId);
|
||||
const obj = {
|
||||
ClassName: this.ClassName,
|
||||
Name: this.Name,
|
||||
InstanceId: this.InstanceId,
|
||||
Properties: {},
|
||||
Children: this.Children.filter(c => c !== exclude).map(c => c.LuaBridge(this, visited)).filter(Boolean),
|
||||
Parent: this.Parent && this.Parent !== exclude ? this.Parent.LuaBridge(this, visited) : null // Avoid circular reference by excluding self
|
||||
};
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user