Wesnoth Unit Creator App

Discussion of all aspects of the game engine, including development of new and existing features.

Moderator: Forum Moderators

Post Reply
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Wesnoth Unit Creator App

Post by Lord-Knightmare »

Hi, everyone!

I didn't know where to post this so I posted it here. Moderators may move this topic to its rightful subthread if I posted in the wrong place.

As the title suggests, I have coded a GUI interface for making Wesnoth unit files.

This is how the current version looks:
GUI with placeholder text
GUI with placeholder text
Yes, I am well aware that I forgot to add a level entry field for it, but this is just a demo and I can always add it in later as well as the other stuff.

Code: Select all

[unit_type]
    id = "Orcish Dumbass"
    name = "Orcish Dumbass"
    race = "orc"
    hitpoints = "50"
    experience = "150"
    advances_to = "null"
    description = "This is a sample unit."
[/unit_type]
This is the source code link:

The Github Repo

For simplicity and avoiding compiling errors for external tests, I have used built-in modules only. QtWidgets would be better but tkinter is the module for the current version.

Please use python 3.7.6 or above for compiling it. I am a bit skeptical on the new 3.8 version of Python so I stayed with the 3.7 version.

Lastly, I would like to hear what the Wesnoth Community has to say regarding this.
Last edited by Lord-Knightmare on December 30th, 2019, 8:28 pm, edited 1 time in total.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Unit Creator App

Post by Elvish_Hunter »

Lord-Knightmare wrote: December 29th, 2019, 8:18 am Yes, I am well aware that I forgot to add a level entry field for it, but this is just a demo and I can always add it in later as well as the other stuff.
I can see that there's a lot of stuff that can be added. Just to say a few things, a checkbutton for {AMLA_DEFAULT} (I've noticed your comment in the code), spinboxes for numerical values like hitpoints, a combobox for the alignment field...
Oh, right, there's no combobox widget in plain Tkinter, you'll have to import the tkinter.ttk module on top of it. My recommendation is to always use ttk on top of Tkinter, otherwise you'll miss some additional widgets and your GUI will get the terrible look Tk applications are (in)famous for.
Lord-Knightmare wrote: December 29th, 2019, 8:18 am For simplicity and avoiding compiling errors for external tests, I have used built-in modules only. QtWidgets would be better but tkinter is the module for the current version.
Fun fact: on Debian-like Linux distributions, tkinter isn't installed by default, so you don't have any guarantee that it's always imported. The script also needs a shebang on its first line.
Lord-Knightmare wrote: December 29th, 2019, 8:18 am I am a bit skeptical on the new 3.8 version of Python so I stayed with the 3.7 version.
Is there any reason for this? Besides, I don't see anything that shouldn't work on 3.8 or even 3.6...
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Wesnoth Unit Creator App

Post by Lord-Knightmare »

Update!

Okay, I have added unit level and an AMLA enabler in the GUI of the app. Additionally, I have included a file_name selector so the app can generate outputs indefinitely or as much as the user wants.
I can see that there's a lot of stuff that can be added. Just to say a few things, a checkbutton for {AMLA_DEFAULT} (I've noticed your comment in the code), spinboxes for numerical values like hitpoints, a combobox for the alignment field...
Oh, right, there's no combobox widget in plain Tkinter, you'll have to import the tkinter.ttk module on top of it. My recommendation is to always use ttk on top of Tkinter, otherwise you'll miss some additional widgets and your GUI will get the terrible look Tk applications are (in)famous for.
I ran into a problem which is showing as IntVar()/StringVar() not being accepted for the checkbox option. I enabled the AMLA to default to "Yes". Any available fix on this?

tkk kinda broke the 'fg' and 'bg' keys but that's not really relevant.
The script also needs a shebang on its first line.
I don't have the faintest clue on what this even means? :hmm:
More clarification please? Maybe a coded example?

Is there any reason for this? Besides, I don't see anything that shouldn't work on 3.8 or even 3.6...
Most packages haven't been ported to 3.8 yet so in order to compile it into an app later on, I need to stick to python3.7 for the time being. pyinstaller and py2app do not work with python 3.8.

