Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6a393ae
feat(GameObj-data.xml): new type jarable
mrhoribu Nov 10, 2025
0b8af7d
Update 66_jarable.rb
mrhoribu Nov 10, 2025
a4b7438
Update gem_spec.rb
mrhoribu Nov 10, 2025
9a3683a
Update core_spec.rb
mrhoribu Nov 10, 2025
c025a49
Update table.rb
mrhoribu Nov 10, 2025
62db218
Update migrator.rb
mrhoribu Nov 10, 2025
74e5700
Update 66_jarable.rb
mrhoribu Nov 10, 2025
38d8bb3
fix: rubocop
mrhoribu Nov 10, 2025
c543757
fix: rubocop
mrhoribu Nov 10, 2025
73988f4
Update change-set.rb
mrhoribu Nov 10, 2025
b60b5e8
Update migrator.rb
mrhoribu Nov 10, 2025
785d618
Update 66_jarable.rb
mrhoribu Nov 10, 2025
ae3d11e
Update change-set.rb
mrhoribu Nov 10, 2025
66cd4fb
Update convert.rb
mrhoribu Nov 10, 2025
3734ca6
Update migration.rb
mrhoribu Nov 10, 2025
27382fd
Update migrator.rb
mrhoribu Nov 10, 2025
5fc2119
Update table.rb
mrhoribu Nov 10, 2025
821f5ae
Update validate.rb
mrhoribu Nov 10, 2025
caec664
Update migration.rb
mrhoribu Nov 10, 2025
42860ee
Update gameobj.rb
mrhoribu Nov 10, 2025
86d857f
Update factories.rb
mrhoribu Nov 10, 2025
620604b
Update color.rb
mrhoribu Nov 10, 2025
56ba9da
Update gem_spec.rb
mrhoribu Nov 10, 2025
43f8c73
Update gem_spec.rb
mrhoribu Nov 10, 2025
683ff0c
Update rspec_tests.yml
mrhoribu Nov 10, 2025
1f6e4f7
Update rspec_tests.yml
mrhoribu Nov 10, 2025
61cc530
Update rspec_tests.yml
mrhoribu Nov 10, 2025
791806a
Merge pull request #9 from mrhoribu/feat/gameobj-jarable-type
mrhoribu Nov 10, 2025
adbc6ff
Merge branch 'elanthia-online:master' into feat/gameobj-data-jarable
mrhoribu Dec 16, 2025
bce4a7b
Update rspec_tests.yml
mrhoribu Feb 17, 2026
369a03a
Update gameobj.rb
mrhoribu Feb 17, 2026
d476383
Update rspec_tests.yml
mrhoribu Feb 17, 2026
f5e128a
Merge branch 'elanthia-online:master' into feat/gameobj-data-jarable
mrhoribu Feb 17, 2026
deb4cd9
Update rspec_tests.yaml
mrhoribu Feb 17, 2026
0953bc1
fix: rubocop
mrhoribu Feb 17, 2026
740f385
Rename 66_jarable.rb to 69_jarable.rb
mrhoribu Feb 17, 2026
ce8e048
Update 69_jarable.rb
mrhoribu Feb 17, 2026
381f3c0
Update 69_jarable.rb
mrhoribu Feb 17, 2026
1550362
fix: rubocop
mrhoribu Feb 17, 2026
f484599
Merge branch 'elanthia-online:master' into feat/gameobj-data-jarable
mrhoribu Mar 1, 2026
c55d0d2
Rename 69_jarable.rb to 70_jarable.rb
mrhoribu Mar 1, 2026
a56f708
Merge branch 'master' into feat/gameobj-data-jarable
mrhoribu Mar 18, 2026
7b7104a
Update core_spec.rb
mrhoribu Mar 18, 2026
eac03b8
Update and rename 70_jarable.rb to 70_bottleable.rb
mrhoribu Mar 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/rspec_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,12 @@ jobs:
version: 1.0
- name: Run type data migrations to create gameobj-data.xml
run: bin/migrate
- name: Upload gameobj-data.xml artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: gameobj-data-ruby-${{ matrix.ruby }}
path: dist/gameobj-data.xml
retention-days: 1
overwrite: true
- name: Run RSpec tests
run: bundle exec rspec
2 changes: 1 addition & 1 deletion lib/migration.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Dir[File.join(__dir__, "migration", "**", "*.rb")].each do |file| require(file) end
Dir[File.join(__dir__, "migration", "**", "*.rb")].each do |file| require(file) end
26 changes: 19 additions & 7 deletions lib/migration/change-set.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
require "pathname"

module Migration
class PrettyError < Exception
class PrettyError < StandardError
def initialize(changeset, msg)
super <<~ERROR
\n\t#{changeset.file.split("../").last} >> #{changeset.table.log_name} #{msg}
ERROR
end
end

class KeyError < PrettyError; end
class RuleError < PrettyError; end

##
## this is execution instance for
## evaluating a new set of changes
## to be applied to a table
##
class ChangeSet
def self.run(table, file, &block)
changeset = ChangeSet.new(table, file)
def self.run(table, file, tables, &block)
changeset = ChangeSet.new(table, file, tables)
changeset.instance_eval(&block)
changeset
end

attr_reader :table, :file, :inserts, :deletes, :creates
def initialize(table, file)
attr_reader :table, :file, :inserts, :deletes, :creates, :tables

def initialize(table, file, tables)
@table = table
@file = file
@tables = tables # Add this line
@inserts = {}
@deletes = {}
@creates = []
@table.pending << self
end

# Add helper methods
def get_table(table_name)
@tables[Table.normalize_key(table_name)]
end

