dkrasner / Simpletalk

Apache License 2.0
53 stars 3 forks source link

JSON serialization #153

Closed dkrasner closed 1 year ago

dkrasner commented 1 year ago

Main Points

This PR primarily does two things:

  1. allows for JSON serialization to be imported and exported from the env
  2. gives parts control of the import and export process

The motivation for this is the following:

  1. there is no need to carry around the entire html file, since it consists of a) dependencies (ie the bundle, css and PEG) which are generally stable and b) the serialization <- this is where all the env data lives
  2. moving to a strictly json import/export we can now do so with any part (and its subparts), ie you can save a button or a menu area, and then import it. Part specific control can be done with with overriding the base class method as you can see for world. Moreover there is not difference between importing or saving a world, a stack or a button. This uniformity allows us to export/save specific subparts, for example a single stack from a world and then import to another. This is very nice.
  3. System only comes into play when dealing with the OS, ie reading and writing files
  4. clipboard copy&paste are effectively the same as OS save/import. This is what we want in the future.
  5. save and import are now simple commands which you can send to any part (Note: save takes a string arg, save [fileName]. If that is not provided it will use the part's type and name to make one)

Tests

I have added basic serialization/de-serialization tests

Note

I updated the index.html page (ie the toolbox save/import buttons within) to reflect the above. I have also left the saveHTML System command at the moment as it is helpful when making such page exports. Once this is stable we should refactor the clipboard to use the Part methods, issue #152 I added save and import to the context menu (we might want to remove import from parts which can't accept any subpart). On an unrelated note, I fixed a bug to update the tab title with the world name. This is a pretty major change, so please take care to make sure the changes work for you and the code makes sense. As usual in ST, if you try to import a part into a part which doesn't accept the former nothing happens (just like with the add [part] command).