Defold utility library for python

EDIT: I made one for Python! I call it DefTree and there is forum post about it

I like python and I like Defold, but I don’t like long boring repetitive task that could (read: should) be scripted. Unfortunately because I can’t really parse the file format that Defold uses I find it extremely hard to make small scripts that would help a lot. This also makes it harder to create workflow and pipeline tools.

If I had a genie and could wish wildly, I would wish for a DefoldUtil library! It would maybe work something like these examples below. I have been thinking on it for a while and have done some tests, but unfortunately it is a bit too hard, it would have been easier if the format was json or xml or something that I didn’t have to write a parser for myself. But then if it was json or xml I could have written tools and script for it without this.

# Example how a defold util script could look like
# This would of course include all types of files so you can edit them in scripts

import DefoldUtil as du

my_file = "C:/Repositories/DefoldProject/Assets/lobby.gui"
gui_file = du.parse(my_file)


# Example: Adding forgotten layers
for node in gui_file.nodes:
    if node.layer not in gui_file.layers:
        gui_file.layers.add(node.layer)


# Example: Adding new layer
for node in gui_file.nodes:
    layer_name, _ = node.texture.split("/")
    node.layer = layer_name
    gui_file.layers.add(layer_name)


# Example: "Random stuff"
if "gui.material" in gui_file.material:
    for node in gui_file.nodes:
        node.inherit_alpha = False

du.dump(gui_file, my_file)

Is this a feeling only I have? What is the general thoughts about something like this? Is there a easier way to do something like this? Would love to hear peoples thoughts and opinions on this!

2 Likes

I’m thinking that if there’s really a need for a script to be run in a terminal to get Defold to behave in a certain way then Defold is either used inthe wrong way or there’s a missing feature in Defold somewhere (most likely it’s the latter).,

Sometimes people have ‘problem’ that is pipeline related.

A example; A team is always building their UI in Photoshop or something else. Instead of then saving out each single image then adding it to Defold, adding them to a atlas, creating a gui file, creating tons of nodes in that gui file move them around and so on. Someone in the team could write a exporter for photoshop that creates all this in Defold. Reducing the amount of work the dev have to do by a lot, a couple of clicks instead of hours of work.

Another; Some art is changed the template that is using this art is now always 10 px wrong in x and needs to be rotated with 15 degrees, but only in collections that are using this other gui scene or is in a particular folder.

Or maybe they want to add layers into a scene that have been forgotten.

Or maybe adding a new layer depending on the texture name.

Or maybe if the scene have a particular material they want to set the inherit_alpha to False.

Maybe they have some user files that always needs a special setup, this setup always takes 30 min but could be scripted to one click.

These are just some random examples but hopefully they show what I mean, this isn’t nice to have because Defold is used wrong or that there is a missing feature, the goal is empower a game team to remove repetitive tasks.

I agree with you. I wrote a whole helper application just to do those kinds of stuff during the work with Hammerwatch, such as converting from the format of the original Hammerwatch game into .atlas or .tilesources. That being said, I have created a parser/exporter for some of the Defold file formats, but in C#. I could probably share it if someone have the need.

2 Likes

I would very much like to see it! I am sure more people will come think about similar problems in the future and would like to also take a look. :smile:

I’ll take a look at it and see if it is suitable for the public eye… :smile: If it is I’ll upload it to GitHub.

I like this! I don’t mind if a team prefers to do GUI and layouting work in Photoshop (using slices) but when this has to be taken into Defold there is way too much of a hassle.

1 Like

These are great examples. We are definitely looking at empowering our users in various ways. In some way or the other we want you to be able to tailor the pipeline to specific needs.

For the time being it should be pretty easy in many cases to write scripts that generate or modify Defold data files.

Would be nice, but I would prefer lua over python/C#

Ok - so I have now uploaded what I have to GitHub. You can find it here: https://github.com/johnnyjr/defold-stuff

The parser library is very crude and written to work for my specific use-case (and on Mac) - so it might very well be that it doesn’t work on PC and it will certainly not read even close to all file formats produced by Defold. Also as I look through it, I clearly see a lot of stuff that could be made simpler - so take it for what it is and use as (and if) you please.

4 Likes