diff --git a/example/src/shared/start.luau b/example/src/shared/start.luau index e1b9608..c8651d5 100644 --- a/example/src/shared/start.luau +++ b/example/src/shared/start.luau @@ -26,6 +26,7 @@ local function start(containers) local cx = { world = world, state = state, widgets = debugger:getWidgets() } local loop = Matter.Loop.new(cx) + loop:setWorlds({ world }) -- Set up hot reloading diff --git a/lib/debugger/debugger.luau b/lib/debugger/debugger.luau index bf5b410..1172c6f 100644 --- a/lib/debugger/debugger.luau +++ b/lib/debugger/debugger.luau @@ -271,16 +271,6 @@ function Debugger:_enable() return end - -- TODO: Find a better way for the user to specify the world. - if not self.debugWorld then - for _, object in self.loop._state do - if getmetatable(object) == World then - self.debugWorld = object - break - end - end - end - self.enabled = true self.loop.profiling = self.loop.profiling or {} diff --git a/lib/debugger/ui.luau b/lib/debugger/ui.luau index aa671a1..add2474 100644 --- a/lib/debugger/ui.luau +++ b/lib/debugger/ui.luau @@ -41,12 +41,13 @@ local function ui(debugger, loop) }) local objectStack = plasma.useState({}) - local worldViewOpen, setWorldViewOpen = plasma.useState(false) - local worldExists = debugger.debugWorld ~= nil + local worldViewOpen, setWorldViewOpen = plasma.useState() - if debugger.hoverEntity and worldExists then - if debugger.debugWorld:contains(debugger.hoverEntity) then - custom.hoverInspect(debugger.debugWorld, debugger.hoverEntity, custom) + if debugger.hoverEntity then + for _, world in loop._worlds do + if world:contains(debugger.hoverEntity) then + custom.hoverInspect(world, debugger.hoverEntity, custom) + end end end @@ -79,25 +80,33 @@ local function ui(debugger, loop) local items = {} - for index, object in loop._state do - if type(object) ~= "table" then - continue - end + for index, world in loop._worlds do + local selected = worldViewOpen == index - local isWorld = getmetatable(object) == World + table.insert(items, { + index = index, + text = "World " .. index, + icon = "🌐", + object = world, + selected = selected, + isWorld = true, + }) + end - local selected = (#objectStack > 0 and object == objectStack[#objectStack].value) - or (debugger.debugWorld == object and worldViewOpen) + for index, value in loop._state do + if type(value) ~= "table" then + continue + end - local name = debugger.loopParameterNames[index] - local defaultName = (if isWorld then "World" else "table") .. " " .. index + local selected = (#objectStack > 0 and value == objectStack[#objectStack].value) table.insert(items, { - text = if name then name else defaultName, - icon = if isWorld then "🌐" else "{}", - object = object, + index = index, + text = "table " .. index, + icon = "{}", + object = value, selected = selected, - isWorld = isWorld, + isWorld = false, }) end @@ -105,12 +114,10 @@ local function ui(debugger, loop) if selectedState then if selectedState.isWorld then - if worldViewOpen and debugger.debugWorld == selectedState.object then - debugger.debugWorld = nil - setWorldViewOpen(false) + if worldViewOpen == selectedState.index then + setWorldViewOpen(nil) else - debugger.debugWorld = selectedState.object - setWorldViewOpen(true) + setWorldViewOpen(selectedState.index) end else local previousFirstValue = if objectStack[1] then objectStack[1].value else nil @@ -228,16 +235,16 @@ local function ui(debugger, loop) end) debugger.parent = custom.container(function() - if debugger.debugWorld and worldViewOpen then - local closed = custom.worldInspect(debugger, objectStack) + if worldViewOpen then + local closed = custom.worldInspect(debugger, loop._worlds[worldViewOpen], objectStack) if closed then - setWorldViewOpen(false) + setWorldViewOpen(nil) end end - if debugger.debugWorld and debugger.debugEntity then - custom.entityInspect(debugger) + if worldViewOpen and debugger.debugEntity then + custom.entityInspect(debugger, loop._worlds[worldViewOpen]) end if #objectStack > 0 then diff --git a/lib/debugger/widgets/entityInspect.luau b/lib/debugger/widgets/entityInspect.luau index 817f87a..b6d9449 100644 --- a/lib/debugger/widgets/entityInspect.luau +++ b/lib/debugger/widgets/entityInspect.luau @@ -3,7 +3,7 @@ local formatTable = formatTableModule.formatTable local FormatMode = formatTableModule.FormatMode return function(plasma) - return plasma.widget(function(debugger) + return plasma.widget(function(debugger, world) local style = plasma.useStyle() local closed = plasma @@ -11,7 +11,7 @@ return function(plasma) title = string.format("Entity %d", debugger.debugEntity), closable = true, }, function() - if not debugger.debugWorld:contains(debugger.debugEntity) then + if not world:contains(debugger.debugEntity) then debugger.debugEntity = nil return end @@ -28,7 +28,7 @@ return function(plasma) plasma.row(function() if plasma.button("despawn"):clicked() then - debugger.debugWorld:despawn(debugger.debugEntity) + world:despawn(debugger.debugEntity) debugger.debugEntity = nil end end) @@ -39,7 +39,7 @@ return function(plasma) local items = { { "Component", "Data" } } - for component, data in debugger.debugWorld:_getEntity(debugger.debugEntity) do + for component, data in world:_getEntity(debugger.debugEntity) do table.insert(items, { tostring(component), formatTable(data, FormatMode.Long), diff --git a/lib/debugger/widgets/worldInspect.luau b/lib/debugger/widgets/worldInspect.luau index 094ae13..a23c0ec 100644 --- a/lib/debugger/widgets/worldInspect.luau +++ b/lib/debugger/widgets/worldInspect.luau @@ -5,11 +5,9 @@ local BY_COMPONENT_NAME = "ComponentName" local BY_ENTITY_COUNT = "EntityCount" return function(plasma) - return plasma.widget(function(debugger, objectStack) + return plasma.widget(function(debugger, world, objectStack) local style = plasma.useStyle() - local world = debugger.debugWorld - local cache, setCache = plasma.useState() local sortType, setSortType = plasma.useState(BY_COMPONENT_NAME)