Current State:
GUI:
Screenshot 2019-12-31 at 02.10.53.png
Sample output:
Screenshot 2019-12-31 at 02.12.41.png
I guess a further improvement can be made to include image file paths for both the unit and the portrait. And, I guess that just leaves the [attack][/attack] tags.

As for the animations, I am still not sure that if want to push into that much depth but I guess I can add in support for the {GENERIC_ANIMATION WEAPON_NAME UNIT_IMAGE SOUND}.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Wesnoth Unit Creator App

Post by Ravana »

I suggest removing filename selection, instead generate it based on id.

Not sure if it already works that way, but advances_to could suggest based on other files in same directory.
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Wesnoth Unit Creator App

Post by Lord-Knightmare »

I suggest removing filename selection, instead generate it based on id.
I do not think that should be done. Unit id can have whitespaces but filenames need to have underscores instead of whitespaces. AFAIK, python has a built-in function "String".replace(" ","_") to replace one part of a string with another stated part so, I can try tinkering with it.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Wesnoth Unit Creator App

Post by Ravana »

Id is allowed to have whitespace, but I believe it should not.

https://github.com/wesnoth/wesnoth/issues/1847 whitespaces are supported for compatibility only.
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Unit Creator App

Post by Elvish_Hunter »

Lord-Knightmare wrote: December 30th, 2019, 8:24 pm I ran into a problem which is showing as IntVar()/StringVar() not being accepted for the checkbox option. I enabled the AMLA to default to "Yes". Any available fix on this?
StringVar() isn't accepted for the variable= key (and not var=, this one doesn't have any meaning in Tkinter), but either IntVar() or the less known BooleanVar() should work.
Lord-Knightmare wrote: December 30th, 2019, 8:24 pm tkk kinda broke the 'fg' and 'bg' keys but that's not really relevant.
That's because in ttk how a widget looks is handled by styles. On Windows and MacOS, the style used by default makes the application look like a native one.
Lord-Knightmare wrote: December 30th, 2019, 8:24 pm I don't have the faintest clue on what this even means? :hmm:
More clarification please? Maybe a coded example?

Code: Select all

#!/usr/bin/env python3
In Unix-like systems, this line tells the OS which interpreter should be used to run the script, if said script has the executable permission set up.
Two other things I noticed:
  • on name= and description= there's no translation mark added;
  • since a unit description can be quite long, you might consider replacing its Entry widget with a Text widget.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Wesnoth Unit Creator App

Post by Lord-Knightmare »

StringVar() isn't accepted for the variable= key (and not var=, this one doesn't have any meaning in Tkinter), but either IntVar() or the less known BooleanVar() should work.
Not sure how but this isn't working either. :hmm:
In Unix-like systems, this line tells the OS which interpreter should be used to run the script if said script has the executable permission set up.
I knew about this but I never knew this was addressed as a "shebang". Guess I know now.
on name= and description= there's no translation mark added;
since a unit description can be quite long, you might consider replacing its Entry widget with a Text widget.
I have added these in the current version.
GUI Appearance
GUI Appearance
GUI Appearance
Sample Output

Code: Select all

[unit_type]
    id = "Sample Orc"
    name = _ "Sample Orc"
    race = "orc"
    hitpoints = 50
    experience = 100
    level = 2
    {AMLA_DEFAULT}
    advances_to = "null"
    description = _ "This is a sample unit file."
[/unit_type]
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
gnombat
Posts: 682
Joined: June 10th, 2010, 8:49 pm

Re: Wesnoth Unit Creator App

Post by gnombat »

