diff --git a/frontends/nextjs/src/lib/lua/ui/load-lua-ui-package.ts b/frontends/nextjs/src/lib/lua/ui/load-lua-ui-package.ts index e1209f47d..165410c6e 100644 --- a/frontends/nextjs/src/lib/lua/ui/load-lua-ui-package.ts +++ b/frontends/nextjs/src/lib/lua/ui/load-lua-ui-package.ts @@ -4,6 +4,7 @@ import * as fengari from 'fengari-web' import { createLuaEngine } from '@/lib/lua/engine/core/create-lua-engine' import { pushToLua } from '@/lib/lua/functions/converters/push-to-lua' import { fromLua } from '@/lib/lua/functions/converters/from-lua' +import { normalizeLuaComponent } from './normalize-lua-structure' import type { LuaUIManifest, LuaUIPackage, LuaUIPage, LuaUIComponent } from './types/lua-ui-package' const lua = fengari.lua @@ -67,8 +68,9 @@ export async function loadLuaUIPackage(packagePath: string): Promise { + const num = Number(key) + return Number.isInteger(num) && num >= 1 + }) + + if (isLuaArray && keys.length > 0) { + // Convert to JavaScript array + const arr: any[] = [] + const sortedKeys = keys.map(Number).sort((a, b) => a - b) + + for (const key of sortedKeys) { + arr.push(normalizeLuaStructure(value[key])) + } + + return arr + } + + // Otherwise, recursively normalize the object + const normalized: any = {} + for (const key of keys) { + normalized[key] = normalizeLuaStructure(value[key]) + } + + return normalized + } + + return value +} + +/** + * Normalize a LuaUIComponent structure + */ +export function normalizeLuaComponent(component: any): LuaUIComponent { + return normalizeLuaStructure(component) as LuaUIComponent +}