Class: RgssDb::DataFileMap

Inherits:
DataFile show all
Defined in:
lib/rgss_db/model/data_file.rb

Overview

RPG Maker map data file

This class expects the object to be a RPG::Map instance

This class forces map events hash keys to be a number.

**Reason: Creating a DataFile instance from a RPG Maker Map JSON file provokes undesired behavior.**

JSON only allows key names to be strings, so all keys of the hash will be converted to string.

This is undesired behavior because RPG Maker editor requires the map events hash keys to be numbers.

So we need to convert all keys read from the JSON file to integers when importing the JSON file into the RPG Maker database, hence the inclusion of this class specification from DataFileHash.

Otherwise the RPG Maker editor will fail to show the map events even though data still exists.

Instance Attribute Summary collapse

Attributes inherited from DataFile

#file_path, #object_ids, #type

Instance Method Summary collapse

Methods inherited from DataFile

#<=>, #all_objects?, #convert_list_to_ids, #customizable?, #file, #file?, #file_path?, #initialize, #merge, #mergeable?, #object_ids_clear, #object_ids_update, #serialize_file_name, #to_list, #to_merge, #to_s, #type?

Constructor Details

This class inherits a constructor from RgssDb::DataFile

Instance Attribute Details

#objectRPG::Map (readonly)

Data file object (not processed)

Returns:



538
539
540
# File 'lib/rgss_db/model/data_file.rb', line 538

def object
  @object
end

Instance Method Details

#serializeObject

Serializes the data file’s object

This method prepares the object as a RPG::Map object

Returns:

  • (Object)


547
548
549
550
551
552
553
554
555
556
# File 'lib/rgss_db/model/data_file.rb', line 547

def serialize
  # Dups the original object
  processed_object = object.dup

  # Applies the selected object IDs (if any)
  processed_object.events.transform_keys! { |key| key.to_s.to_i }

  # Returns the formatted object
  processed_object
end