Class: Avm::MaysMagicalSchool::Stage
- Inherits:
-
Object
- Object
- Avm::MaysMagicalSchool::Stage
- Defined in:
- lib/avm/mays_magical_school/stage.rb,
lib/avm/mays_magical_school/stage/object.rb,
lib/avm/mays_magical_school/stage/terrain.rb
Defined Under Namespace
Constant Summary collapse
- SIZE =
::Cliutils.v2.new(11, 12)
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#terrains ⇒ Object
readonly
Returns the value of attribute terrains.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source, number, terrains_types, objects) ⇒ Stage
constructor
A new instance of Stage.
- #serialize_file(file) ⇒ Object
- #size ⇒ Object
- #terrain(*coord_args) ⇒ Object
- #to_serialized_data ⇒ Object
Constructor Details
#initialize(source, number, terrains_types, objects) ⇒ Stage
Returns a new instance of Stage.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/avm/mays_magical_school/stage.rb', line 44 def initialize(source, number, terrains_types, objects) self.source = source self.number = number self.terrains = terrains_types.assert_count(SIZE.product, 'terrains_types') .each_with_index.map do |tt, i| ::Avm::MaysMagicalSchool::Stage::Terrain.new(self, tt, ::Cliutils.v2.new( i % size.x, i.div(size.y) )) end self.objects = objects end |
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
42 43 44 |
# File 'lib/avm/mays_magical_school/stage.rb', line 42 def number @number end |
#objects ⇒ Object
Returns the value of attribute objects.
42 43 44 |
# File 'lib/avm/mays_magical_school/stage.rb', line 42 def objects @objects end |
#source ⇒ Object
Returns the value of attribute source.
42 43 44 |
# File 'lib/avm/mays_magical_school/stage.rb', line 42 def source @source end |
#terrains ⇒ Object
Returns the value of attribute terrains.
42 43 44 |
# File 'lib/avm/mays_magical_school/stage.rb', line 42 def terrains @terrains end |
Class Method Details
.from_serialized_data(source, data) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/avm/mays_magical_school/stage.rb', line 20 def from_serialized_data(source, data) new( source, data.fetch(:number), terrains_types_from_data(data.fetch(:terrains)), objects_from_data(data.fetch(:objects)) ) end |
.from_serialized_file(source, file) ⇒ Object
16 17 18 |
# File 'lib/avm/mays_magical_school/stage.rb', line 16 def from_serialized_file(source, file) from_serialized_data(source, ::EacRubyUtils::Yaml.load_file(file)) end |
Instance Method Details
#serialize_file(file) ⇒ Object
57 58 59 60 |
# File 'lib/avm/mays_magical_school/stage.rb', line 57 def serialize_file(file) file.to_pathname.parent.mkpath ::EacRubyUtils::Yaml.dump_file(file, to_serialized_data) end |
#terrain(*coord_args) ⇒ Object
66 67 68 69 |
# File 'lib/avm/mays_magical_school/stage.rb', line 66 def terrain(*coord_args) coord = ::Cliutils.v2.new(*coord_args) terrains.fetch(coord.x + coord.y * size.x) end |
#to_serialized_data ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/avm/mays_magical_school/stage.rb', line 71 def to_serialized_data { number: number, terrains: terrains_to_serialized_data, objects: objects_to_serialized_data } end |