Syncing an in-game editing mode with Construct 2's layouts in the interface?

0 favourites
  • 4 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • So, I've created a somewhat robust in-game object creation/deletion and metadata-editor mode as seen here:

    Edit Mode

    While this is merely meant for quick tests without having to open up/go back to Construct 2, is there some way I can have changes synced to Construct 2's layouts in the editor interface or is that impossible? What I mean like is, if I spawn an object via the edit-mode, save the game, then save Construct 2, close it and then reopen it, the object will appear in the layout in Construct 2's editor? Or is that impossible or generally unfeasible and really difficult to do? I figured I could use JSON to store layout objects but I haven't fiddled much with JSON beyond savedata/dict usage.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It probably is more involved than it appears at first glance. Mostly tedious.

    Layouts in capx files are in a xml format and if you add more layouts you’ll need to modify the project.xml in the capx to add it to the layout list.

    Modifying layout xml files instead of just creating them are more involved. Probably would require parsing the entire layout, and then you’d have to decide what to remove or add. A easier bet is to save everything from in game and just recreate a new layout xml.

    So you can still save your game in json or whatever but it will ultimately need to be recreated in xml in the format the construct2 uses. Save your game as a folder or open your capx as a zip file to see how these xml files are formatted. As an exercise see if you can duplicate an instance. Basically that’s all you’ll be doing to generate a layout, or rather that’s what a program will be doing.

    Anyways the basic flow is:

    1 save to a file from your running game.

    2. Close the capx in construct

    3. Take that file, generate the layout xml and insert it in the capx.

    The closest I’ve done before is to take a tiled file and create a layout.xml with a sprite per tile. This pre-dated the tilemap plugin. It was more of a one shot thing though, so I did a lot of it manually.

    It’s an interesting idea though.

  • So I explored further the feasibility of doing this within the running game. Here's the current test:

    It's piecing together the necessary parts and very wip atm so it's a bit messy. Mostly a lot of asynchronous calls. A final step if I works well will be to simplify everything best I can.

    What it does?

    It can show a open file dialog, load a capx file as a zip and access files inside.

    I also was able to make it save the zip again. It's not possible to show a SaveAs dialog from JavaScript so it just invokes a download of the file. Maybe if I decide to go the nwjs route...

    The file I decided to open was the .caproj file since it has a list of the layouts, and I wanted to see how easy it was to get info from a xml file. First snag was there was three garbage characters at the start of the xml that prevented it from parsing. Fixed that and found out navigating xml is a pain. I tried doing it with the xml plugin and in javascript. Also the xml plugin doesn't let me modify data, only read it.

    So I made a converter to convert the xml to json so it's easier to navigate, copy and modify in various ways. The plan it to also convert it back to xml when done if I want to save changes.

    What is left to do?

    * Convert the json back to xml for saving.

    * Do some manipulation of instances on a layout. Initial things I had in mind were changing positions, duplicating instances, and destroying instances. Probably will make a simple ui for that purpose.

    * Save a completed new capx file with the modifications.

    It's mostly all done in js, and doing it in a plugin would be too restrictive, and doing it in straight events would take too long and be slow and hard to reuse.

    Anyways cheers.

  • This doesn't work the way you want in fact it works the other way around but just in case you didn't know there's this Ashley's tutorial about"Continuous Preview"

    Again not what you wanted but it can come in handy at times.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)