Exemplo n.º 1
0
def Parse(worldData=None):
    if not options["entities.timelines"]:
        return
    if worldData == None:
        print('No world data.')
    if worldData["map"] == None:
        print('No map loaded.')
    
    mapName = worldData["map"]["settings"]["mapName"]

    # Timeline
    print(f'Parsing {mapName} Timeline')
    timeline = {
        "name" : f'{mapName} Timeline',
        "type": "Global",
        "is_private": False
    }
    response = kankaapi.create('timelines', timeline)
    worldData["world_timeline_id"] = response["data"]["id"]
    worldData["world_timeline_entity_id"] = response["data"]["entity_id"]

    # Era
    print(f'Parsing {mapName} Current Era')
    era = {
        "timeline_id": worldData["world_timeline_id"],
        "name": "Current",
        "abbreviation": "C",
        "start_year": 0,
        "end_year": None,
        "visiblity": "all"
    }
    response = kankaapi.create(f'timelines/{worldData["world_timeline_id"]}/timeline_eras', era)
    worldData["era_id"] = response["data"]["id"]
Exemplo n.º 2
0
def Parse(worldData=None):
    if not options["entities.rivers"]:
        return
    if worldData == None:
        print('No world data.')
    if worldData["map"] == None:
        print('No map loaded.')

    print(f'Parsing Rivers')
    worldData["riverIds"] = {}
    rivers = worldData["map"]["pack"]["rivers"]
    for river in rivers:
        print(f' Parsing {river["name"]} {river["type"]}')
        location = {
            "name": f'{river["name"]} {river["type"]}',
            "entry": "\n<p>Lorem Ipsum.</p>\n",
            "parent_location_id": worldData["world_location_id"],
            "is_private": False,
            "type": "Watercourse"
        }
        response = kankaapi.create('locations', location)
        worldData["riverIds"][river["i"]] = {
            "location_id": response["data"]["id"],
            "entity_id": response["data"]["entity_id"],
        }

    location = {
        "name": worldData["map"]["settings"]["mapName"],
        "image_url": None,
        "entry": "\n<p>Lorem Ipsum.</p>\n",
        "is_private": False,
        "type": "World"
    }
    response = kankaapi.create('locations', location)

    worldData["world_location_id"] = response["data"]["id"]
    worldData["world_entity_id"] = response["data"]["entity_id"]
Exemplo n.º 3
0
def Parse(worldData=None):
    if not options["entities.provinces"]:
        return
    if worldData == None:
        print('No world data.')
    if worldData["map"] == None:
        print('No map loaded.')

    print(f'Parsing Provinces:')
    worldData["provinceIds"] = {}
    stateIds = worldData["stateIds"]
    provinces = worldData["map"]["pack"]["provinces"][1:]
    seed = worldData["map"]["seed"]

    for province in provinces:
        if province["state"] in stateIds:
            print(f' Parsing {province["fullName"]} (Province)')
            if options["heraldry"]:
                image_url = ironarachne.getHeraldryLink(
                    seed, f'p{province["i"]}')
            else:
                image_url = None

            location = {
                "name": province["fullName"],
                "image_url": image_url,
                "entry": "\n<p>Lorem Ipsum.</p>\n",
                "parent_location_id":
                stateIds[province["state"]]["location_id"],
                "is_private": False,
                "type": "Province"
            }
            response = kankaapi.create('locations', location)
            entity_id = response["data"]["entity_id"]
            # Save the created ids for later
            worldData["provinceIds"][province["i"]] = {
                "location_id": response["data"]["id"],
                "entity_id": entity_id,
            }
            # Attributes
            if options["attributes"]:
                print(f'  : creating attributes')
                kankaapi.createAttribute("Name",
                                         str(province["name"]),
                                         entity_id=entity_id)
                kankaapi.createAttribute("Form Name",
                                         str(province["formName"]),
                                         entity_id=entity_id)
