-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add a few more JSON instances #494
Conversation
TristanCacqueray
commented
Jun 26, 2022
•
edited by xsebek
Loading
edited by xsebek
- part of Add missing ToJSON instances #347
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, Generic
is great! 👍
Please just change the description to "- part of #347" as I think this does not add all missing ToJSON
instances.
My main interest is the World
which has only a parser in Scenario
but is missing a serializer.
I think it's worth using |
I guess the alternative to |
src/Swarm/Game/Robot.hs
Outdated
|
||
deriving instance Show (f RID) => Show (RobotR f) | ||
deriving instance FromJSON (f RID) => FromJSON (RobotR f) | ||
deriving instance ToJSON (f RID) => ToJSON (RobotR f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit surprising since we have the FromJSONE
instance above.
That one requires the entity map and also does not allow specifying robot ID nor some other fields like the log.
I am not sure what this ToJSON
instance produces, but I would like it to match the FromJSONE
.
Though if the generated instance is reasonable maybe it could be useful and we could align them later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I have no idea, I just typed on the keyboard until GHC could link the binary :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, when I made the FromJSONE
instances I was just interested in putting in enough functionality to be able to describe robots in the ways that I wanted in scenario description files. But if there are fields that are still missing we can definitely add them.
fd78831
to
c403805
Compare
Here are the missing instances to be able to serialize the GameState: instance FromJSONKey (V2 Int64) instance FromJSON (Array Int Text) instance FromJSON (W.World Int Entity) instance FromJSON ScenarioCollection instance FromJSON StdGen |
Oh well, build time are back to the 5min range (they went up to 15min in the previous checks) |
|
Agreed, let's move it. |
https://discourse.haskell.org/t/save-and-restore-random-number-generator-freeze-thaw/4751/9 |
Actually we may not want to serialize the |
Counterexample: A player submits a bug report with a saved game and it depends on a random number somewhere. We already allow a custom seed, so keeping the current random generator in saves seems natural. 🤷♂️ |
I was going to say the same thing re: saving the |
ca6c9cd
to
a6ddd02
Compare
a6ddd02
to
bd5576f
Compare
a572e56
to
05f91dd
Compare
ef0aec6
to
0aa7c56
Compare
Co-authored-by: Restyled.io <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me!