Compare commits

..

4 Commits

Author SHA1 Message Date
65cd0906a4 Added era and ai level selector. 2026-06-01 15:10:12 +02:00
31e4ec08c4 Merged ai_slots and closed_slots into one. 2026-06-01 15:07:41 +02:00
6e52242483 Added Era selection. 2026-06-01 13:51:21 +02:00
29df7b2a53 fixed port input validation 2026-06-01 13:48:36 +02:00
2 changed files with 83 additions and 11 deletions

View File

@@ -54,10 +54,9 @@ def server_command_builder(
name: str,
port: int,
era: int, # 1 EA, 2 MA, 3 LA
closed_slots: list[int] = [], # list of nations that will be closed
ai_slots: list[
tuple[int, int]
] = [], # list of nations that will be ai tuple format: NationID, AI Level (1-6)
] = [], # list of nations that will be ai tuple format: NationID, AI Level (1-6), 0 being closed
client_start: bool = True,
teams: list[tuple[int, int, int]] = [],
clustered_start: bool = False,
@@ -105,8 +104,8 @@ def server_command_builder(
if not (len(ai_indexes) == len(set(ai_indexes))):
return "ERROR_AIS"
if bool(set(closed_slots) & set(ai_indexes)):
return "ERROR_CLOSED_AIS"
# if bool(set(closed_slots) & set(ai_indexes)):
# return "ERROR_CLOSED_AIS"
if required_apoints == 0:
required_apoints = thrones[0] + (2 * thrones[1]) + (3 * thrones[2]) - 1
@@ -150,7 +149,7 @@ def server_command_builder(
]
if team_game:
for team in teams:
# TODO Can team have more than one disciple and pretender?
# TODO: Can team have more than one disciple and pretender?
if team[0] not in available_nations[str(era)]:
return "ERROR_INVALID_NATION"
@@ -229,6 +228,8 @@ def server_command_builder(
if ai[0] in added_ais:
return "ERROR_DUPLICATE_AI"
match ai[1]:
case 0:
command.append(" --closed " + str(ai[0]))
case 1:
command.append(" --easyai " + str(ai[0]))
case 2:

View File

@@ -48,14 +48,85 @@ def creator_page():
).value
# Port
load_dotenv()
port_min = os.getenv("PORT_MIN")
port_max = os.getenv("PORT_MAX")
port_min = int(os.getenv("PORT_MIN", 1024))
port_max = int(os.getenv("PORT_MAX", 65535))
port = ui.input(
label="Port",
validation={
f"Port must be between {str(port_min)} and {str(port_max)}": lambda value: port_min
<= value
<= port_max
f"Port must be between {str(port_min)} and {str(port_max)}": lambda value: value.isdigit()
and port_min <= int(value) <= port_max,
"Port in use": lambda value: value.isdigit()
and not servermanager.is_port_in_use(int(value)),
},
)
# Era
# Era + AI
# 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]))