left4me/rails/db/seeds.rb
mwiegand 34b1a009f2
wip
2022-11-27 19:23:31 +01:00

401 lines
6.6 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

keys = [
{
ingame: 'escape',
short: 'ESC',
title: 'Escape',
keycap: 'ESC',
},
{
ingame: 'tab',
short: 'TAB',
title: 'Tabulator',
keycap: '↹',
},
{
ingame: 'capslock',
short: 'CAPS',
title: 'Capslock',
keycap: '⇪',
},
{
ingame: 'shift',
short: 'SFT',
title: 'Shift',
keycap: '⇧',
},
{
ingame: 'ctrl',
short: 'CTL',
title: 'Control',
keycap: 'CTL',
},
{
ingame: 'alt',
short: 'ALT',
title: 'ALT',
keycap: 'ALT',
},
{
ingame: 'space',
short: 'SPC',
title: 'Space',
keycap: 'SPACE',
},
{
ingame: 'backspace',
short: 'BSP',
title: 'Backspace',
keycap: '⇦',
},
{
ingame: 'enter',
short: 'ENT',
title: 'Enter',
keycap: '↵',
},
{
ingame: 'semicolon',
short: ';',
title: 'Semicolon',
keycap: ';',
},
{
ingame: 'lwin',
short: 'LWIN',
title: 'Left Super',
keycap: '⊞',
},
{
ingame: 'rwin',
short: 'RWIN',
title: 'Right Super',
keycap: '⊞',
},
{
ingame: 'apps',
short: 'MENU',
title: 'Menu',
keycap: '≡',
},
{
ingame: 'numlock',
short: 'NUM',
title: 'Numlock',
keycap: 'NUM',
},
{
ingame: 'scrolllock',
short: 'SCR',
title: 'Scrollock',
keycap: 'SCR',
},
{
ingame: 'uparrow',
short: 'ARU',
title: 'Arrow Up',
keycap: '↑',
},
{
ingame: 'downarrow',
short: 'ARD',
title: 'Arrow Down',
keycap: '↓',
},
{
ingame: 'leftarrow',
short: 'ARL',
title: 'Arrow Left',
keycap: '←',
},
{
ingame: 'rightarrow',
short: 'ARR',
title: 'Arrow Right',
keycap: '→',
},
{
ingame: 'ins',
short: 'INS',
title: 'Insert',
keycap: 'INS',
},
{
ingame: 'del',
short: 'DEL',
title: 'Delete',
keycap: 'DEL',
},
{
ingame: 'pgdn',
short: 'PGD',
title: 'Page Down',
keycap: '⇣',
},
{
ingame: 'pgup',
short: 'PGU',
title: 'Page Up',
keycap: '⇡',
},
{
ingame: 'home',
short: 'HOM',
title: 'Home',
keycap: '⌂',
},
{
ingame: 'end',
short: 'END',
title: 'End',
keycap: '⇥',
},
{
ingame: 'pause',
short: 'PAU',
title: 'Pause',
keycap: '⏸',
},
{
ingame: 'kp_end',
short: 'N1',
title: 'Keypad 1 (End)',
keycap: '1',
},
{
ingame: 'kp_downarrow',
short: 'N2',
title: 'Keypad 2 (Arrow Down)',
keycap: '2',
},
{
ingame: 'kp_pgdn',
short: 'N3',
title: 'Keypad 3 (Page Down)',
keycap: '3',
},
{
ingame: 'kp_leftarrow',
short: 'N4',
title: 'Keypad 4 (Arrow Left)',
keycap: '4',
},
{
ingame: 'kp_5',
short: 'N5',
title: 'Keypad 5',
keycap: '5',
},
{
ingame: 'kp_rightarrow',
short: 'N6',
title: 'Keypad 6 (Arrow Right)',
keycap: '6',
},
{
ingame: 'kp_home',
short: 'N7',
title: 'Keypad 7 (Home)',
keycap: '7',
},
{
ingame: 'kp_uparrow',
short: 'N8',
title: 'Keypad 8 (Arrow Up)',
keycap: '8',
},
{
ingame: 'kp_pgup',
short: 'N9',
title: 'Keypad 9 (Page Up)',
keycap: '9',
},
{
ingame: 'kp_enter',
short: 'NENT',
title: 'Keypad Enter',
keycap: '↵',
},
{
ingame: 'kp_ins',
short: 'NINS',
title: 'Keypad 0',
keycap: '0',
},
{
ingame: 'kp_del',
short: 'NDEL',
title: 'Keypad .',
keycap: '.',
},
{
ingame: 'kp_slash',
short: 'NSL',
title: 'Keypad /',
keycap: '/',
},
{
ingame: 'kp_multiply',
short: 'NMUL',
title: 'Keypad *',
keycap: '*',
},
{
ingame: 'kp_minus',
short: 'NMIN',
title: 'Keypad -',
keycap: '-',
},
{
ingame: 'kp_plus',
short: 'NPLS',
title: 'Keypad +',
keycap: '+',
},
{
ingame: 'mwheeldown',
short: 'WLD',
title: 'Mousewheel Down',
keycap: '⇟',
},
{
ingame: 'mwheelup',
short: 'WLU',
title: 'Mousewheel Up',
keycap: '⇞',
},
{
ingame: 'mouse1',
short: 'M1',
title: 'Mouse 1',
keycap: '🖱1',
},
{
ingame: 'mouse2',
short: 'M2',
title: 'Mouse 2',
keycap: '🖱2',
},
{
ingame: 'mouse3',
short: 'M3',
title: 'Mouse 3',
keycap: '🖱3',
},
{
ingame: 'mouse4',
short: 'M4',
title: 'Mouse 4',
keycap: '🖱4',
},
{
ingame: 'mouse5',
short: 'M5',
title: 'Mouse 5',
keycap: '🖱5',
},
]
%(0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜß,.+-*/#^´<>).each_char do |char|
keys.append({
ingame: char,
short: char,
title: char,
keycap: char,
})
end
(1..12).each do |num|
keys.append({
ingame: "F#{num}",
short: "F#{num}",
title: "Function #{num}",
keycap: "F#{num}",
})
end
keys.each do |key|
Key
.find_or_initialize_by(ingame: key[:ingame])
.update!(key)
end
{
'none' => {
regex: /^$/,
is_nestable: true,
},
'command' => {
regex: /^.*$/,
is_nestable: false,
},
'string' => {
regex: /^.*$/,
is_nestable: false,
},
'integer' => {
regex: /^\d+$/,
is_nestable: true,
},
'float' => {
regex: /^\d+(?:\.\d+)|\.\d+$/,
is_nestable: true,
},
}.each_with_index do |(name, conf), i|
Datatype
.find_or_initialize_by(name: name)
.update!({
regex: conf[:regex].to_s,
is_nestable: conf[:is_nestable],
specifity: i,
})
end
Nokogiri::HTML
.parse(
URI('https://developer.valvesoftware.com/wiki/List_of_L4D2_Cvars').read
)
.css('#mw-content-text pre')
.collect(&:content)
.join("\n")
.split("\n")
.each do |line|
next if line.blank?
name, default, flags, description = line.split(' :')
name.strip! && default.strip! && flags.strip! && description.strip!
flags = flags.strip.split(', ')[1..] # TODO
Command
.find_or_initialize_by(name: name.strip)
.update!(
name: name,
description: description,
default: default == 'cmd' ? nil : default,
datatype:
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 } || 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'),
),
value: 2.0,
),
)
)