-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Save/Load Tileset #35
base: main
Are you sure you want to change the base?
Save/Load Tileset #35
Conversation
2d4c288
to
ce869d1
Compare
Other option could be implement custom MarshalXML functions for types that contain |
I see your point, but is it worth to add custom Marshal/Unmarshal functions? It will require to manually assemble all the other fields and can be error-prone. Using pointers when Unmarshaling only requires to set the default value as we are already doing. When marshaling it requires you to specify the value that you want to print, and if you do not define it, it simply ignores the field. I know that not all the Visibility values have been modified to use pointers, this is because I wanted to keep the scope of the merge request as small as possible. Basically, I would like to perform only the necessary modifications to Marshal/Unmarshal Tilesets. But thinking it again, maybe it makes sense to modify all the booleans with default true now to keep consistency. PD: I'm not on holidays anymore, so I will slow down my contributions ;) Thank you for your time. |
weekend again! what can I do to keep this moving? |
I don't quite like changing bool to pointer so imho custom xml encoder would be better |
What do you think about following the pattern of other packages to handle nullable fields? For example, in aws cli you can find the String function or the Bool function that basically converts a value to a pointer. Then, they use pointer in the structures that will be serialized. To follow this approach, we just have to replace the values with pointers and create the helper functions. Although the functions are not really needed. |
Yeah I have seen them but they are useful in cases where bool can acutally be nil, true, false. In TMX bool can not be xml:nil, it will be either true/false or if absent (default value). So we should build API on same principle imho with custom encoder |
I understand that absent means the default value. I think that the key difference is that with the current implementation you can not tell the difference between the default value set on purpose or the default value because it was missing. Maybe we can do this in two steps. We could define the structures with pointer references so we can track if the values was defined in the original file or not. Then we provide a method fillTiledDefaults() that will replace the missing values with the defaults. This way, an user interested in working with Tiled defaults could work with this library without preventing other use cases such as generating valid Tiles files without the default values forced by the current implementation. |
Other point for not using |
A simple thought on this, there's no reason to omit values from the save file if it's the same as the default value. Writing out all the field values when saving, even if they are the default values, should not create an unworkable file. Just because visible=true is default, it's not going to hurt if every relevant element has that attr set. It might appear a little more verbose in the output file, but it's likely a lot less headache than going through and deciding on a case by case basis what fields might be able to be omitted. |
Hey, I'm probably not going to follow up with this MR, I'm currently focused on other projects. Maybe we should just close it. |
Just leave it open, I will work on this later on to what I have more free time |
06a4855
to
c2a3f9b
Compare
Does this need anything else in order to merge? Working on a level editor and saving the tiled map directly would make my life a lot easier. |
need someone to finish this PR, see also my comment about pointers |
Concerns were around using pointer-to-bool to support omitting default-true bools during save. Removed the Save feature to get past that issue, hoping to get at least part of this PR moving after 4 years.
Concerns were around using pointer-to-bool to support omitting default-true bools during save. Removed the Save feature to get past that issue, hoping to get at least part of this PR submitted after 4 years.
Concerns were around using pointer-to-bool to support omitting default-true bools during save. Removed the Save feature to get past that issue, hoping to get at least part of this PR submitted after 4 years.
I have been working on a tool to automatically turn a folder of frames into a Tileset. For this purpose, I've modified the structures in this package to have the "omitempty" flag so I can write files similar to those generated by Tiled. Although this is working fine for most of the fields right the way, I had to make a few important changes
Properties Properties `xml:"properties>property"`
replacing it by an intermediate structure.I've tested TilesetTile and Tileset in different blocks because TilesetTile can be really complex so though that testing it in two steps could be easier to understand.