This commit is contained in:
Auric Vente 2024-07-22 08:09:49 -06:00
parent 9ceff213fb
commit 6fb7d02bd5
5 changed files with 84 additions and 12 deletions

View File

@ -54,7 +54,7 @@ class Config:
filter_width: int = 150 filter_width: int = 150
filter_debouncer_delay: int = 200 filter_debouncer_delay: int = 200
default_population: int = 100 default_population: int = 100
merge_goal: int = 8 merge_goal: int = 10
manifest_path: Path manifest_path: Path
manifest: dict[str, str] manifest: dict[str, str]

View File

@ -30,6 +30,7 @@ class Method:
sentence_1 = 6 sentence_1 = 6
sentence_2 = 7 sentence_2 = 7
sentence_3 = 8 sentence_3 = 8
sentence_4 = 9
class Game: class Game:
@ -196,19 +197,51 @@ class Game:
if not ant: if not ant:
return return
min_num = 0 mode = Settings.mode
max_num = 12 opts: list[int]
if mode == "all":
opts = [
Method.triumph,
Method.hit,
Method.travel,
Method.thinking_1,
Method.thinking_2,
Method.sentence_1,
Method.sentence_2,
Method.sentence_3,
Method.sentence_4,
Method.sentence_4 + 1,
Method.sentence_4 + 2,
Method.sentence_4 + 3,
]
elif mode == "score":
opts = [Method.triumph, Method.hit]
elif mode == "travel":
opts = [Method.travel]
elif mode == "thought":
opts = [Method.thinking_1, Method.thinking_2]
elif mode == "words":
opts = [
Method.sentence_1,
Method.sentence_2,
Method.sentence_3,
Method.sentence_4,
]
num = random.randint(min_num, max_num)
Game.merge_charge += 1 Game.merge_charge += 1
if num == Method.merge:
if Game.merge_charge >= Config.merge_goal: if Game.merge_charge >= Config.merge_goal:
opts.insert(0, Method.merge)
num = random.choice(opts)
if num == Method.merge:
if Ants.merge(): if Ants.merge():
Game.merge_charge = 0 Game.merge_charge = 0
return return
num = min_num num = Method.sentence_4
status = "" status = ""
method = "normal" method = "normal"
@ -242,9 +275,12 @@ class Game:
elif num == Method.sentence_3: elif num == Method.sentence_3:
status = Utils.rand_sentence.bare_bone_with_adjective() status = Utils.rand_sentence.bare_bone_with_adjective()
else: elif num >= Method.sentence_4:
status = Utils.rand_sentence.sentence() status = Utils.rand_sentence.sentence()
else:
status = "???"
Ants.set_status(ant, status, method) Ants.set_status(ant, status, method)
@staticmethod @staticmethod
@ -287,6 +323,16 @@ class Game:
Settings.set_speed(speed) Settings.set_speed(speed)
Game.start_loop() Game.start_loop()
@staticmethod
def update_mode() -> None:
mode = Window.mode.currentText().lower()
if mode == Settings.mode:
return
Settings.set_mode(mode)
Game.start_loop()
@staticmethod @staticmethod
def info() -> None: def info() -> None:
text = [] text = []

View File

@ -1,5 +1,5 @@
{ {
"version": "1.1.0", "version": "1.2.0",
"title": "Cromulant", "title": "Cromulant",
"program": "cromulant", "program": "cromulant",
"author": "madprops", "author": "madprops",

View File

@ -6,18 +6,25 @@ from .storage import Storage
class Settings: class Settings:
speed: str speed: str
mode: str
@staticmethod @staticmethod
def prepare() -> None: def prepare() -> None:
settings = Storage.get_settings() settings = Storage.get_settings()
Settings.speed = settings.get("speed", "normal") Settings.speed = settings.get("speed", "normal")
speed = Settings.speed.capitalize() speed = Settings.speed.capitalize()
Window.speed.setCurrentText(speed) Window.speed.setCurrentText(speed)
Settings.mode = settings.get("mode", "all")
mode = Settings.mode.capitalize()
Window.mode.setCurrentText(mode)
@staticmethod @staticmethod
def save() -> None: def save() -> None:
settings = { settings = {
"speed": Settings.speed, "speed": Settings.speed,
"mode": Settings.mode,
} }
Storage.save_settings(settings) Storage.save_settings(settings)
@ -26,3 +33,8 @@ class Settings:
def set_speed(speed: str) -> None: def set_speed(speed: str) -> None:
Settings.speed = speed Settings.speed = speed
Settings.save() Settings.save()
@staticmethod
def set_mode(mode: str) -> None:
Settings.mode = mode
Settings.save()

View File

@ -87,6 +87,7 @@ class Window:
player: QMediaPlayer player: QMediaPlayer
audio: QAudioOutput audio: QAudioOutput
filter: QLineEdit filter: QLineEdit
mode: QComboBox
@staticmethod @staticmethod
def prepare() -> None: def prepare() -> None:
@ -236,6 +237,18 @@ class Window:
Window.speed.setCurrentIndex(1) Window.speed.setCurrentIndex(1)
Window.speed.currentIndexChanged.connect(Game.update_speed) Window.speed.currentIndexChanged.connect(Game.update_speed)
Window.mode = QComboBox()
tooltip = "Game mode\n"
tooltip += "All: All kind of updates\n"
tooltip += "Score: Only triumph and hit updates\n"
tooltip += "Travel: Only travel updates\n"
tooltip += "Thought: Only thought updates\n"
tooltip += "Words: Only sentences"
Window.mode.setToolTip(tooltip)
Window.mode.addItems(["All", "Score", "Travel", "Thought", "Words"])
Window.mode.setCurrentIndex(1)
Window.mode.currentIndexChanged.connect(Game.update_mode)
Window.filter = FilterLineEdit() Window.filter = FilterLineEdit()
Window.filter.setFixedWidth(Config.filter_width) Window.filter.setFixedWidth(Config.filter_width)
Window.filter.setPlaceholderText("Filter") Window.filter.setPlaceholderText("Filter")
@ -244,6 +257,7 @@ class Window:
container.addWidget(btn_restart) container.addWidget(btn_restart)
container.addWidget(Window.speed) container.addWidget(Window.speed)
container.addWidget(Window.mode)
container.addWidget(Window.filter) container.addWidget(Window.filter)
root.setLayout(container) root.setLayout(container)