Exemplo n.º 4
0
def Parse(worldData=None):
    if not options["entities.world"]:
        return
    if worldData == None:
        print('No world data.')
    if worldData["map"] == None:
        print('No map loaded.')

    print(f'Parsing {worldData["map"]["settings"]["mapName"]} (World)')

    location = {
        "name": worldData["map"]["settings"]["mapName"],
        "image_url": None,
        "entry": GenerateEntry(worldData),
        "is_private": False,
        "type": "World"
    }
    response = kankaapi.create('locations', location)

    worldData["world_location_id"] = response["data"]["id"]
    worldData["world_entity_id"] = response["data"]["entity_id"]
Exemplo n.º 5
0
def Parse(worldData=None):
    if not options["entities.biomes"]:
        return
    if worldData == None:
        print('No world data.')
    if worldData["map"] == None:
        print('No map loaded.')

    print(f'Parsing Biomes')
    worldData["biome_data"] = {}
    biomes = worldData["map"]["biomesData"]
    for biomeId in biomes["i"]:
        print(f' Parsing {biomes["name"][biomeId]}')
        note = {
            "name": biomes["name"][biomeId],
            "entry": "\n<p>Lorem Ipsum.</p>\n",
            "is_private": False,
            "type": "Biome"
        }
        response = kankaapi.create('notes', note)
        worldData["biome_data"][biomeId] = {
            "note_id": response["data"]["id"],
            "entity_id": response["data"]["entity_id"],
        }
