|
|
@@ -1,15 +1,31 @@
|
|
|
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 = {
|
|
|
- {name="Test", type="Action"},
|
|
|
- {name="Test2", type="Action"},
|
|
|
- {name="Cont", type="Container", holding={4,5,6,7,8}, condition="And"},
|
|
|
- {name="Held", type="Action"},
|
|
|
- {name="Held", type="Action"},
|
|
|
- {name="Held", type="Action"},
|
|
|
- {name="Held", type="Action"},
|
|
|
- {name="Held", type="Action"},
|
|
|
- {name="Held", type="Action"}
|
|
|
+ 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
|
|
|
@@ -23,66 +39,21 @@ function not_in(v,t)
|
|
|
return true
|
|
|
end
|
|
|
|
|
|
-function draw_action_node(node)
|
|
|
- local v = 0
|
|
|
- imgui.BeginChildFrame(node.id,0,64, true, {"NoInputs"})
|
|
|
-
|
|
|
- local x,y = imgui.GetCursorPos()
|
|
|
- imgui.InvisibleButton("",-1,-1)
|
|
|
- if imgui.IsItemClicked() then
|
|
|
- selected_node = node
|
|
|
- end
|
|
|
- imgui.SetCursorPos(x,y)
|
|
|
-
|
|
|
- imgui.Text(node.name)
|
|
|
- imgui.Separator()
|
|
|
-
|
|
|
- imgui.EndChildFrame()
|
|
|
-end
|
|
|
-
|
|
|
function draw_array()
|
|
|
imgui.Begin("Array")
|
|
|
imgui.BeginChild("", 0,0, true)
|
|
|
imgui.Columns(2)
|
|
|
- local nodes_drawn_in_containers = {}
|
|
|
for i,node in ipairs(array) do
|
|
|
- if node.type == "Action" and not_in(i, nodes_drawn_in_containers) then
|
|
|
- draw_action_node(node)
|
|
|
- elseif node.type == "Container" then
|
|
|
- if node.condition == "Or" then
|
|
|
- imgui.PushStyleColor("ChildWindowBg", 0.2,0,0,1)
|
|
|
- elseif node.condition == "And" then
|
|
|
- imgui.PushStyleColor("ChildWindowBg", 0,0.2,0,1)
|
|
|
- else
|
|
|
- imgui.PushStyleColor("ChildWindowBg", 0,0,0,1)
|
|
|
- end
|
|
|
- imgui.BeginChild("Container "..i, 0,104, true, {"NoInputs"})
|
|
|
- local x,y = imgui.GetCursorPos()
|
|
|
- imgui.InvisibleButton("",-1,-1)
|
|
|
- if imgui.IsItemClicked() then
|
|
|
- selected_node = node
|
|
|
- end
|
|
|
- imgui.SetCursorPos(x,y)
|
|
|
-
|
|
|
-
|
|
|
- imgui.Text("Condition | "..node.condition)
|
|
|
- imgui.Separator()
|
|
|
- imgui.Columns(#node.holding, nil, false)
|
|
|
- imgui.PopStyleColor(1)
|
|
|
- for k,v in ipairs(node.holding) do
|
|
|
- nodes_drawn_in_containers[#nodes_drawn_in_containers + 1] = v
|
|
|
- local node = array[v]
|
|
|
- draw_action_node(node)
|
|
|
- imgui.NextColumn()
|
|
|
- end
|
|
|
- imgui.PushStyleColor("ChildWindowBg", 1,0,0,1)
|
|
|
- imgui.EndChild()
|
|
|
- imgui.PopStyleColor(1)
|
|
|
+ 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()
|
|
|
@@ -101,6 +72,10 @@ 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()
|