From abf55c9af141d7752d835068cc6168788c5ecf51 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Sun, 27 Nov 2022 18:41:02 +0100 Subject: [PATCH] wip --- rails/app/models/action.rb | 9 +++++++++ rails/app/models/batch.rb | 4 ++++ rails/app/models/execution.rb | 5 +++++ rails/app/models/setup.rb | 6 ++++++ rails/db/seeds.rb | 33 +++++++++++++++++++++++++++------ 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/rails/app/models/action.rb b/rails/app/models/action.rb index 42b79d2..dc7ead2 100644 --- a/rails/app/models/action.rb +++ b/rails/app/models/action.rb @@ -1,4 +1,13 @@ class Action < ApplicationRecord belongs_to :batch belongs_to :actionable, polymorphic: true + + def render + case actionable + when Execution + %(#{actionable.command.name} #{actionable.value}) + else + to_s + end + end end diff --git a/rails/app/models/batch.rb b/rails/app/models/batch.rb index 152c248..b746ddf 100644 --- a/rails/app/models/batch.rb +++ b/rails/app/models/batch.rb @@ -3,4 +3,8 @@ class Batch < ApplicationRecord has_many :menu_options has_many :wheel_options has_many :key_binds + + def render + actions.collect(&:render).join("; ") + end end diff --git a/rails/app/models/execution.rb b/rails/app/models/execution.rb index 30458e3..3d0fd35 100644 --- a/rails/app/models/execution.rb +++ b/rails/app/models/execution.rb @@ -1,4 +1,9 @@ class Execution < ApplicationRecord belongs_to :command has_many :actions + has_one :execution, ->(o){Execution.find(o.value)} + + def execution + Execution.find(value) + end end diff --git a/rails/app/models/setup.rb b/rails/app/models/setup.rb index 495f767..917d57e 100644 --- a/rails/app/models/setup.rb +++ b/rails/app/models/setup.rb @@ -3,4 +3,10 @@ class Setup < ApplicationRecord has_many :wheels has_many :menus has_many :input_devices + + def render + key_binds.collect { |key_bind| + %(alias batch#{id} \"#{key_bind.batch.render}\"\nbind #{key_bind.key.ingame} batch#{id}) + }.join("\n") + end end diff --git a/rails/db/seeds.rb b/rails/db/seeds.rb index 8014a56..a484b20 100644 --- a/rails/db/seeds.rb +++ b/rails/db/seeds.rb @@ -318,6 +318,7 @@ end { 'none' => /^$/, + 'command' => /^.*$/, 'string' => /^.*$/, 'integer' => /^\d+$/, 'float' => /^\d+(?:\.\d+)|\.\d+$/, @@ -345,19 +346,39 @@ Nokogiri::HTML flags = flags.strip.split(', ')[1..] # TODO Command .find_or_initialize_by(name: name.strip) - .update!({ + .update!( name: name, description: description, default: default == 'cmd' ? nil : default, datatype: - if default == 'cmd' + if default.blank? Datatype.find_by!(name: 'none') + elsif default == 'cmd' + Datatype.find_by!(name: 'command') else Datatype .order(specifity: :desc) - .find{ |datatype| - datatype.match? default - } or raise(default) + .find{ |datatype| datatype.match? default } || raise(default) end, - }) + ) end + + +( +Setup + .create!(name: 'test1') + .key_binds + .create!( + key: Key.find_by!(ingame: 'E'), + batch: Batch.create!(), + ) + .batch + .actions + .create!( + actionable: Execution.create!( + command: Command.find_by!( + datatype: Datatype.find_by!(name: 'float'), + ), + ), + ) +)