Jump to content

Script template refactor


buckmaster

Recommended Posts

This hasn't been announced extremely publicly, but the issue has been hanging around on GitHub for ages now, with a corresponding discussion at GG. I thought I'd bring it up again since we're nearing the release of at least the preview version of 3.7.


The idea, briefly, is to move all the stock template scripts around so that we don't have so much duplication. Two examples are the entire core/ directory, and more egregiously, the tools/ directory, both of which are identical duplicated in Full/ and Empty/, and would have to be duplicated in any other templates you added. This is frustrating and irritating, so we thought we'd do something about it.


My proposal is to move common script code into a top-level directory Packages, which looks like this currently. There's, for example, a Core package, and an Editors package. This way, those scripts aren't duplicated. So, before, your folders looked like this:

 

Templates/
   Full/
       tools/
   Empty/
       tools/

 

But now they'll look like this:

 

Templates/
   Full/
   Empty/
Packages/
   Editor/
       tools/

 

This means that when you create a project, instead of just copying the template to the new project, you must also copy the package scripts you want. I've made some changes to the Project Manager to do this automatically, the way it currently copies templates. However, this also required some additional infrastructure: a template.xml file in each template dictating which packages should be copied (since you don't just want all of them).


Unfortunately I wasn't able to get this to work with the Project Manager UI, so you can't choose which packages to include at project generation time - if you want additional packages, you either need to edit template.xml, or copy the package manually after project creation.


@Azaezel mentioned that this seems like a large change to be introduced, especially without much fanfare. My reasons are that it doesn't actually change the structure of a project, or any code - just moves it around. Projects generated the new way should look identical to projects generated the old way. And it does cut down on a lot of duplicated code that needs to be updated twice every time.


Anyway, the point of this post is to raise awareness, but also to make sure I haven't made any fatal miscalculations that mean this is a bad idea. The obvious large downside is that this change will break any pull-requests involving changes to the templates, but I'm happy to weather that and help fix/resubmit them.

Link to comment
Share on other sites

  • 2 weeks later...

I just made a fairly significant update to the Project Manager and the structure of the packages. I realised that if, for example, you wanted a package to be a git repository, then the .git directory would be copied from the package to your game template, which was a bad thing. Ditto with, for example, a package readme.


So I've edited the PM to look for a 'package/' directory inside the package. Now a package ends up looking like this:

 

Packages/
   Editor/
       stuff here
       package/
           tools/

 

This makes it more gooderer and stuff. I also renamed the 'path' attribute in template.xml to 'name', since that makes sense.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...