Skip to content

Commit

Permalink
New version.
Browse files Browse the repository at this point in the history
  • Loading branch information
NiHoel committed Apr 6, 2023
1 parent 3061b1b commit 5ccf26a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 261 deletions.
264 changes: 4 additions & 260 deletions savegame_visualizer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,14 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
},
"tags": []
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Image(value=b'GIF89a\\xf2\\x01\\xf2\\x01\\xf7\\xa3\\x00\\xd7\\xd7\\xda\\xd6\\xd6\\xd9\\xd8\\xd8\\xdb\\xd7\\xd7\\xd9\\xf4\\xf4\\xf4\\x…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"import ipywidgets as widgets\n",
"with open(\"imgs/loading-buffering.gif\", \"rb\") as f:\n",
Expand All @@ -48,44 +33,14 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
},
"tags": []
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Dropdown(index=1, options=('chinese', 'english', 'french', 'german', 'italian', 'japanese', 'korean', 'polish'…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0d104e9026e04beaa01fba1bf7c57d90",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Button(description='OK', style=ButtonStyle()),))"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"import importlib\n",
"from IPython.display import clear_output\n",
Expand All @@ -106,217 +61,6 @@
"\n",
"ui.display()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'NoneType' object has no attribute 'buildings'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn [3], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtools\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01ma7s_model\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m----> 2\u001b[0m hex_to_int(\u001b[38;5;28mlist\u001b[39m(\u001b[43mui\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_island\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbuildings\u001b[49m\u001b[38;5;241m.\u001b[39mvalues())[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m.\u001b[39mnode\u001b[38;5;241m.\u001b[39mfind(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m./Variation\u001b[39m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39mtext)\n",
"\u001b[1;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'buildings'"
]
}
],
"source": [
"from tools.a7s_model import *\n",
"hex_to_int(list(ui.get_island().buildings.values())[0].node.find(\"./Variation\").text)\n"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [],
"source": [
"def get_stamp():\n",
" self = ui.get_island()\n",
" options = ui.get_options()\n",
" \"\"\"\n",
"\n",
" Args:\n",
" options: See get_layout()\n",
"\n",
" Returns: XML Tree that can be saved and used as a stamp in Anno\n",
"\n",
" \"\"\"\n",
" if len(self.buildings) == 0:\n",
" return None\n",
"\n",
" e_options = options.get(\"exclude\", {})\n",
" l_options = options.get(\"label\", {})\n",
" c_options = options.get(\"color\", {})\n",
" i_options = options.get(\"icon\", {})\n",
"\n",
" exclude_blueprints = (\"blueprints\" in e_options)\n",
"\n",
" root = ET.Element(\"Content\")\n",
"\n",
" stamp_path = ET.Element(\"StampPath\")\n",
" stamp_path.text = str(self.session.get_region_guid())\n",
" root.append(stamp_path)\n",
"\n",
" counts = dict()\n",
"\n",
" buildings = ET.Element(\"BuildingInfo\")\n",
" tl = self.rectangle[1]\n",
" #print(tl)\n",
" for b in self.buildings.values():\n",
" if b.is_blueprint and exclude_blueprints:\n",
" continue\n",
"\n",
" btree = ET.Element(\"None\")\n",
"\n",
" if b.guid in counts:\n",
" counts[b.guid] += 1\n",
" else:\n",
" counts[b.guid] = 1\n",
"\n",
" def add(name: str, value):\n",
" node = ET.Element(name)\n",
" node.text = str(value)\n",
" btree.append(node) \n",
" \n",
" pos = b.position[::2] - tl - np.array([0.5,0.5])\n",
" #print(b.position[::2], pos)\n",
" add(\"Pos\", \"{} {}\".format(pos[0], pos[1]))\n",
" add(\"Dir\", b.direction)\n",
" add(\"GUID\", b.guid)\n",
" if b.variation is not None:\n",
" add(\"Variation\", b.variation)\n",
"\n",
" if hasattr(b, \"modules\"):\n",
" add(\"ComplexOwnerID\", self.identifier)\n",
"\n",
" if hasattr(b, \"main_building\"):\n",
" add(\"ComplexOwnerID\", getattr(b, \"main_building\").identifier)\n",
"\n",
" buildings.append(btree)\n",
"\n",
" icon_guid = ET.Element(\"IconGUID\")\n",
" icon_guid.text = str(max(counts, key=counts.get))\n",
"\n",
" root.append(icon_guid)\n",
" root.append(buildings)\n",
"\n",
" # process streets\n",
" exclude_quay = (\"quay\" in e_options)\n",
"\n",
" rect = self.rectangle\n",
" streets = self.session.get_streets()[rect[0][1]:rect[1][1], rect[0][0]:rect[1][0]]\n",
" street_dict = dict()\n",
" count = 0\n",
" for x in range(len(streets)):\n",
" for y in range(len(streets[0])):\n",
" street = A7PARAMS[\"streets\"].get(streets[-y, -x])\n",
" if street is None:\n",
" continue\n",
"\n",
" if exclude_quay and is_quay(street[\"id\"]):\n",
" continue\n",
"\n",
" guid = street.get(\"guid\")\n",
" if guid not in street_dict:\n",
" street_dict[guid] = ET.Element(\"None\")\n",
"\n",
" street_node = ET.Element(\"None\")\n",
" street_node.text = \"{} {}\".format(-x,-y)\n",
" street_dict[guid].append(street_node)\n",
" count += 1\n",
"\n",
" street_info = ET.Element(\"StreetInfo\")\n",
" for guid, value in street_dict.items():\n",
" guid_node = ET.Element(\"None\")\n",
" guid_node.text = str(guid)\n",
" street_info.append(guid_node)\n",
" street_info.append(value)\n",
" root.append(street_info)\n",
"\n",
" street_count = ET.Element(\"StreetCount\")\n",
" street_count.text = str(count)\n",
" root.append(street_count)\n",
"\n",
" return root"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [],
"source": [
"xml = get_stamp()"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [],
"source": [
"import lxml\n",
"path = ui.get_island().name + \".xml\"\n",
"with open(path, \"wb\") as f:\n",
" f.write(lxml.etree.tostring(xml, pretty_print=True))"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import subprocess\n",
"subprocess.call([\"tools/FileDBReader/FileDBReader.exe\", \"compress\", \"-i\", \"tools/FileDBReader/FileFormats/stamp.xml\", \"-y\", \"-c\", \"3\", \"-f\", str(path)])"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"path = \"Roads 01.xml\"\n",
"subprocess.call([\"tools/FileDBReader/FileDBReader.exe\", \"compress\", \"-i\", \"tools/FileDBReader/FileFormats/stamp.xml\", \"-y\", \"-c\", \"3\", \"-f\", str(path)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Row highlighting in dark mode\n",
"# Make trade rout table sortable (or sort by name)"
]
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion tools/savegame_visualizer_gui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "v4.2"
VERSION = "v5.0"

import json
import lxml.etree as ET
Expand Down

0 comments on commit 5ccf26a

Please sign in to comment.