Reusable Object Templates

Hello everyone, I’m Mohamed Thabet, a Google Summer of Code 2017 student, my project is creating Reusable Object Templates.

You can find more about it on github(Object templates #70).

My proposal discusses implementation details and UI Mocks, feel free to post any questions or suggestions.

3 Likes

Your proposal looks great, I didn’t find anything that I would change anything about it. I’m really looking forward to this feature!

Thank you :smile:

First of all thanks for putting up a very well thought-through proposal! You went into everything from mockups to looking at existing functionality and relevant code and finally the data storage format. I think it will guide us well.

Some feedback from my side:

Updating a saved template

The “Template Editor” you show basically only shows a property editor. This works well for custom properties, but not for visual things like size, rotation, polygons or the tile of tile objects.

Personally, I kind of fear we may need a rather full-blown editor view for editing templates, similar to the Tile Collision Editor (but in addition it may need the Tilesets view). Possibly the TemplateEditor should get its own tab alongside other documents like maps and tilesets.

Collections format

The proposal proposes the following format:

 <template name="Old Tree" gid="30">
  <properties>
   <property name="type" value="tree"/>
   <property name="width" value="32" locked="true"/>
   <property name="height" value="32" locked="true"/>
  </properties>
 </template>

I think it is too different from how objects are stored in the TMX format. My suggestion would be to keep it largely the same:

 <template name="Old Tree" id="1">
  <object type="tree" width="32" height="32" gid="30">
   <properties>
    <property name="custom-property" value="tree" type="string" locked="true"/>
   </properties>
  </object>
 </template>

I understand this doesn’t immediately allow for storing the “locked” status for built-in properties like size and rotation, and I would suggest to consider these ‘overridable’ by default and maybe eventually introduce another XML element for storing the locked state of these things if considered useful.

Wrapping the object element inside of a template element is done to enable more code re-use and well as in order to make the format more flexible for the future. We may want to support multi-object templates or layer templates eventually.

I would say the top-level element should be templates rather than collection, as should be the element used to refer to the templates from the map file. Similarly, in the code I would call the new dock TemplatesDock instead of CollectionsDock.

That’s it for now, just let me know what you think. Thanks again for joining us and I’m looking forward to see this project through!

That is a really well written proposal, great job! :slight_smile:

Thanks :smile:, good luck with your project.

1 Like

Thank you, I hope I manage to complete the project as expected :smile:.

I assumed everything will be done by typing but didn’t consider how inconvenient it would be, a dedicated editor would be nice but would need some extra work and it can be also used to create templates, another way would be to update the template according to the instances, so if the size of an instance changes, the template would change accordingly, so a locked property in that context would be better called a shared property, the pull request that changes the tile of an object might be useful in that case :sweat_smile:, one downside is that editing a template will require creating an instance.

Hmm, I agree, reusing the object format would be optimal but I think having the ability to lock the geometry is important, I think introducing the element that aggregates the names of all the locked properties will work fine, unless there is a custom property called width :smile:.

I’m not sure yet how XML is handled in the code, so currently I will have to check it out. I spent more time than expected with the objects search so didn’t have enough time for exploring the code, anyway I will start implementing exporting an object as a template through out this week, I will notify you of any new updates.

Thanks for the review.

What I would suggest, given the current proposal, is that this work could be made a little bit more generic so that it could be used later on.

What I mean is to completely separate templates (as bags of properties) from the Object cloning, because templates (as bags of properties) could be very useful to make similar features with other items, and not only for Objects.

I would also prefer if there was a right click specific menu to select all cloned objects, instead of just clicking the entry in the list. This will make it more generic for future added UI features.

Could you please give examples of other items that might require having templates?

And I think adding a menu item to select all clones is a good idea, thank you.

@bjorn I agree with choosing templates dock as the name of the dock, but I think the name templateGroup might be fine for the top element in the xml file as well as the document that contains the templates as we should be able to import multiple groups in the templates dock, so a button tool tip might be something like import template group rather than import templates, also it will be similar to object groups.

Implementation wise I think a collection will be analogous to the MapDocument class and will have similar functionality in many areas, would this be a good approach?

hey guys

this feature seems extremely useful for level designer

is it possible to use this feature right now as a plugin?
or maybe someone knows when will it be available

@Yuriy_Dorogoy Glad to hear that. I’m currently working on it, expect a post probably during this week demonstrating how it works in Tiled.

Also it will be part of the development snapshot pretty soon so you will be able to check it out yourself.

Hello everybody, I have been working on the template project for a while now. This is the first preview of the new features, let’s get going!

Introduction

Reusable object templates allow saving any object in Tiled and using it many times. All instances of the template are linked, so a change to the original template will be reflected on all template instances. Here is a preview of the workflow of using templates.

Saving objects as a templates

Saving an object is done by right clicking and selecting the required group to save it to. Group files are XML or JSON file holding multiple templates and can be loaded in Tiled to be used in any map.

Creating template instances

An instance of the template can be created either by dragging the template into the map or using the template creation tool.

.

Editing templates

The dock view serves two purposes, showing how the template looks and allowing changing properties of the template. Instances are immediately updated after any change and the changes can be undone.

The project is in progress and there are more features to be added. Feel free to post your comments and feedback.

3 Likes

Looks amazing! I’m building online rogue-like game with Tiled, and templates are so important for procedural generated content, can’t wait to use that :slight_smile:

Hey! Is it possible to get somehow current version of this plugin?

You can try out the current development version by installing a development snapshot:

Great, thank you!