Compare commits

...

15 Commits

Author SHA1 Message Date
9a1c18f815 Added name symbol validation. 2026-06-05 12:06:28 +02:00
bb2388c914 Added multiplier options. 2026-06-05 12:01:55 +02:00
f76d0ce63a Dark mode, maybe? 2026-06-05 11:19:21 +02:00
3beb9b67f7 Fixed master select binding both ways. 2026-06-05 11:15:53 +02:00
2bf7898720 Added comment. 2026-06-05 11:09:26 +02:00
64dd7cc3ae Changed table layout and added set all button for ai. 2026-06-05 11:08:41 +02:00
49e090b3c9 Fixed typo in command name. 2026-06-03 11:00:42 +02:00
efc9145f80 Fixed AI validation. 2026-06-02 17:33:31 +02:00
bfb3f74342 No comment. We do not speak of this. 2026-06-02 17:29:39 +02:00
d6a56f5084 I must have been high while writing that. 2026-06-02 17:23:29 +02:00
fac0b12c21 Added TODO comments. 2026-06-02 17:16:19 +02:00
fe53cba904 Fixed nation id being captured too late. 2026-06-02 17:14:04 +02:00
e8b6edb0d8 Added checkbox and toggle options. 2026-06-01 16:13:06 +02:00
965fea2227 Added string generation for testing. 2026-06-01 15:22:38 +02:00
9f0059e833 Added missing space between -TS and game name. 2026-06-01 15:22:16 +02:00
3 changed files with 124 additions and 23 deletions

View File

@@ -50,7 +50,7 @@ class SlashCommands(commands.Cog):
print("a") print("a")
@app_commands.command( @app_commands.command(
name="domt5-pingme", name="dom5-pingme",
description="Signs you up to be pinged for a game. Run the command again to not get pinged anymore.", description="Signs you up to be pinged for a game. Run the command again to not get pinged anymore.",
) )
async def pingme(self, interaction: discord.Interaction, name: str): async def pingme(self, interaction: discord.Interaction, name: str):

View File

