The built-in serialization/deserialization functions of DragonRuby fail when used with moderately big data.
With Hoard you can serialize and deserialize arbitrarily big data without having to think about splitting them into manageable small pieces.
Add following line to your Smaug.toml
:
hoard = "https://github.com/kfischer-okarin/hoard/releases/download/v1.0.0/hoard.zip"
Alternatively you can also just run smaug add hoard
though that will add the whole repository to your project.
Download the current release, extract it,
and put the contained lib/hoard.rb
anywhere in your game folder and require it.
To serialize data:
serialized_data = Hoard.serialize save_game_data
# Save the data
$gtk.write_file 'saves/001.sav', serialized_data
To deserialize data:
serialized_data = $gtk.read_file 'saves/001.sav'
save_game_data = Hoard.deserialize serialized_data
Entities created by args.state.new_entity
or args.state.new_entity_strict
are serialized/deserialized as a whole.
So if a single entity is very big it could still mean that your data cannot be properly deserialized (DragonRuby will
print out a warning in that case).
Therefore if you need to serialize huge units of data it might be better to use Hashes.
A serializer is a class derived from Hoard::Serializer::BaseSerializer
that defines several class methods as below.
class MySerializer < Hoard::Serializer::BaseSerializer
class << self
def type
# Return a unique symbol identifier for your serializer
end
def can_serialize?(value)
# Return true if the value can be serialized by your serializer
end
def serialize(value)
# Return a serialized string representation of your data
end
def deserialize(serialized_value)
# Return the deserialized data
end
end
end
You can check the implementations of the default serializers if you need more details.
See the open issues for a list of proposed features (and known issues).
Thank your for your willingness to help out with the development!
If you have any contributions, please fork the repository, add your changes to a feature branch and open a Pull Request.
You can find me usually on the DragonRuby Discord under the username
kfischer_okarin
.