XML or INI

For code related discussions and questions
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

XML or INI

Post by milo christiansen »

If I were to write programs to convert the current data files to xml or ini format would anyone be interested?

Also, how hard would it be to make the game read a xml or ini file instead of comma delimited like it does now?

And which would be better for modders xml or ini?
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: XML or INI

Post by Per »

It depends on the data which is more readable. Well, except that most XML is not really human readable. I think much of the data we have in CSV format is best suited in that format, and would be very verbose in any other.
User avatar
Zarel
Elite
Elite
Posts: 5770
Joined: 03 Jan 2008, 23:35
Location: Minnesota, USA
Contact:

Re: XML or INI

Post by Zarel »

Yeah, the only things we really need to do in that respect is rename the files to .csv (so they'll be opened automatically by spreadsheet programs), and add descriptive headers to the ones we haven't yet. Some of them might be more suited for INI, but CSV is only slightly less readable, easier to parse, and there's no real reason to change.

XML, on the other hand, is way overkill for anything we do in Warzone.
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: XML or INI

Post by milo christiansen »

Zarel wrote:easier to parse
I agree with that :wink: ,but it would be kind of nice to have the files easier for humans to read.

After much consideration, I think that ini or renaming the files to csv would be the way to go.

It might not be that hard to set it to look for .csv files and if missing look for ini files. That way modders could use ether depending on preference and/or skill.

About descriptive headers, is there a way for me to help with that? I already did some research on the various fields for my stats editor and now that I've found the loading routines the rest should be easy to figure out.

And where are the stat files loaded? I know the routines are in stats.c, but where are they used?
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
i-NoD
Code contributor
Code contributor
Posts: 318
Joined: 30 Nov 2008, 00:42
Location: In the middle of nowhere

Re: XML or INI

Post by i-NoD »

milo christiansen wrote:And where are the stat files loaded? I know the routines are in stats.c, but where are they used?
Short answer: they are used from here when this resource file (for example) is parsed.

Detailed answer: "I'm sorry. My responses are limited. You must ask the right questions." (c)
XD
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: XML or INI

Post by milo christiansen »

The short answer is fine XD , thanks!
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
Wibble199
Trained
Trained
Posts: 194
Joined: 21 Feb 2010, 13:58

Re: XML or INI

Post by Wibble199 »

I would be inter, I often wish to use XML to make a Flash project, related to WarZone 2100, however I gave up because of the sheer time I would need to make the XMLs (Including all the upgrades for each weapon, and which weapons go with which upgrade). Example:

Code: Select all

<Weapon>
		<Name>Machinegun</Name>
		<Type>Normal</Type>
		<Damage>10</Damage>
		<ROF>120</ROF>
		<DPS>3</DPS>
		<Accuracy_S>75</Accuracy_S>
		<Accuracy_L>50</Accuracy_L>
		<Range_S>4</Range_S>
		<Range_L>6</Range_L>
		<HP>75</HP>
		<Weight>200</Weight>
		<Descript>7.62mm machinegun\nBest Targets: Infantry, base structures, wheeled vehicles\nBody Points: Low</Descript>
		<DamageUpgrade>MGDamageUpgrades</DamageUpgrade>
		<ROFUpgrade>MGROFUpgrades</ROFUpgrade>
		<AccuracyUpgrade>-1</AccuracyUpgrade>
	</Weapon>
In the description, the '#NEWLINE#' tells flash to add a new line there.
Damage upgrade is MGDamageUpgrades because there is an XML file called MGDamageUpgrades.xml
ROF upgrade is MGROFUpgrades because there is an XML file called MGROFUpgrades.xml
Accuracy upgrade is -1 because it doesn't exist.

If you could write a program for this, I would be grateful for an eternity :D

Thanks, Wibble199 :)
MagickPanda
Rookie
Rookie
Posts: 17
Joined: 26 Oct 2010, 17:21

Re: XML or INI

Post by MagickPanda »

A lua or similar script language is more flexible and readable than both imo.
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: XML or INI

Post by milo christiansen »

Maybe but these are stat lists not scripts. Lua is planed to replace WZScript, this would be a replacement for TXT files.

In any case this won't be done soon.
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: XML or INI

Post by milo christiansen »

Challenges use ini don't they? Where can I get the documentation for the lib used?
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
Safety0ff
Trained
Trained
Posts: 397
Joined: 18 Jul 2009, 23:23

Re: XML or INI

Post by Safety0ff »

milo christiansen wrote:Challenges use ini don't they? Where can I get the documentation for the lib used?
For the current lib:
http://developer.wz2100.net/browser/lib ... ctionary.h
http://developer.wz2100.net/browser/lib ... niparser.h
For the re-written/future interface:
http://developer.wz2100.net/ticket/2012
Commander_Alt_F4
Greenhorn
Posts: 15
Joined: 13 Jun 2011, 11:23

Re: XML or INI

Post by Commander_Alt_F4 »

you can use QSettings for ini file or QDocDocument (requires XML module) for xml, since it uses qt
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: XML or INI

Post by milo christiansen »

True... good idea, I sort of put a halt on this until I found time to find/write a good ini parser and now that I have one I need to find time to write a program to convert the existing CSV files.