@@ -58,7 +58,7 @@ def server_command_builder(
tuple[int, int] tuple[int, int]
] = [], # list of nations that will be ai tuple format: NationID, AI Level (1-6), 0 being closed ] = [], # list of nations that will be ai tuple format: NationID, AI Level (1-6), 0 being closed
client_start: bool = True, client_start: bool = True,
teams: list[tuple[int, int, int]] = [], teams: list[tuple[int, int, int]] = [], # list of teams with format nation id,
clustered_start: bool = False, clustered_start: bool = False,
team_game: bool = False, team_game: bool = False,
mapfile: str = "", mapfile: str = "",
@@ -100,7 +100,7 @@ def server_command_builder(
if not (0 < era < 4): if not (0 < era < 4):
return "ERROR_ERA" return "ERROR_ERA"
ai_indexes = [t[1] for t in ai_slots] ai_indexes = [t[0] for t in ai_slots]
if not (len(ai_indexes) == len(set(ai_indexes))): if not (len(ai_indexes) == len(set(ai_indexes))):
return "ERROR_AIS" return "ERROR_AIS"

139
webui.py
View File

@@ -1,5 +1,6 @@
from nicegui import ui from nicegui import ui
from bot_instance import bot from bot_instance import bot
import re
from dom5game import Dom5game from dom5game import Dom5game
import servermanager import servermanager
import os import os
@@ -15,8 +16,8 @@ def create_ui():
pages.add("/", lambda: main_page(rows)) pages.add("/", lambda: main_page(rows))
pages.add("/create", lambda: creator_page()) pages.add("/create", lambda: creator_page())
# ui.dark_mode().enable()
ui.run(reload=False) ui.run(reload=False, show=False)
def main_page(rows): def main_page(rows):
@@ -43,9 +44,12 @@ def creator_page():
validation={ validation={
"Game with that name already exists": lambda value: not ( "Game with that name already exists": lambda value: not (
os.path.isdir("games/" + value) os.path.isdir("games/" + value)
) ),
"Name contains an invalid symbol": lambda value: bool(
re.match("^[A-Za-z0-9_-]*$", value)
),
}, },
).value )
# Port # Port
load_dotenv() load_dotenv()
port_min = int(os.getenv("PORT_MIN", 1024)) port_min = int(os.getenv("PORT_MIN", 1024))
@@ -65,7 +69,7 @@ def creator_page():
era_container = ui.row() era_container = ui.row()
table_container = ui.column() table_container = ui.column()
with era_container: with era_container:
era = ( # might not need the variable anymore era = (
ui.radio({1: "Early Age", 2: "Middle Age", 3: "Late Age"}) ui.radio({1: "Early Age", 2: "Middle Age", 3: "Late Age"})
.props("inline") .props("inline")
.on_value_change( .on_value_change(
@@ -73,6 +77,97 @@ def creator_page():
) )
) )
# client_start = ui.checkbox("Allow clients to start the game")
checkbox_container = ui.row()
with checkbox_container:
team_game = ui.checkbox("Disciple Game")
clustered_start = ui.checkbox("Clustered Spawns (Disciple games only)")
random_start_research = ui.checkbox("Random Start Research")
score_graphs = ui.checkbox("Score Graphs")
renaming = ui.checkbox("Allow Renaming", value=True)
no_nation_info = ui.checkbox("No Info About Other Nations")
no_cheat_det = ui.checkbox("Disable Anticheat")
no_artifact_rest = ui.checkbox("Disable Artifact Forge Limit")
no_new_ai = ui.checkbox("Disable Becoming AI Controlled")
vwrap = ui.checkbox("North South Wrapping")
hwrap = ui.checkbox("East West Wrapping")
description_container = ui.row()
toggle_container = ui.row()
# TODO: Are these containers still needed?
with toggle_container:
event_rarity = ui.toggle({1: "Common", 2: "Rare"}, value=1)
random_map = ui.toggle([10, 15, 20], value=15)
with description_container:
ui.label("Event Rarity")
# TODO: Fix Padding
ui.label("Provinces per player:")
with ui.row():
ui.label("Gold Multiplier:").classes("w-36")
richness = ui.input(
validation={
"Value must be between 50 and 300": lambda value: value.isdigit()
and 50 <= int(value) <= 300,
},
value="100",
)
with ui.row():
ui.label("Resource Multiplier:").classes("w-36")
resources = ui.input(
validation={
"Value must be between 50 and 300": lambda value: value.isdigit()
and 50 <= int(value) <= 300,
},
value="100",
)
with ui.row():
ui.label("Recruitment Multiplier:").classes("w-36")
recruitment = ui.input(
validation={
"Value must be between 50 and 300": lambda value: value.isdigit()
and 50 <= int(value) <= 300,
},
value="100",
)
with ui.row():
ui.label("Supplies Multiplier:").classes("w-36")
supplies = ui.input(
validation={
"Value must be between 50 and 300": lambda value: value.isdigit()
and 50 <= int(value) <= 300,
},
value="100",
)
# TODO: REMOVE THIS it is just for testing
ui.button(
"Generate String",
on_click=lambda: print(
servermanager.server_command_builder(
name=name.value,
port=int(port.value),
era=int(era.value),
ai_slots=ai_slots,
random_map=int(random_map.value),
event_rarity=int(event_rarity.value),
hwrap=hwrap.value,
vwrap=vwrap.value,
no_new_ai=no_new_ai.value,
no_artifact_rest=no_artifact_rest.value,
no_cheat_det=no_cheat_det.value,
renaming=renaming.value,
score_graphs=score_graphs.value,
random_start_research=random_start_research.value,
clustered_start=clustered_start.value,
team_game=team_game.value,
no_nation_info=no_nation_info.value,
recruitment=int(recruitment.value),
resources=int(resources.value),
richness=int(richness.value),
supplies=int(supplies.value),
)
),
)
def create_ai_table(era, table_container, ai_slots): def create_ai_table(era, table_container, ai_slots):
# TODO: move this somewhere else # TODO: move this somewhere else
@@ -92,26 +187,34 @@ def create_ai_table(era, table_container, ai_slots):
with ui.card().classes("w-full"): with ui.card().classes("w-full"):
with ui.row().classes("font-bold w-full"): with ui.row().classes("font-bold w-full"):
ui.label("ID").classes("w-16") ui.label("ID").classes("w-16")
ui.label("Nation").classes("w-40") ui.label("Nation").classes("w-104")
ui.label("Title").classes("w-64")
ui.label("AI Level") ui.label("AI Level")
ui.separator() ui.separator()
with ui.row().classes("items-center, w-full"):
ui.label("All").classes("w-124")
master_select = ui.select(
AI_LEVELS,
value="Human",
)
for nation_id, nation in nations[str(era)].items(): for nation_id, nation in nations[str(era)].items():
nation_name, title = nation["name"] nation_name, title = nation["name"]
with ui.row().classes("items-center w-full"): with ui.row().classes("items-center w-full"):
ui.label(str(nation_id)).classes("w-16") ui.label(str(nation_id)).classes("w-16")
ui.label(nation_name).classes("w-40") ui.label(nation_name + ", " + title).classes("w-104")
ui.label(title).classes("w-64") # TODO: Random nations?
# Although that logic should probably go into servermanager.py
ui.select( ui.select(
AI_LEVELS, AI_LEVELS,
value="Human", value="Human",
on_change=lambda e: set_ai_level(e.value, nation_id, ai_slots), on_change=lambda e, nid=nation_id: set_ai_level(
) e.value, nid, ai_slots
),
).bind_value_from(master_select)
def set_ai_level(value, nation_id, ai_slots): def set_ai_level(value, nid, ai_slots):
level_map = { level_map = {
"Closed": 0, "Closed": 0,
"Easy": 1, "Easy": 1,
@@ -121,12 +224,10 @@ def set_ai_level(value, nation_id, ai_slots):
"Master": 5, "Master": 5,
"Impossible": 6, "Impossible": 6,
} }
ai_slots[:] = [ for ai in ai_slots:
(nation_id, ai_level) if ai[0] == nid:
for nation_id, ai_level in ai_slots ai_slots.remove(ai)
if nation_id != nation_id
]
if value == "Human": if value == "Human":
return return
ai_slots.append((nation_id, level_map[value])) ai_slots.append((nid, level_map[value]))