Config is now saved and synced when updated

This commit is contained in:
2020-06-07 22:47:53 -05:00
parent ab6edb7a58
commit 151df4ca57
14 changed files with 162 additions and 59 deletions

View File

@@ -2,6 +2,9 @@ module TAC
class States
class Editor < CyberarmEngine::GuiState
def setup
@active_group = nil
@active_action = nil
theme(THEME)
stack width: 1.0, height: 1.0 do
@@ -10,19 +13,7 @@ module TAC
flow width: 1.0, height: 1.0 do
stack width: 0.70 do
label TAC::NAME, color: Gosu::Color::BLACK, bold: true
flow do
button "Add Group", text_size: 18 do
push_state(TAC::Dialog::NamePromptDialog, title: "Create Group", subtitle: "Add Group", submit_label: "Add", callback: proc {|instance| instance.close })
end
button "Add Action", text_size: 18 do
push_state(TAC::Dialog::NamePromptDialog, title: "Create Action", subtitle: "Add Action", submit_label: "Add", callback: proc {|instance| instance.close })
end
button "Add Value", text_size: 18 do
push_state(TAC::Dialog::NamePromptDialog, title: "Create Value", subtitle: "Add Value", submit_label: "Add", callback: proc {|instance| instance.close })
end
end
label TAC::NAME, color: Gosu::Color.rgb(59, 200, 81), bold: true, text_size: 72
end
flow width: 0.299 do
@@ -44,26 +35,44 @@ module TAC
flow width: 1.0, height: 0.9 do
stack width: 0.2, height: 1.0 do
background TAC::Palette::GROUPS_PRIMARY
label "Groups"
flow do
label "Groups"
button "Add Group", text_size: 18 do
push_state(TAC::Dialog::NamePromptDialog, title: "Create Group", submit_label: "Add", callback_method: method(:create_group))
end
end
@groups_list = stack width: 1.0 do
TAC::Storage.groups.each_with_index do |group, i|
button group.name, width: 1.0, text_size: 18 do
populate_actions_list(group.id)
end
end
end
end
stack width: 0.2, height: 1.0 do
background TAC::Palette::ACTIONS_PRIMARY
label "Actions"
flow do
label "Actions"
button "Add Action", text_size: 18 do
if @active_group
push_state(TAC::Dialog::NamePromptDialog, title: "Create Action", submit_label: "Add", callback_method: method(:create_action))
else
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create action,\nno group selected.")
end
end
end
@actions_list = stack width: 1.0 do
end
end
stack width: 0.2, height: 1.0 do
background TAC::Palette::VALUES_PRIMARY
label "Values"
flow do
label "Values"
button "Add Value", text_size: 18 do
if @active_action
push_state(TAC::Dialog::NamePromptDialog, title: "Create Value", subtitle: "Add Value", submit_label: "Add", callback_method: method(:create_value))
else
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create value,\nno action selected.")
end
end
end
@values_list = stack width: 1.0 do
end
@@ -77,6 +86,46 @@ module TAC
end
end
end
populate_groups_list
end
def create_group(name)
window.backend.config[:data][:groups] << {id: rand(100), name: name}
window.backend.save_config
populate_groups_list
end
def create_action(name)
window.backend.config[:data][:actions] << {id: rand(100), group_id: @active_group.id, name: name, enabled: true}
window.backend.save_config
populate_actions_list(@active_group.id)
end
def create_value(name, type = :float, value = 45.0)
window.backend.config[:data][:values] << {id: rand(100), action_id: @active_action.id, name: name, type: type, value: value}
window.backend.save_config
populate_values_list(@active_action.id)
end
def populate_groups_list
groups = TAC::Storage.groups
@groups_list.clear do
groups.each do |group|
button group.name, text_size: 18, width: 1.0 do
@active_group = group
@active_action = nil
populate_actions_list(group.id)
@values_list.clear
@editor.clear
end
end
end
end
def populate_actions_list(group_id)
@@ -85,7 +134,10 @@ module TAC
@actions_list.clear do
actions.each do |action|
button action.name, text_size: 18, width: 1.0 do
@active_action = action
populate_values_list(action.id)
@editor.clear
end
end
end