commit 5ea8d1365347d3a3c7c52fef70226a65813a2532 Author: Cyberarm Date: Sun Jun 7 09:02:02 2020 -0500 Initial Commit diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..b96d232 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "https://rubygems.org" + +gem "cyberarm_engine" +gem "faker", group: :development \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e52730f --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# TimeCrafters Action Configurator for Desktop \ No newline at end of file diff --git a/lib/palette.rb b/lib/palette.rb new file mode 100644 index 0000000..43beab0 --- /dev/null +++ b/lib/palette.rb @@ -0,0 +1,25 @@ +module TAC + module Palette + TACNET_CONNECTED = Gosu::Color.new(0xff008000) + TACNET_CONNECTING = Gosu::Color.new(0xffff8800) + TACNET_CONNECTION_ERROR = Gosu::Color.new(0xff800000) + + TIMECRAFTERS_PRIMARY = Gosu::Color.new(0xff008000) + TIMECRAFTERS_SECONDARY = Gosu::Color.new(0xff006000) + + TACNET_PRIMARY = Gosu::Color.new(0xff000080) + TACNET_SECONDARY = Gosu::Color.new(0xff000060) + + GROUPS_PRIMARY = Gosu::Color.new(0xff444444) + GROUPS_SECONDARY = Gosu::Color.new(0xff444444) + + ACTIONS_PRIMARY = Gosu::Color.new(0xff4444aa) + ACTIONS_SECONDARY = Gosu::Color.new(0xff040404) + + VALUES_PRIMARY = Gosu::Color.new(0xff660066) + VALUES_SECONDARY = Gosu::Color.new(0x040404ff) + + EDITOR_PRIMARY = Gosu::Color.new(0xff446688) + EDITOR_SECONDARY = Gosu::Color.new(0x040404ff) + end +end \ No newline at end of file diff --git a/lib/states/editor.rb b/lib/states/editor.rb new file mode 100644 index 0000000..da430df --- /dev/null +++ b/lib/states/editor.rb @@ -0,0 +1,114 @@ +module TAC + class States + class Editor < CyberarmEngine::GuiState + def setup + stack width: 1.0, height: 1.0 do + stack width: 1.0, height: 0.1 do + background [TAC::Palette::TIMECRAFTERS_PRIMARY, TAC::Palette::TIMECRAFTERS_SECONDARY] + + flow width: 1.0, height: 1.0 do + stack width: 0.70 do + label TAC::NAME, color: Gosu::Color::BLACK, bold: true + + flow do + [:add, :delete, :clone, :create, :simulate].each do |b| + button b.capitalize, text_size: 18 + end + end + end + + flow width: 0.299 do + stack width: 0.5 do + label "TACNET", color: TAC::Palette::TACNET_PRIMARY + @tacnet_ip_address = label "192.168.49.1", color: TAC::Palette::TACNET_SECONDARY + end + + stack width: 0.499 do + @tacnet_status = label "Connection Error", background: TAC::Palette::TACNET_CONNECTION_ERROR, text_size: 18, padding: 5, margin_top: 2 + @tacnet_connection_button = button "Connect", text_size: 18 + end + end + end + end + + flow width: 1.0, height: 0.9 do + stack width: 0.2, height: 1.0 do + background TAC::Palette::GROUPS_PRIMARY + label "Groups" + + @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" + + @actions_list = stack width: 1.0 do + end + end + stack width: 0.2, height: 1.0 do + background TAC::Palette::VALUES_PRIMARY + label "Values" + + @values_list = stack width: 1.0 do + end + end + stack width: 0.399, height: 1.0 do + background TAC::Palette::EDITOR_PRIMARY + label "Editor" + + @editor = stack width: 1.0 do + end + end + end + end + end + + def populate_actions_list(group_id) + actions = TAC::Storage.actions(group_id) + + @actions_list.clear do + actions.each do |action| + button action.name, text_size: 18, width: 1.0 do + populate_values_list(action.id) + end + end + end + end + + def populate_values_list(action_id) + values = TAC::Storage.values(action_id) + + @values_list.clear do + values.each do |value| + button value.name, text_size: 18, width: 1.0 do + populate_editor(value) + end + end + end + end + + def populate_editor(value) + @editor.clear do + [:id, :action_id, :name, :type, :value].each do |m| + label "#{m}: #{value.send(m)}", text_size: 18 + end + + case value.type + when :double, :float, :integer, :string + edit_line "#{value.value}", width: 1.0 + when :boolean + toggle_button checked: value.value + else + label "Unsupported value type: #{value.type.inspect}", text_size: 18 + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/storage.rb b/lib/storage.rb new file mode 100644 index 0000000..b27f176 --- /dev/null +++ b/lib/storage.rb @@ -0,0 +1,39 @@ +module TAC + module Storage + Group = Struct.new(:id, :name) + Action = Struct.new(:id, :group_id, :name, :enabled) + Value = Struct.new(:id, :action_id, :name, :type, :value) + + def self.groups + @@_g ||= Array.new(15) { |i| Group.new(i, Faker::Book.title) } + end + + def self.actions(group_id) + @@_a ||= Array.new(100) { |i| Action.new(i, groups.sample.id, Faker::Space.meteorite, true) } + @@_a.select { |a| a.group_id == group_id } + end + + def self.values(action_id) + types = [:double, :float, :string, :boolean, :integer] + + @@_v ||= Array.new(500) do |i| + v = Value.new(i, rand(100), Faker::Space.meteorite, types.sample) + + v.value = case v.type + when :double, :float + rand(-1.0..1.0) + when :integer + rand(-1024..1024) + when :string + Faker::Quotes::Shakespeare.hamlet_quote + when :boolean + rand > 0.5 + end + + v + end + + @@_v.select { |a| a.action_id == action_id } + end + end +end \ No newline at end of file diff --git a/lib/version.rb b/lib/version.rb new file mode 100644 index 0000000..42f4449 --- /dev/null +++ b/lib/version.rb @@ -0,0 +1,5 @@ +module TAC + NAME = "TimeCrafters Action Configurator" + VERSION = "0.1.0" + RELEASE_NAME = "IN-DEV" +end \ No newline at end of file diff --git a/lib/window.rb b/lib/window.rb new file mode 100644 index 0000000..a092a41 --- /dev/null +++ b/lib/window.rb @@ -0,0 +1,14 @@ +module TAC + class Window < CyberarmEngine::Window + def initialize(**args) + super(**args) + + self.caption = "#{TAC::NAME} v#{TAC::VERSION} (#{TAC::RELEASE_NAME})" + push_state(TAC::States::Editor) + end + + def needs_cursor? + true + end + end +end \ No newline at end of file diff --git a/timecrafters_action_configurator.rb b/timecrafters_action_configurator.rb new file mode 100644 index 0000000..9ccabd9 --- /dev/null +++ b/timecrafters_action_configurator.rb @@ -0,0 +1,13 @@ +require_relative "../cyberarm_engine/lib/cyberarm_engine" +require "socket" +require "json" + +require "faker" + +require_relative "lib/palette" +require_relative "lib/window" +require_relative "lib/version" +require_relative "lib/storage" +require_relative "lib/states/editor" + +TAC::Window.new(width: (Gosu.screen_width * 0.8).round, height: (Gosu.screen_height * 0.8).round, resizable: true).show \ No newline at end of file