Compare commits
15 Commits
bfb3f74342
...
webbeta
| Author | SHA1 | Date | |
|---|---|---|---|
| 448fc8aebe | |||
| 7dab0ed143 | |||
| a13748b833 | |||
| 11e531fef2 | |||
| d198e8906f | |||
| d677ff8ae9 | |||
| cbc961b7c4 | |||
| 9a1c18f815 | |||
| bb2388c914 | |||
| f76d0ce63a | |||
| 3beb9b67f7 | |||
| 2bf7898720 | |||
| 64dd7cc3ae | |||
| 49e090b3c9 | |||
| efc9145f80 |
@@ -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):
|
||||||
|
|||||||
118
main.py
118
main.py
@@ -1,3 +1,5 @@
|
|||||||
|
from datetime import time
|
||||||
|
import datetime
|
||||||
import discord
|
import discord
|
||||||
import os
|
import os
|
||||||
from discord.ext import tasks
|
from discord.ext import tasks
|
||||||
@@ -42,59 +44,67 @@ async def on_ready():
|
|||||||
|
|
||||||
@tasks.loop(seconds=5)
|
@tasks.loop(seconds=5)
|
||||||
async def task_loop():
|
async def task_loop():
|
||||||
await bot.change_presence(
|
try:
|
||||||
activity=discord.Activity(
|
# print(str(datetime.datetime.now()) + ": Loop running.")
|
||||||
type=discord.ActivityType.watching,
|
await bot.change_presence(
|
||||||
name=str(len(bot.tracked_games)) + " Servers.",
|
activity=discord.Activity(
|
||||||
)
|
type=discord.ActivityType.watching,
|
||||||
)
|
name=str(len(bot.tracked_games)) + " Servers.",
|
||||||
for game in bot.tracked_games:
|
|
||||||
channel = bot.get_channel(game.channelId)
|
|
||||||
if channel is None:
|
|
||||||
continue
|
|
||||||
# handle turn ticks
|
|
||||||
new_turn = game.get_turn()
|
|
||||||
if new_turn != game.turn and new_turn.isdigit():
|
|
||||||
game.update_turn()
|
|
||||||
pingstr = ""
|
|
||||||
if game.members:
|
|
||||||
pingstr += "-# "
|
|
||||||
for member in game.members:
|
|
||||||
pingstr += "<@" + str(member) + "> "
|
|
||||||
await channel.send(
|
|
||||||
'Game **"'
|
|
||||||
+ game.name
|
|
||||||
+ '"** has advanced to turn '
|
|
||||||
+ game.turn
|
|
||||||
+ " \n"
|
|
||||||
+ pingstr
|
|
||||||
)
|
)
|
||||||
game.to_json()
|
)
|
||||||
|
for game in bot.tracked_games:
|
||||||
# handle uploaded turns
|
channel = bot.get_channel(game.channelId)
|
||||||
turns = game.get_new_turns()
|
if channel is None:
|
||||||
if turns != {}:
|
continue
|
||||||
for key in turns:
|
# handle turn ticks
|
||||||
value = turns[key]
|
new_turn = game.get_turn()
|
||||||
if value == "Turn played":
|
if new_turn != game.turn and new_turn.isdigit():
|
||||||
await channel.send(
|
game.update_turn()
|
||||||
'Game **"'
|
pingstr = ""
|
||||||
+ game.name
|
if game.members:
|
||||||
+ '"**: '
|
pingstr += "-# "
|
||||||
+ key
|
for member in game.members:
|
||||||
+ " has played their turn."
|
pingstr += "<@" + str(member) + "> "
|
||||||
)
|
await channel.send(
|
||||||
if value == "Eliminated":
|
'Game **"'
|
||||||
await channel.send(
|
+ game.name
|
||||||
'Game **"' + game.name + '"**: ' + key + " has been eliminated."
|
+ '"** has advanced to turn '
|
||||||
)
|
+ game.turn
|
||||||
if value == "Turn unfinished":
|
+ " \n"
|
||||||
await channel.send(
|
+ pingstr
|
||||||
'Game **"'
|
)
|
||||||
+ game.name
|
|
||||||
+ '"**: '
|
|
||||||
+ key
|
|
||||||
+ " has marked their turn as unfinished."
|
|
||||||
)
|
|
||||||
game.update_players()
|
|
||||||
game.to_json()
|
game.to_json()
|
||||||
|
|
||||||
|
# handle uploaded turns
|
||||||
|
turns = game.get_new_turns()
|
||||||
|
if turns != {}:
|
||||||
|
for key in turns:
|
||||||
|
value = turns[key]
|
||||||
|
if value == "Turn played":
|
||||||
|
await channel.send(
|
||||||
|
'Game **"'
|
||||||
|
+ game.name
|
||||||
|
+ '"**: '
|
||||||
|
+ key
|
||||||
|
+ " has played their turn."
|
||||||
|
)
|
||||||
|
if value == "Eliminated":
|
||||||
|
await channel.send(
|
||||||
|
'Game **"'
|
||||||
|
+ game.name
|
||||||
|
+ '"**: '
|
||||||
|
+ key
|
||||||
|
+ " has been eliminated."
|
||||||
|
)
|
||||||
|
if value == "Turn unfinished":
|
||||||
|
await channel.send(
|
||||||
|
'Game **"'
|
||||||
|
+ game.name
|
||||||
|
+ '"**: '
|
||||||
|
+ key
|
||||||
|
+ " has marked their turn as unfinished."
|
||||||
|
)
|
||||||
|
game.update_players()
|
||||||
|
game.to_json()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
|
|||||||
132
webui.py
132
webui.py
@@ -1,6 +1,6 @@
|
|||||||
from nicegui import ui
|
from nicegui import ui
|
||||||
from pandas.core.internals.blocks import external_values
|
|
||||||
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
|
||||||
@@ -16,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):
|
||||||
@@ -44,7 +44,10 @@ 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)
|
||||||
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
# Port
|
# Port
|
||||||
@@ -74,9 +77,9 @@ def creator_page():
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# client_start = ui.checkbox("Allow clients to start the game")
|
|
||||||
checkbox_container = ui.row()
|
checkbox_container = ui.row()
|
||||||
with checkbox_container:
|
with checkbox_container:
|
||||||
|
client_start = ui.checkbox("Allow clients to start the game", value=True)
|
||||||
team_game = ui.checkbox("Disciple Game")
|
team_game = ui.checkbox("Disciple Game")
|
||||||
clustered_start = ui.checkbox("Clustered Spawns (Disciple games only)")
|
clustered_start = ui.checkbox("Clustered Spawns (Disciple games only)")
|
||||||
random_start_research = ui.checkbox("Random Start Research")
|
random_start_research = ui.checkbox("Random Start Research")
|
||||||
@@ -88,15 +91,67 @@ def creator_page():
|
|||||||
no_new_ai = ui.checkbox("Disable Becoming AI Controlled")
|
no_new_ai = ui.checkbox("Disable Becoming AI Controlled")
|
||||||
vwrap = ui.checkbox("North South Wrapping")
|
vwrap = ui.checkbox("North South Wrapping")
|
||||||
hwrap = ui.checkbox("East West Wrapping")
|
hwrap = ui.checkbox("East West Wrapping")
|
||||||
description_container = ui.row()
|
with ui.row():
|
||||||
toggle_container = ui.row()
|
ui.label("Event Rarity").classes("w-40")
|
||||||
with toggle_container:
|
ui.label("Provinces per player").classes("w-36")
|
||||||
|
ui.label("Story Events")
|
||||||
|
|
||||||
|
with ui.row():
|
||||||
event_rarity = ui.toggle({1: "Common", 2: "Rare"}, value=1)
|
event_rarity = ui.toggle({1: "Common", 2: "Rare"}, value=1)
|
||||||
random_map = ui.toggle([10, 15, 20], value=15)
|
random_map = ui.toggle([10, 15, 20], value=15)
|
||||||
with description_container:
|
story_events = ui.toggle({0: "None", 1: "Some", 2: "All"}, value=2)
|
||||||
ui.label("Event Rarity")
|
|
||||||
# TODO: Fix Padding
|
ui.label("Victory Condition")
|
||||||
ui.label("Provinces per player:")
|
# I have to do this to pass by reference?? This is absurd.
|
||||||
|
conq_all = [True]
|
||||||
|
thrones = [(0, 0, 0)]
|
||||||
|
required_apoints = [0]
|
||||||
|
with ui.row():
|
||||||
|
ui.radio({1: "Conquest", 2: "Thrones Of Ascension"}).props(
|
||||||
|
"inline"
|
||||||
|
).on_value_change(
|
||||||
|
lambda e: handle_thrones(
|
||||||
|
e, throne_container, conq_all, thrones, required_apoints
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
throne_container = ui.row()
|
||||||
|
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
|
# TODO: REMOVE THIS it is just for testing
|
||||||
ui.button(
|
ui.button(
|
||||||
@@ -107,12 +162,46 @@ def creator_page():
|
|||||||
port=int(port.value),
|
port=int(port.value),
|
||||||
era=int(era.value),
|
era=int(era.value),
|
||||||
ai_slots=ai_slots,
|
ai_slots=ai_slots,
|
||||||
random_map=15,
|
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),
|
||||||
|
story_events=int(story_events.value),
|
||||||
|
conq_all=conq_all,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def handle_thrones(value, throne_container, conq_all, thrones, required_apoints):
|
||||||
|
if value == 1:
|
||||||
|
throne_container.clear()
|
||||||
|
conq_all[0] = False
|
||||||
|
return
|
||||||
|
with throne_container:
|
||||||
|
with ui.row():
|
||||||
|
thrones = (
|
||||||
|
ui.input(label="Level 1"),
|
||||||
|
ui.input(label="Level 2"),
|
||||||
|
ui.input(label="Level 3"),
|
||||||
|
)
|
||||||
|
required_apoints = ui.input(label="Required Ascension Points")
|
||||||
|
return False, thrones, required_apoints
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
AI_LEVELS = [
|
AI_LEVELS = [
|
||||||
@@ -131,26 +220,31 @@ 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: Set all button
|
|
||||||
# TODO: Random nations?
|
# 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, nid=nation_id: set_ai_level(
|
on_change=lambda e, nid=nation_id: set_ai_level(
|
||||||
e.value, nid, ai_slots
|
e.value, nid, ai_slots
|
||||||
),
|
),
|
||||||
)
|
).bind_value_from(master_select)
|
||||||
|
|
||||||
|
|
||||||
def set_ai_level(value, nid, ai_slots):
|
def set_ai_level(value, nid, ai_slots):
|
||||||
|
|||||||
Reference in New Issue
Block a user