Beispiel #1
0
def parse(item_holder=None, json_file=None, file=None):
    if json_file != None:
        with open(json_file, "r") as f:
            out = json.loads(f.read())

    elif item_holder != None:
        out = eval(item_holder)  #dict(item_holder)

    else:
        raise ValueError("no item holder or json file assigned")

    out = item_parser.parse(out)

    if file == None:
        print(out)
    else:
        if file != None:
            with open(file, "w") as f:
                file.write(json.dumps(out))
            "name": item.Name,
            "type": item.Type,
            "properties": item.Properties,
            "properties2": item.Properties2,
            "material": item.Material,  # sound/etc for it
            "file": item.FileName,
            "fileX": item.TexX,
            "fileY": item.TexY,
            "spread": item.StorageType,
            "visual": item.VisualType,
            "hardness": item.Hardness,
            "collision": item.CollisionType,
            "rarity": item.Rarity,
            "regentime": item.RegenTime
        }
        if item.AltFilePath != "":
            obj[item.ID]["extraString"] = item.AltFilePath
        if item.Type == 20:
            obj[item.ID]["clothingType"] = item.ClothingType
        if item.MaxHold != 200:
            obj[item.ID]["maxHold"] = item.MaxHold

    item_file = open("items.json", "w")
    item_file.write(json.JSONEncoder(indent=4).encode(obj))
    item_file.close()


if __name__ == '__main__':
    items = item_parser.parse("items.dat")
    write_json_data_file(items)