Lord-Knightmare wrote: December 31st, 2019, 10:46 pm I knew about this but I never knew this was addressed as a "shebang". Guess I know now.
The term probably comes from "Sharp Bang", i.e., the "Sharp" character (#) followed by the "Bang" character (!).

https://en.wikipedia.org/wiki/Shebang_(Unix)#Etymology
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Unit Creator App

Post by Elvish_Hunter »

Lord-Knightmare wrote: December 31st, 2019, 10:46 pm Not sure how but this isn't working either.
At line 64 of your script, inside the addAMLACheckbox method, you have this line:

Code: Select all

        # self.check_amla['var'] = self.amla_var
Besides the fact that it's commented out, it's never going to work because 'var' isn't the correct keyword to use.
This one should work instead:

Code: Select all

        self.check_amla['variable'] = self.amla_var
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Wesnoth Unit Creator App

Post by Lord-Knightmare »

At line 64 of your script, inside the addAMLACheckbox method, you have this line:
It's been commented out for a reason. If it's not commented, the entire program fails to compile and I get this:

Code: Select all

self.check_amla['variable'] = self.amla_var
AttributeError: 'Application' object has no attribute 'amla_var'
It says I have no 'amla_var' attribute defined, but however at lines 11-13

Code: Select all

        self.amla_var = BooleanVar(self)
        self.amla_var.set(1)
        self.amla = ""
So, I am a bit perplexed at this.
This one should work instead:
Tried that too. Same case. :hmm: :cry:

EDIT:
I tried to handle the error and made the program compile without commenting out the line

Code: Select all

        try:
            self.check_amla['variable'] = self.amla_var
        except AttributeError as e:
            # show message at terminal
            # but allow program to still compile
            print(e)
This is what I got from the Terminal:
'Application' object has no attribute 'amla_var'
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Unit Creator App

Post by Elvish_Hunter »

Lord-Knightmare wrote: January 2nd, 2020, 1:17 pm This is what I got from the Terminal:

Code: Select all

'Application' object has no attribute 'amla_var'
OK, I found where the problem is :)
This is your __init__ method:

Code: Select all

    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.createWidgets()
        self.amla_var = BooleanVar(self)
        self.amla_var.set(1)
        self.amla = ""
You use the createWidgets method before creating the self.amla_var attribute; at this point, your widget cannot find your variable. To get rid of the error, I just moved the createWidgets call after the variable declaration. Like this:

Code: Select all

    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.amla_var = BooleanVar()
        self.amla_var.set(1)
        self.amla = ""
        self.createWidgets()
Another issue: do you want the Main Stats frame to be around all your widgets, right? Sadly, this isn't the case:
unit creator.png
unit creator.png (38.34 KiB) Viewed 5977 times
This happens because LabelFrame is a container widget, just like Frame, so if you want something to be inside of it you have to specify it as parent in children widgets. For example, self.label_amla = Label(self) should become self.label_amla = Label(self.frame)
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Wesnoth Unit Creator App

Post by Lord-Knightmare »

You use the createWidgets method before creating the self.amla_var attribute; at this point, your widget cannot find your variable. To get rid of the error, I just moved the createWidgets call after the variable declaration. Like this:
:doh: It was that simple? :doh:
Thank you! :D
This happens because LabelFrame is a container widget, just like Frame, so if you want something to be inside of it you have to specify it as parent in children widgets. For example, self.label_amla = Label(self) should become self.label_amla = Label(self.frame)
I did this and everything is now working.

The latest commit is working fine. Now, I can package this as an executable app as version 1.0.
For version 2.0 I have plans on making further additions such as attacks and image files and in that order. For attacks, I am going to add a new frame and there will be dropdown lists for ranged and type. As for weapon specials, I am guessing it will have to be a dropdown list too.

Current GUI interface:
GUI interface
GUI interface
Sample Output files:
Elven_Knight.cfg
without {AMLA_DEFAULT}
(259 Bytes) Downloaded 377 times
Elven_Knight_amla.cfg
with {AMLA_DEFAULT}
(272 Bytes) Downloaded 380 times


Edit: (for Windows Users):
This is the app file which ~9MB in size. Download and do notify me if it's working or not.
Pyinstaller is giving me an epic headache. It's been compressed in a RAR file so uncompress it first.

The App
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
Yomar
Posts: 394
Joined: October 27th, 2011, 5:14 am
Contact:

Re: Wesnoth Unit Creator App

Post by Yomar »

Nothing to handle graphics and animations?
Beholded Wesnoth's Origins.
Max G on WIF
Rank 🌟🌟🌟🌟🌟
Post Reply