Skip to content

Commit

Permalink
Add button for removing component (EntityRemoveComponent)
Browse files Browse the repository at this point in the history
  • Loading branch information
dextercd committed Oct 3, 2022
1 parent 22561a4 commit 9e423c8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions components.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ component_types = {
}

local components_watching = {}
local components_to_remove = {}

function unwatch_component(component_id)
components_watching[component_id] = nil
Expand Down Expand Up @@ -55,16 +56,30 @@ function show_component_windows()
unwatch_component(component)
end
end

for _, pair in ipairs(components_to_remove) do
local entity_id, component_id = unpack(pair)
EntityRemoveComponent(entity_id, component_id)
end
components_to_remove = {}
end

function toggle_component_button(entity_id, component_id)
function component_attributes(entity_id, component_id)
local enabled = ComponentGetIsEnabled(component_id)
imgui.Text("Enabled: " .. tostring(enabled))
imgui.SameLine()
imgui.SetCursorPosX(imgui.GetFontSize() * 8)
if imgui.Button("Toggle") then
EntitySetComponentIsEnabled(entity_id, component_id, not enabled)
end

imgui.PushStyleColor(imgui.Col.Button, 1, 0.4, 0.4)
imgui.PushStyleColor(imgui.Col.ButtonHovered, 1, 0.6, 0.6)
imgui.PushStyleColor(imgui.Col.ButtonActive, 0.8, 0.4, 0.4)
if imgui.Button("Remove") then
table.insert(components_to_remove, {entity_id, component_id})
end
imgui.PopStyleColor(3)
end

{% set supported_fields = [
Expand Down Expand Up @@ -144,7 +159,7 @@ function show_{{ component.name }}_window(entity_id, component_id)

imgui.Separator()

toggle_component_button(entity_id, component_id)
component_attributes(entity_id, component_id)

show_{{ component.name }}_fields(component_id)

Expand Down

0 comments on commit 9e423c8

Please sign in to comment.