This commit is contained in:
mwiegand 2022-11-27 18:41:02 +01:00
parent b42d35d901
commit abf55c9af1
No known key found for this signature in database
5 changed files with 51 additions and 6 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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'),
),
),
)
)