[Patch] Arbitary number of parameters in VarText.

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

[Patch] Arbitary number of parameters in VarText.

#1 Post by Mitten.O »

This patch allows you to have an arbitrary number of parameters of the same type in a VarText.
The scheme is %type:label%.
For example, %planet:my_planet&. This will perform the same lookup as always,
but looks for the data with name "my_planet" instead of "planet", so that you
can have many params of the same type.

The patch should be fully backwards compatible: if the template has a type without
a label, the type is used is used as the label. Therefore, %planet% finds the parameter "planet" as before.

To make this change easier to implement, I revised VarText.cpp by
replacing the long chain of if else ifs with a function lookup table.

This patch came up in the Complex Save Preview thread, but this patch is independent of that one.
This is, in fact, in a small conflict, since that one adds this feature for rawtext only and uses a different syntax.
Therefore, after one of these is applied, the other one needs to be altered a bit.
(To be precise, if this is applied first, the preview thing should not touch VarText and use rawtext: instead of raw: in en.txt,
and if the preview is applied first, this needs to delete its changes in VarText and change the raw: to rawtext: in en.txt)

I'll fix the other one if and when one of these enters the repo.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Any code by me in this post is released under GPL 2.0 or later.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [Patch] Arbitary number of parameters in VarText.

#2 Post by Geoff the Medio »

Builds and runs OK for me. Do you have a quick test script that uses two of the same type of VarText reference that will pop up at the start of a new game to test?

Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

Re: [Patch] Arbitary number of parameters in VarText.

#3 Post by Mitten.O »

The way you say that makes it sound like you have system for this sort of thing?

(I actually tested it against the preview tooltips, but they obviously don't exist here, so um...)
Any code by me in this post is released under GPL 2.0 or later.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [Patch] Arbitary number of parameters in VarText.

#4 Post by Geoff the Medio »

No, I just meant did you write up an effect to generate a sitrep, or some other bit of coding, to produce a sitrep with two vartext references to objects of the same type, without the need to apply and build a big and mostly-unrelated patch.

I suppose that's a "no, except for the save dialog patch", then?

Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

Re: [Patch] Arbitary number of parameters in VarText.

#5 Post by Mitten.O »

Made a test. Found a bug when used from scripts. Please hold.
Any code by me in this post is released under GPL 2.0 or later.

Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

Re: [Patch] Arbitary number of parameters in VarText.

#6 Post by Mitten.O »

There. Fixed.
And included a separate test patch,
which if applied will give you a bunch of silly messages on the third turn.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

[The extension patch has been deactivated and can no longer be displayed.]

Any code by me in this post is released under GPL 2.0 or later.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [Patch] Arbitary number of parameters in VarText.

#7 Post by Geoff the Medio »

Seems to work fine. Committed.

Post Reply