def copy_rules_from(source_table_name, key)
source_table = get_table(source_table_name)
source_table.get_rules(key)
end

def will_create?(key)
@creates.include?(key)
end
Expand Down
10 changes: 5 additions & 5 deletions lib/migration/convert.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module Migration
module Convert
# (?:seasoned |grizzled |battle\-scarred |ancient |veteran )?
# (?:seasoned |grizzled |battle\-scarred |ancient |veteran )?
def self.maybe_pattern_to_regex(maybes = nil, space: nil, required_match: nil)
return %{} if maybes.nil?
#Migration.log(maybes, label: %i[maybes])
# Migration.log(maybes, label: %i[maybes])
with_whitespace = maybes.map do |maybe|
if space.eql?(:left)
" " + maybe
elsif space.eql?(:right)
maybe + " "
maybe + " "
else
maybe
end
end
end.join("|")
if required_match.nil?
%{(?:#{with_whitespace})?}
Expand All @@ -31,4 +31,4 @@ def self.to_safe_xml(str)
str.gsub(%[&], %[&amp;])
end
end
end
end
17 changes: 9 additions & 8 deletions lib/migration/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ module Migration
# creates a raw xml element that does not escape
# html entities, so regexp can properly be serialized
def self.raw_element(name, parent = nil)
Element.new(name, parent, context = {raw: :all, attribute_quote: :quote})
Element.new(name, parent, { raw: :all, attribute_quote: :quote })
end

##
## lookup from cwd
##
Expand All @@ -25,19 +26,19 @@ def self.log(msg, label: %i[], color: nil)
end

def self.load_tables(tables)
Hash[tables.map do |table|
Hash[tables.map do |table|
table = Table.from_yaml(table)
[table.name, table]
end]
end

def self.load_migrations(migrations, tables)
migrations.sort.map do |migration|
Migrator.new(migration, tables)
migrations.sort.map do |migration|
Migrator.new(migration, tables)
end
end

def self.to_xml(tables)
def self.to_xml(_tables)
root = raw_element(%{data})
@tables.values.map(&:to_xml).each do |child|
root.add_element(child)
Expand All @@ -51,9 +52,9 @@ def self.run(**opts)
@migrations = Migration.load_migrations(opts.fetch(:migrations), @tables)
@migrations.each(&:build).each(&:validate).each(&:apply)
asset = File.join(opts.fetch(:dist), "gameobj-data.xml")
Migration.log(%{writing #{asset}},
label: :write,
color: :pink)
Migration.log(%{writing #{asset}},
label: :write,
color: :pink)
File.open(asset, %{w+}) do |file|
file.write Migration.to_xml(@tables).to_s
end
Expand Down
35 changes: 21 additions & 14 deletions lib/migration/migrator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Migration
class TableNotFound < Exception; end
class DuplicateTable < Exception; end
class TableNotFound < StandardError; end
class DuplicateTable < StandardError; end

##
## loads a migration Ruby instance and executes it
## within a ChangeSet context, storing the result
Expand All @@ -9,12 +10,14 @@ class DuplicateTable < Exception; end
##
class Migrator
attr_reader :file, :tables, :basename

def initialize(file, tables)
@file = file
@tables = tables
@basename = File.basename(@file)
@changesets = []
end

##
## read the file into this binding
##
Expand All @@ -35,33 +38,37 @@ def apply_creations()
@changesets.each do |changeset|
changeset.creates.each do |key|
Migration.log(%[#{changeset.table.log_name} CREATE key "#{key}"],
label: %i[changeset],
color: :light_blue)
label: %i[changeset],
color: :light_blue)
changeset.table.create_key(key)
end
end
end

def apply_insertions()
@changesets.each do |changeset|
@changesets.each do |changeset|
changeset.inserts.each do |key, rules|
rules.each do |rule|
Migration.log(%[#{changeset.table.log_name} INSERT #{key} "#{rule}"],
label: %i[changeset],
color: :green)
label: %i[changeset],
color: :green)
end
changeset.table.insert(key, *rules)
end
end
end

def get_table(table_name)
@tables[Table.normalize_key(table_name)]
end

def apply_deletions()
@changesets.each do |changeset|
@changesets.each do |changeset|
changeset.deletes.each do |key, rules|
rules.each do |rule|
Migration.log(%[#{changeset.table.log_name} DELETE #{key} "#{rule}"],
label: %i[changeset],
color: :yellow)
label: %i[changeset],
color: :yellow)
end

changeset.table.delete(key, *rules)
Expand All @@ -70,24 +77,24 @@ def apply_deletions()
end

def assert_table_exists(table_name)
table = @tables[Table.normalize_key(table_name)] or
@tables[Table.normalize_key(table_name)] or
fail TableNotFound, Color.red("Table[:#{table_name}] does not exist")
end

def assert_table_does_not_exist(table_name)
table = @tables[Table.normalize_key(table_name)] and
@tables[Table.normalize_key(table_name)] and
fail DuplicateTable, Color.red("Table[:#{table_name}] already exists")
end

def migrate(*table_names, &migration)
table_names.each do |table_name|
table = assert_table_exists(table_name)
@changesets << ChangeSet.run(table, @file, &migration)
@changesets << ChangeSet.run(table, @file, @tables, &migration) # Add @tables here
end
self
end

def create_table(table_name, kind: 'type', keys:[])
def create_table(table_name, kind: 'type', keys: [])
assert_table_does_not_exist(table_name)
normalized_name = Table.normalize_key(table_name)
@tables[normalized_name] = Table.new(
Expand Down
Loading
Loading