Skip to content

Converting items to CSV

Justin Jacobs edited this page Oct 21, 2013 · 1 revision

In flare-game we are currently in a situation, in which we'll soon need to define lots of items. Have a look here: All items on the screen including all attributes: Screenshot from 2013-04-17 18:19:25

How this is done? Well first of all I converted the item database to a csv file, which then can easily be imported to your spread sheet processor of choice. Here is the ItemsToCSV.py script:

#!/usr/bin/python
# All used attributes can be extracted from the items txt file by
# cat items.txt  |grep "=" | tr "=" " "|awk '{print $1 }' |sort |uniq
import copy
emptyitem={"abs":"", "bonus":"", "dmg_melee":"", "dmg_ment":"", "dmg_ranged":"", "flavor":"", "gfx":"", "icon":"", "id":"", "item_type":"", "loot_animation":"", "max_quantity":"", "name":"", "power":"", "power_desc":"", "power_mod":"", "price":"", "price_sell":"", "quality":"", "rand_vendor":"", "req":"", "soundfx":"", "stepfx":""}

items=[]
f=open("items.txt", 'r')
lines=f.readlines()
f.close()

juststarting=True
for line in lines:
    if len(line.strip()) == 0:
        continue
    if line.startswith("#"):
        continue
    if line.startswith("["):
        if not juststarting:
            items+=[copy.deepcopy(theitem)]
        juststarting=False
        theitem=copy.deepcopy(emptyitem)
    else:
        pos = line.find("=")
        key = line[:pos]
        val = line[pos+1:].strip()
        assert(key in theitem)
        theitem[key]=val

items+=[copy.deepcopy(theitem)]
for attr in emptyitem:
    print attr,"\t",
print

for item in items:
    for value in item:
        print item[value], "\t",
    print
Clone this wiki locally