local imgui = require("imgui") local Action = require("node.action") local Condition = require("node.condition") local function coro_test (action) for i=0,100 do action.progress = i/100 coroutine.yield( ) end end local function coro_test_longer (action) for i=0,400 do action.progress = i/400 coroutine.yield( ) end end local array = { Action(coroutine.create( coro_test )), Action(coroutine.create( coro_test )), Action(coroutine.create( coro_test )), Condition("and", {Action(coroutine.create( coro_test )), Action(coroutine.create( coro_test_longer ))}), Condition("and", {Action(), Action(coroutine.create(function() coroutine.yield() end))}), Condition("and", {Action(coroutine.create(function() coroutine.yield() end)), Action(coroutine.create(function() coroutine.yield() end))}), Condition("or", {Action(coroutine.create( coro_test )), Action(coroutine.create( coro_test_longer ))}), Condition("or", {Action(), Action(coroutine.create(function() coroutine.yield() end))}), Condition("or", {Action(coroutine.create(function() coroutine.yield() end)), Action(coroutine.create(function() coroutine.yield() end))}) } for i,node in ipairs(array) do node.id = i end local selected_node = nil function not_in(v,t) for k,e in ipairs(t) do if v == e then return false end end return true end function draw_array() imgui.Begin("Array") imgui.BeginChild("", 0,0, true) imgui.Columns(2) for i,node in ipairs(array) do local current_selected_node = node:draw_debug() if current_selected_node then selected_node = current_selected_node end end imgui.NextColumn() if selected_node then imgui.Text(selected_node.name) imgui.Text(selected_node.id) imgui.Text("Is finished "..tostring(selected_node:is_finished())) end imgui.Button("OK") imgui.EndChild() imgui.End() end local iui_state = { array={cbk = draw_array, show=true} } function love.load() end function love.update(dt) imgui.NewFrame() for _,node in ipairs(array) do node:update(dt) if not node:is_finished() then break end end end function love.draw() if imgui.BeginMainMenuBar() then if imgui.BeginMenu("Test") then for k,v in pairs(iui_state) do if imgui.MenuItem(k, nil, v.show) then iui_state[k].show = not iui_state[k].show end end imgui.EndMenu() end end imgui.EndMainMenuBar() for k,v in pairs(iui_state) do if v.show then v.cbk() end end imgui.Render() end function love.quit() imgui.ShutDown() end -- -- User inputs -- function love.textinput(t) imgui.TextInput(t) if not imgui.GetWantCaptureKeyboard() then -- Pass event to the game end end function love.keypressed(key) imgui.KeyPressed(key) if not imgui.GetWantCaptureKeyboard() then -- Pass event to the game end end function love.keyreleased(key) imgui.KeyReleased(key) if not imgui.GetWantCaptureKeyboard() then -- Pass event to the game end end function love.mousemoved(x, y) imgui.MouseMoved(x, y) if not imgui.GetWantCaptureMouse() then -- Pass event to the game end end function love.mousepressed(x, y, button) imgui.MousePressed(button) if not imgui.GetWantCaptureMouse() then -- Pass event to the game end end function love.mousereleased(x, y, button) imgui.MouseReleased(button) if not imgui.GetWantCaptureMouse() then -- Pass event to the game end end function love.wheelmoved(x, y) imgui.WheelMoved(y) if not imgui.GetWantCaptureMouse() then -- Pass event to the game end end