Exemplo n.º 6
0
def Parse(worldData=None):
    if not options["entities.states"]:
        return
    if worldData == None:
        print('No world data.')
    if worldData["map"] == None:
        print('No map loaded.')

    diplomacyValues = {
        "Ally": {
            "attitude": 50,
            "colour": "#00b300"
        },
        "Friendly": {
            "attitude": 25,
            "colour": "#d4f8aa"
        },
        "Neutral": {
            "attitude": 0,
            "colour": "#edeee8"
        },
        "Suspicion": {
            "attitude": -25,
            "colour": "#eeafaa"
        },
        "Enemy": {
            "attitude": -100,
            "colour": "#e64b40"
        },
        "Unknown": {
            "attitude": 0,
            "colour": "#a9a9a9"
        },
        "Rival": {
            "attitude": -50,
            "colour": "#ad5a1f"
        },
        "Vassal": {
            "attitude": 100,
            "colour": "#87CEFA"
        },
        "Suzerain": {
            "attitude": 100,
            "colour": "#00008B"
        },
    }

    print(f'Parsing States')
    worldData["stateIds"] = {}
    states = worldData["map"]["pack"]["states"]
    seed = worldData["map"]["seed"]

    for state in states:
        if state["name"] != "Neutrals":
            print(f' Parsing {state["fullName"]} (State)')
            if options["heraldry"]:
                image_url = ironarachne.getHeraldryLink(seed, f's{state["i"]}')
            else:
                image_url = None

            location = {
                "name": state["fullName"],
                "image_url": image_url,
                "entry": GenerateEntry(worldData, state),
                "parent_location_id": worldData["world_location_id"],
                "is_private": False,
                "type": "State"
            }
            response = kankaapi.create('locations', location)
            entity_id = response["data"]["entity_id"]
            worldData["stateIds"][state["i"]] = {
                "location_id": response["data"]["id"],
                "entity_id": entity_id,
            }

            if options["attributes"]:
                print(f'  Parsing attributes')
                kankaapi.createAttribute("Name",
                                         str(state["name"]),
                                         entity_id=entity_id)
                kankaapi.createAttribute("Form",
                                         str(state["form"]),
                                         entity_id=entity_id)
                kankaapi.createAttribute("Form Name",
                                         str(state["formName"]),
                                         entity_id=entity_id)
                kankaapi.createAttribute("Burgs",
                                         str(state["burgs"]),
                                         entity_id=entity_id)
                kankaapi.createAttribute("Area",
                                         f'~{str(state["area"])} acres',
                                         entity_id=entity_id)
                kankaapi.createAttribute("Type",
                                         str(state["type"]),
                                         entity_id=entity_id)
                kankaapi.createAttribute("Expansionism",
                                         str(state["expansionism"]),
                                         entity_id=entity_id)
                kankaapi.createAttribute(
                    "Total Population",
                    "{Urban Population}+{Rural Population}",
                    entity_id=entity_id)
                kankaapi.createAttribute("Urban Population",
                                         str(round(state["urban"] * 1000)),
                                         entity_id=entity_id)
                kankaapi.createAttribute("Rural Population",
                                         str(round(state["rural"] * 1000)),
                                         entity_id=entity_id)
                kankaapi.createAttribute("Military Alert",
                                         str(state["alert"]),
                                         entity_id=entity_id)

            # TODO sort by date while adding
            if options["entities.states.history"]:
                print(f'  Parsing history')
                timelineId = worldData["world_timeline_id"]
                eraId = worldData["era_id"]
                for campaign in state["campaigns"]:
                    print(f'   Parsing {campaign["name"]} (Campaign)')
                    element = {
                        # TODO add an actual calendar entity
                        "name": campaign["name"],
                        "timeline_id": timelineId,
                        "era_id": eraId,
                        "date": f'{campaign["start"]}-{campaign["end"]}',
                        "entry":
                        f'\n<p>[location:{entity_id}] campaign from {campaign["start"]}-{campaign["end"]}.</p>\n',
                        "is_private": False,
                        "visiblity": "all"
                    }
                    response = kankaapi.create(
                        f'timelines/{timelineId}/timeline_elements', element)

    # relations
    for state in states:
        if state["name"] == "Neutrals":
            continue
        state_entity_id = worldData["stateIds"][state["i"]]["entity_id"]
        if options["entities.states.neighbors"]:
            print(f' Parsing {state["fullName"]} neighbors relations')
            for neighbour in state["neighbors"]:
                if neighbour in worldData["stateIds"]:
                    target_id = worldData["stateIds"][neighbour]["entity_id"]
                    kankaapi.createRelation(relation="Neighbour",
                                            owner_id=state_entity_id,
                                            target_id=target_id)
        if options["entities.states.diplomacy"]:
            print(f' Parsing {state["fullName"]} diplomacy relations')
            for i, diplomacy in enumerate(state["diplomacy"]):
                if i != 0 and i != state["i"] and (
                        options["entities.states.diplomacy.all"] or
                    (diplomacyValues[diplomacy]["attitude"] != 0)):
                    target_id = worldData["stateIds"][i]["entity_id"]
                    kankaapi.createRelation(
                        relation=diplomacy,
                        owner_id=state_entity_id,
                        target_id=target_id,
                        attitude=diplomacyValues[diplomacy]["attitude"],
                        colour=diplomacyValues[diplomacy]["colour"])
