feat(rbxl): XML-������ ������ .rbxl + Day/Night + Tool/Mouse/Backpack flow #38

Closed
min wants to merge 39 commits from feat/rbxl-xml-parser-import into main
2 changed files with 24 additions and 2 deletions
Showing only changes of commit 3e20107125 - Show all commits

View File

@ -129,11 +129,17 @@ export class LuaSharedSandbox {
// Регистрируем coroutine в __rbxl_coroutines с id для возобновления.
// Скрипт оборачиваем в coroutine. task.wait()→coroutine.yield(sec) возвращает
// delay из resume → планируем следующий resume через scheduleResume.
// Fallback Parent = workspace для скриптов без target (или с невалидным
// target). Это спасает массу Roblox-скриптов которые делают
// script.Parent.Parent — если бы Parent был nil, упало бы сразу.
const parentExpr = primId != null
? `(__rbxl_get_part_by_id(${Number(primId)}) or workspace)`
: 'workspace';
const wrapped = `
do
local script = {
Name = ${JSON.stringify(scriptName)},
Parent = ${primId != null ? `__rbxl_get_part_by_id(${Number(primId)})` : 'nil'},
Parent = ${parentExpr},
ClassName = "Script",
Disabled = false,
Source = nil,

View File

@ -191,7 +191,23 @@ function makeInstanceMethods() {
while (p) { if (p.ClassName === cls) return p; p = p.Parent; }
return undefined;
},
WaitForChild: function (name) { return this.FindFirstChild(name); },
WaitForChild: function (name) {
// В Roblox WaitForChild блокирует пока ребёнок не появится. У нас
// нет yield с произвольных JS-функций, поэтому возвращаем либо
// существующего ребёнка, либо ленивый stub-Folder чтобы избежать
// падений типа "attempt to index a nil value" в импортированных
// скриптах. Stub автоматически добавляется в Children.
const existing = this.FindFirstChild(name);
if (existing) return existing;
try {
const stub = newInstance('Folder', String(name));
stub.Parent = this;
if (this.Children) this.Children.push(stub);
return stub;
} catch (_) {
return undefined;
}
},
IsA: function (cls) { return this.ClassName === cls || cls === 'Instance'; },
GetFullName: function () {
const parts = [];