aboutsummaryrefslogtreecommitdiff
path: root/build/content/autolevel.py
blob: 51d30f3f86005057b4ae1338119245f19f66563b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json

def vectorize (obj, forbidlist, _):
    for c in obj:
        for key in c:
            if not(key in forbidlist):
                val = c[key]
                try: val = int(val);
                except: pass
                try: val = float(val);
                except: pass
                c[key] = [val for i in range(3)]
    
def query (obj, allowlist, op):
    for c in obj:
        for key in c:
            if key in allowlist:
                c[key] = op(c[key])
                

def comp(filename, l, fun, op=None):
    with open(filename+".txt", "r") as f: obj = json.loads(f.read())
    fun(obj, l, op)
    with open(filename+"-new"+".txt", "w") as f:
        f.write(json.dumps(obj, indent=4))
    
if __name__ == "__main__":
    #comp("weapons", ["name", "damage_type"])
    #comp("augments", ["name"])
    #comp("batteries", ["name"])
    #comp("armor", ["name"])
    #comp("chassis", ["name"])
    #comp("brains", ["name"])
    #comp("brains", ["name"])
    
    amt = .5
    perc_inc = lambda x: [x[i]*(1.0+(i/2.0)*amt) for i in range(3)]
    comp("weapons", ["damage"], query, perc_inc)