Exemplo n.º 7
0
def Parse(worldData=None):
    if not options["entities.burgs"]:
        return
    if worldData == None:
        print('No world data.')
    if worldData["map"] == None:
        print('No map loaded.')

    print(f'Parsing Burgs:')
    # features = ["capital", "port", "citadel", "plaza", "walls", "shanty", "temple"]
    worldData["burgIds"] = {}
    map = worldData["map"]
    burgs = map["pack"]["burgs"][1:]
    seed = map["seed"]
    gridCells = map["grid"]["cells"]
    cells = map["pack"]["cells"]
    biomes = map["biomesData"]
    rivers = map["pack"]["rivers"]
    cultures = map["pack"]["cultures"]
    religions = map["pack"]["religions"]

    for burg in burgs[1:100]:
        if burg["state"] in worldData["stateIds"]:
            print(f' Parsing {burg["name"]} (Burg)')
            if options["heraldry"]:
                image_url = ironarachne.getHeraldryLink(seed, f'b{burg["i"]}')
            else:
                image_url = None

            cellId = burg["cell"]

            h = int(gridCells["h"][cellId])
            prec = int(gridCells["prec"][cellId])
            f = int(gridCells["f"][cellId])
            t = int(gridCells["t"][cellId])
            temp = int(gridCells["temp"][cellId])

            conf = int(cells["conf"][cellId])
            fl = int(cells["fl"][cellId])
            population = cells["pop"][cellId]
            riverId = int(cells["r"][cellId])

            biomeId = int(cells["biome"][cellId])
            provinceId = int(cells["provinces"][cellId])
            cultureId = int(cells["culture"][cellId])
            roadId = int(cells["road"][cellId])
            religionId = int(cells["religions"][cellId])

            biomeName = biomes["name"][biomeId]

            # print(f' cultureId {cultureId}')
            # print(f'   riverId {riverId}')
            # print(f'religionId {religionId}')
            culture = list(filter(lambda c: c["i"] == cultureId, cultures))[0]
            # road = list(filter(lambda r: r["i"] == roadId, roads))[0]
            if riverId != 0:
                river = list(filter(lambda r: r["i"] == riverId, rivers))[0]
            religion = list(filter(lambda r: r["i"] == religionId,
                                   religions))[0]

            print(f'h {h}')
            print(f'prec {prec}')
            print(f'f {f}')
            print(f't {t}')
            print(f'temp {temp}')
            print(f'provinceId {provinceId}')
            print(f'conf {conf}')
            print(f'fl {fl}')
            print(f'      road {roadId}')

            print(f'population {population}')
            print(f'     biome {biomeName}')
            print(f'   culture {culture}')
            print(f'     river {river}')
            print(f'  religion {religion}')

            location = {
                "name":
                burg["name"],
                "image_url":
                image_url,
                "entry":
                "\n<p>Lorem Ipsum.</p>\n",
                "parent_location_id":
                worldData["provinceIds"][provinceId]["location_id"],
                "is_private":
                False,
                "type":
                "Burg"
            }
            response = kankaapi.create('locations', location)
            # Save the created ids for later
            worldData["burgIds"][burg["i"]] = {
                "location_id": response["data"]["id"],
                "entity_id": response["data"]["entity_id"],
            }

            entity_id = response["data"]["entity_id"]
            # Attributes
            if options["attributes"]:
                print(f'  Parsing attributes')
                kankaapi.createAttribute("Name",
                                         str(burg["name"]),
                                         entity_id=entity_id)
                kankaapi.createAttribute("Population",
                                         str(round(burg["population"] * 1000)),
                                         entity_id=entity_id)
                kankaapi.createAttribute("Is Capital",
                                         str(burg["capital"] == 1),
                                         entity_id=entity_id,
                                         att_type="checkbox")
                kankaapi.createAttribute("Has port",
                                         str(burg["port"] == 1),
                                         entity_id=entity_id,
                                         att_type="checkbox")
                kankaapi.createAttribute("Has citadel",
                                         str(burg["citadel"] == 1),
                                         entity_id=entity_id,
                                         att_type="checkbox")
                kankaapi.createAttribute("Has plaza",
                                         str(burg["plaza"] == 1),
                                         entity_id=entity_id,
                                         att_type="checkbox")
                kankaapi.createAttribute("Has walls",
                                         str(burg["walls"] == 1),
                                         entity_id=entity_id,
                                         att_type="checkbox")
                kankaapi.createAttribute("Has shanty town",
                                         str(burg["shanty"] == 1),
                                         entity_id=entity_id,
                                         att_type="checkbox")
                kankaapi.createAttribute("Has temple",
                                         str(burg["temple"] == 1),
                                         entity_id=entity_id,
                                         att_type="checkbox")