cubequest/questhelper/map/map_renderer.py
henriquenakashima e568a06872 Crop icons
2021-03-28 15:22:34 -04:00

50 lines
1.7 KiB
Python

from map.quest_map import MapEncounter, QuestMap, EncounterType
from typing import List, Dict, Optional
_ICONS = {
EncounterType.BATTLE_REGULAR: 'noun_Battle_3647629_cropped.png',
EncounterType.BATTLE_ELITE: 'noun_Shield_3806325_cropped.png',
EncounterType.BATTLE_BOSS: 'noun_dragon_3820621_cropped.png',
EncounterType.TOWN_TAVERN: 'noun_Beer_3054928_cropped.png',
EncounterType.TOWN_DOCKS: 'noun_Caravel_2421659_cropped.png',
EncounterType.TOWN_MARKET: 'noun_Store_786819_cropped.png',
EncounterType.TOWN_LIBRARY: 'noun_Library_3820590_cropped.png',
EncounterType.TOWN_WORKSHOP: 'noun_cogs_442166_cropped.png',
EncounterType.TOWN_TOWN_HALL: 'noun_brussels town hall_3284349_cropped.png',
EncounterType.TOWN_TEMPLE: 'noun_temple_2382601_cropped.png',
EncounterType.TOWN_REST: 'noun_Tent_3814999_cropped.png',
EncounterType.TOWN_ROAD: 'noun_Hiking Trail_2686687_cropped.png',
}
def render_map(quest_map: QuestMap) -> List[Dict]:
rendered_encounters = []
row: List[MapEncounter]
for r, row in enumerate(quest_map.encounters):
for c, encounter in enumerate(row):
rendered_encounter = _render_encounter(r, c, encounter)
if rendered_encounter is not None:
rendered_encounters.append(rendered_encounter)
return rendered_encounters
def _render_encounter(r: int, c: int, encounter: MapEncounter) -> Optional[Dict]:
if encounter.type == EncounterType.INACCESSIBLE:
return None
icon = f'map/{_ICONS[encounter.type]}'
x = 120 * c
y = 100 * r
w = 40
h = 40
return {
'description': encounter.description,
'src': icon,
'x': x,
'y': y,
'w': w,
'h': h,
}