ini2json: Convert IDs to real names.
parent
9954fdaebf
commit
999928e70b
|
@ -3,11 +3,34 @@
|
|||
#
|
||||
# Missing : bodypropulsionimd.ini propulsionsounds.ini propulsiontype.ini structuremodifier.ini weaponmodifier.ini
|
||||
#
|
||||
|
||||
BASE="../../../data"
|
||||
|
||||
#
|
||||
# First make dictionary of used IDs
|
||||
#
|
||||
|
||||
function dict
|
||||
{
|
||||
python ini2dict.py ${BASE}/base/stats/$1.ini > id_dict.json
|
||||
python ini2json_generic.py ${BASE}/mp/stats/$1.ini > ${BASE}/mp/stats/$1.json
|
||||
}
|
||||
rm -f id_dict_*.json
|
||||
python ini2dict.py ${BASE}/base/stats/ecm.ini ${BASE}/base/stats/sensor.ini ${BASE}/base/stats/weapons.ini ${BASE}/base/stats/repair.ini \
|
||||
${BASE}/base/stats/construction.ini ${BASE}/base/stats/propulsion.ini ${BASE}/base/stats/structure.ini ${BASE}/base/stats/body.ini \
|
||||
${BASE}/base/stats/templates.ini ${BASE}/mp/stats/research_cam3.ini > id_dict_base.json
|
||||
python ini2dict.py ${BASE}/mp/stats/ecm.ini ${BASE}/mp/stats/sensor.ini ${BASE}/mp/stats/weapons.ini ${BASE}/mp/stats/repair.ini \
|
||||
${BASE}/mp/stats/construction.ini ${BASE}/mp/stats/propulsion.ini ${BASE}/mp/stats/structure.ini ${BASE}/mp/stats/body.ini \
|
||||
${BASE}/mp/stats/templates.ini ${BASE}/mp/stats/research.ini > id_dict_mp.json
|
||||
|
||||
#
|
||||
# Finally make the JSON files
|
||||
#
|
||||
|
||||
function generic
|
||||
{
|
||||
python ini2json_generic.py ${BASE}/base/stats/$1.ini > ${BASE}/base/stats/$1.json
|
||||
python ini2json_generic.py ${BASE}/mp/stats/$1.ini > ${BASE}/mp/stats/$1.json
|
||||
python ini2json_generic.py ${BASE}/base/stats/$1.ini id_dict_base.json > ${BASE}/base/stats/$1.json
|
||||
python ini2json_generic.py ${BASE}/mp/stats/$1.ini id_dict_mp.json > ${BASE}/mp/stats/$1.json
|
||||
}
|
||||
generic ecm
|
||||
generic sensor
|
||||
|
@ -18,7 +41,7 @@ generic propulsion
|
|||
generic structure
|
||||
generic body
|
||||
generic templates
|
||||
python ini2json_research.py ${BASE}/base/stats/research_cam1.ini > ${BASE}/base/stats/research_cam1.json
|
||||
python ini2json_research.py ${BASE}/base/stats/research_cam2.ini > ${BASE}/base/stats/research_cam2.json
|
||||
python ini2json_research.py ${BASE}/base/stats/research_cam3.ini > ${BASE}/base/stats/research_cam3.json
|
||||
python ini2json_research.py ${BASE}/mp/stats/research.ini > ${BASE}/mp/stats/research.json
|
||||
python ini2json_research.py ${BASE}/base/stats/research_cam1.ini id_dict_base.json > ${BASE}/base/stats/research_cam1.json
|
||||
python ini2json_research.py ${BASE}/base/stats/research_cam2.ini id_dict_base.json > ${BASE}/base/stats/research_cam2.json
|
||||
python ini2json_research.py ${BASE}/base/stats/research_cam3.ini id_dict_base.json > ${BASE}/base/stats/research_cam3.json
|
||||
python ini2json_research.py ${BASE}/mp/stats/research.ini id_dict_mp.json > ${BASE}/mp/stats/research.json
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import ConfigParser
|
||||
import json
|
||||
import sys
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print 'Need file parameter(s)'
|
||||
sys.exit(1)
|
||||
|
||||
data = {}
|
||||
for n in range(1, len(sys.argv)):
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.optionxform = str # stop making keys lowercase
|
||||
config.read(sys.argv[n])
|
||||
|
||||
for section in config.sections():
|
||||
name = config.get(section, 'name')
|
||||
if name.startswith('"') and name.endswith('"'):
|
||||
name = name[1:-1]
|
||||
if section in data:
|
||||
print >> sys.stderr, "Error: %s is duplicate in %s" % (section, sys.argv[n])
|
||||
data[section] = name
|
||||
print json.dumps(data, indent=4, separators=(',', ': '))
|
|
@ -2,8 +2,8 @@ import ConfigParser
|
|||
import json
|
||||
import sys
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print 'Need file parameter'
|
||||
if len(sys.argv) < 3:
|
||||
print 'Need file and dictionary parameters'
|
||||
sys.exit(1)
|
||||
|
||||
config = ConfigParser.ConfigParser()
|
||||
|
@ -25,6 +25,8 @@ translation = {
|
|||
}
|
||||
|
||||
data = {}
|
||||
fp = open(sys.argv[2])
|
||||
ids = json.load(fp)
|
||||
for section in config.sections():
|
||||
name = config.get(section, 'name')
|
||||
if name.startswith('"') and name.endswith('"'):
|
||||
|
@ -43,6 +45,8 @@ for section in config.sections():
|
|||
for result in value: # convert numbers
|
||||
if is_number(result):
|
||||
accum.append(int(result))
|
||||
elif result in ids:
|
||||
accum.append(ids[result]) # change ID to real name
|
||||
else:
|
||||
accum.append(result)
|
||||
if len(accum) == 1 and key != 'weapons':
|
||||
|
@ -50,4 +54,6 @@ for section in config.sections():
|
|||
else:
|
||||
entry[key] = accum
|
||||
data[name] = entry
|
||||
data['id'] = section # for backwards compatibility
|
||||
fp.close()
|
||||
print json.dumps(data, indent=4, separators=(',', ': '))
|
||||
|
|
|
@ -2,8 +2,8 @@ import ConfigParser
|
|||
import json
|
||||
import sys
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print 'Need file parameter'
|
||||
if len(sys.argv) < 3:
|
||||
print 'Need file and dictionary parameters'
|
||||
sys.exit(1)
|
||||
|
||||
config = ConfigParser.ConfigParser()
|
||||
|
@ -17,6 +17,8 @@ def is_number(s):
|
|||
return False
|
||||
|
||||
data = {}
|
||||
fp = open(sys.argv[2])
|
||||
ids = json.load(fp)
|
||||
opts = ['researchPoints', 'researchPower', 'keyTopic', 'msgName', 'iconID', 'statID', 'requiredResearch', 'resultComponents',
|
||||
'techCode', 'imdName', 'subgroupIconID', 'requiredStructures', 'redStructures', 'redComponents', 'resultComponents',
|
||||
'replacedComponents']
|
||||
|
@ -35,6 +37,8 @@ for section in config.sections():
|
|||
for result in value: # convert numbers
|
||||
if is_number(result):
|
||||
accum.append(int(result))
|
||||
elif result in ids:
|
||||
accum.append(ids[result]) # change ID to real name
|
||||
else:
|
||||
accum.append(result)
|
||||
if len(accum) == 1:
|
||||
|
@ -69,4 +73,6 @@ for section in config.sections():
|
|||
accum.append(tmp)
|
||||
entry['results'] = accum
|
||||
data[name] = entry
|
||||
data['id'] = section # for backwards compatibility
|
||||
fp.close()
|
||||
print json.dumps(data, indent=4, separators=(',', ': '))
|
||||
|
|
Loading…
Reference in New Issue