I'm planing to use a sort of XML/INI hybrid called IML that looks something like this

Code: Select all

[section]
    key:string=string value
    ; possible values (the part between : and =) are:
    ; string
    ; int
    ; float
    ; bool 
    ; and DSV
    ; DSV is a special case. It is structured :DSV|= the char after DSV is the delimiter in this case |
    ; Delimiter Separated Value 
    ; No value is considered a string
[/section]
The values are for special pre-processing and things like returning a list or vector from a read on a DSV key
so far the parser is a little incomplete and most of the value related stuff is unimplemented :( but for basic reads of string values everything works.

Only one big problem, the parser was written before I learned how to write "real" parsers so its line based aka it only reads the first two chars on every line to determine the line type :( so I will probably end up rewriting it before to long.

Also it heavily relies on QT so it wasn't really possible to use it until lately.

Now I just need to find the time...
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
Commander_Alt_F4
Greenhorn
Posts: 15
Joined: 13 Jun 2011, 11:23

Re: XML or INI

Post by Commander_Alt_F4 »

well if i were you i would use QSettings instead and use a class that saves the output and initialises throught it

QSettings support grouping (you can see on the Docs)

ill use an example that i have on my free project

(think BackgroundColor and other variables as a QColor)

Code: Select all

    QSettings settings(*initialisation code here*);
    settings.beginGroup("Colors");
    settings.setValue("Background",BackgroundColor->rgb()); //will outuput QRgb which is a typedef of unsigned int
    settings.setValue("Foreground",ForegroundColor->rgb());
    settings.setValue("Text",TextColor->rgb());
    settings.setValue("Lines",LineColor->rgb());
    settings.endGroup();
and the output will be

Code: Select all

[Colors]
Background=4281479730
Foreground=4284769380
Text=4291348680
Lines=4291348680
and

Code: Select all

    QSettings settings(*initialisation code here*);
    settings.beginGroup("Colors");
    settings.setValue("Background",BackgroundColor->rgb()); //will outuput QRgb which is a typedef of unsigned int
    settings.setValue("Foreground",ForegroundColor->rgb());
    settings.setValue("Text",TextColor->rgb());
    settings.setValue("Lines",LineColor->rgb());
    settings.endGroup();

    settings.beginGroup("Colors2"); // Same thing for example purposes
    settings.setValue("Background",BackgroundColor->rgb()); //will outuput QRgb which is a typedef of unsigned int
    settings.setValue("Foreground",ForegroundColor->rgb());
    settings.setValue("Text",TextColor->rgb());
    settings.setValue("Lines",LineColor->rgb());
    settings.endGroup();
and the output will be

Code: Select all

[Colors]
Background=4281479730
Foreground=4284769380
Text=4291348680
Lines=4291348680

[Colors2]
Background=4281479730
Foreground=4284769380
Text=4291348680
Lines=4291348680
however

Code: Select all

    QSettings settings(*initialisation code here*);
    settings.beginGroup("Options");
    settings.beginGroup("Colors");
    settings.setValue("Background",BackgroundColor->rgb());
    settings.setValue("Foreground",ForegroundColor->rgb());
    settings.setValue("Text",TextColor->rgb());
    settings.setValue("Lines",LineColor->rgb());
    settings.endGroup();
    settings.endGroup();
will output

Code: Select all

[Options]
Colors\Background=4281479730
Colors\Foreground=4284769380
Colors\Text=4291348680
Colors\Lines=4291348680
which can take some readability like doing this

Code: Select all

    QSettings settings(*initialisation code here*);
    settings.beginGroup("Options");
    settings.beginGroup("Colors");
    settings.setValue("Background",BackgroundColor->rgb());
    settings.setValue("Foreground",ForegroundColor->rgb());
    settings.setValue("Text",TextColor->rgb());
    settings.setValue("Lines",LineColor->rgb());
    settings.endGroup();

    settings.beginGroup("Colors2"); //same thing for example purposes
    settings.setValue("Background",BackgroundColor->rgb());
    settings.setValue("Foreground",ForegroundColor->rgb());
    settings.setValue("Text",TextColor->rgb());
    settings.setValue("Lines",LineColor->rgb());
    settings.endGroup();

    settings.endGroup();
will output

Code: Select all

[Options]
Colors\Background=4281479730
Colors\Foreground=4284769380
Colors\Text=4291348680
Colors\Lines=4291348680
Colors2\Background=4281479730
Colors2\Foreground=4284769380
Colors2\Text=4291348680
Colors2\Lines=4291348680
note: they can be read like this (for the fist example):

Code: Select all

    QSettings settings(*initialisation code here*);
    settings.beginGroup("Options");
    settings.beginGroup("Colors");
    BackgroundColor->setRgb(settings.value("Background").toUInt());
    ForegroundColor->setRgb(settings.value("Foreground").toUInt());
    TextColor->setRgb(settings.value("Text").toUInt());
    LineColor->setRgb(settings.value("Lines").toUInt());
    settings.endGroup();
    settings.endGroup();
note that is was just an idea...its always wise to have a small code to make it easier to find and fix errors
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: XML or INI

Post by Per »

In master, the challenges are read (and written) using QSettings already.
Post Reply