Added era and ai level selector.
This commit is contained in:
73
webui.py
73
webui.py
@@ -59,5 +59,74 @@ def creator_page():
|
|||||||
and not servermanager.is_port_in_use(int(value)),
|
and not servermanager.is_port_in_use(int(value)),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
# Era
|
# Era + AI
|
||||||
era = ui.radio({1: "Early Age", 2: "Middle Age", 3: "Late Age"}).props("inline")
|
# This sucks but idk how else to move the radio selector above the table
|
||||||
|
ai_slots = []
|
||||||
|
era_container = ui.row()
|
||||||
|
table_container = ui.column()
|
||||||
|
with era_container:
|
||||||
|
era = ( # might not need the variable anymore
|
||||||
|
ui.radio({1: "Early Age", 2: "Middle Age", 3: "Late Age"})
|
||||||
|
.props("inline")
|
||||||
|
.on_value_change(
|
||||||
|
lambda e: create_ai_table(e.value, table_container, ai_slots)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def create_ai_table(era, table_container, ai_slots):
|
||||||
|
# TODO: move this somewhere else
|
||||||
|
AI_LEVELS = [
|
||||||
|
"Human",
|
||||||
|
"Easy",
|
||||||
|
"Normal",
|
||||||
|
"Difficult",
|
||||||
|
"Mighty",
|
||||||
|
"Master",
|
||||||
|
"Impossible",
|
||||||
|
"Closed",
|
||||||
|
]
|
||||||
|
table_container.clear()
|
||||||
|
nations = servermanager.get_nations()
|
||||||
|
with table_container:
|
||||||
|
with ui.card().classes("w-full"):
|
||||||
|
with ui.row().classes("font-bold w-full"):
|
||||||
|
ui.label("ID").classes("w-16")
|
||||||
|
ui.label("Nation").classes("w-40")
|
||||||
|
ui.label("Title").classes("w-64")
|
||||||
|
ui.label("AI Level")
|
||||||
|
ui.separator()
|
||||||
|
for nation_id, nation in nations[str(era)].items():
|
||||||
|
nation_name, title = nation["name"]
|
||||||
|
|
||||||
|
with ui.row().classes("items-center w-full"):
|
||||||
|
ui.label(str(nation_id)).classes("w-16")
|
||||||
|
ui.label(nation_name).classes("w-40")
|
||||||
|
ui.label(title).classes("w-64")
|
||||||
|
|
||||||
|
ui.select(
|
||||||
|
AI_LEVELS,
|
||||||
|
value="Human",
|
||||||
|
on_change=lambda e: set_ai_level(e.value, nation_id, ai_slots),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def set_ai_level(value, nation_id, ai_slots):
|
||||||
|
level_map = {
|
||||||
|
"Closed": 0,
|
||||||
|
"Easy": 1,
|
||||||
|
"Normal": 2,
|
||||||
|
"Difficult": 3,
|
||||||
|
"Mighty": 4,
|
||||||
|
"Master": 5,
|
||||||
|
"Impossible": 6,
|
||||||
|
}
|
||||||
|
ai_slots[:] = [
|
||||||
|
(nation_id, ai_level)
|
||||||
|
for nation_id, ai_level in ai_slots
|
||||||
|
if nation_id != nation_id
|
||||||
|
]
|
||||||
|
if value == "Human":
|
||||||
|
return
|
||||||
|
|
||||||
|
ai_slots.append((nation_id, level_map[value]))
|
||||||
|
|||||||
Reference in New Issue
Block a user