-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] New architecture for level serialization. #64
Comments
that's neat |
Hi, yes, I plan to redo the level loading and saving systems, and this includes serialization as well. If you want to see the development process or help with it yourself, you can check us out on Discord |
Eh I don't use Discord but would love to help with the development! |
We do a lot of coordination-related stuff on Discord, since it's easier to communicate there casually. However, if you have something specific in mind that you want to add, fix or improve, you are welcome to use the issues tab to submit proposals and, after approvals, implement them. |
Will do 👍🏾 |
Problem
The current code for level serialization is messy and not comfortable to use (involves a lot of hacks and tricks, see levelparse.js) and doesn't allow for extension (if a new game version will release, we would have to go through a lot of steps to adapt for the new content).
Solution
I propose a cleaner architecture that benefits from the use of TypeScript that can be easily extended and composed, if needed (GD's level format involves a lot of composition, for example trigger properties). The idea is to implement an abstract
GDObject
class that hasGDProperty
inherited properties (Vector2
,ZLayer
) as well asserialize()
abstract method.GDObject
As mentioned previously,
GDObject
is an abstract class withZLayer
andVector2
fields and an abstractserialize()
method. This is how it could look in TypeScript code:Then, it gets inherited by
GDBlock
andGDTrigger
classes that implement the abstractserialize()
method, that will be explained later.GDProperty
Just like
GDObject
,GDProperty
is an abstract class, but it only defines a single abstractserialize()
method.Here's how it can look in code:
As mentioned previously,
Vector2
andZLayer
classes extend aGDProperty
, and are used as properties ofGDObject
.Vector2
Pretty obvious, its a two component structure with X and Y coordinates. This is how it can be implemented:
It can also implement other methods, for example
dot()
orlength()
, if we will need them.ZLayer
Again, its in the name. It only contains a number value
index
:And so on, for every property type we'd like to have.
GDTrigger
Triggers are interesting ones as OOP approach will render them pretty messy. This is why I think we could compose
GDProperty
together in aproperties
array.GDBlock
Extends
GDObject
but adds properties like color, etc. needed for a block.In practice
In the actual editor backend the level will look like an array of
GDObject
, and when its time to save the level in GD's format it will be pretty easy to do so:Benefits
With this approach, its trivial to add more types of objects and properties, resulting in much cleaner code. However, we should also consider that level format might change, so we should somehow combat that as well.
The text was updated successfully, but these errors were encountered: