mirror of
https://github.com/csd4ni3l/logical-signals.git
synced 2025-11-05 05:58:09 +01:00
Add completed levels and highlight them
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -180,3 +180,4 @@ test*.py
|
||||
logs/
|
||||
logs
|
||||
settings.json
|
||||
data.json
|
||||
21
game/play.py
21
game/play.py
@@ -1,4 +1,4 @@
|
||||
import arcade, arcade.gui, random, datetime
|
||||
import arcade, arcade.gui, random, datetime, os, json
|
||||
|
||||
from utils.utils import cubic_bezier_points, get_gate_port_position, generate_task_text
|
||||
from utils.constants import button_style, dropdown_style, LOGICAL_GATES, LEVELS
|
||||
@@ -68,7 +68,7 @@ class Game(arcade.gui.UIView):
|
||||
self.tools_box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=5), anchor_x="right", anchor_y="bottom", align_x=-5, align_y=20)
|
||||
|
||||
if not level_num == -1:
|
||||
self.task_label = self.anchor.add(arcade.gui.UILabel(text=generate_task_text(LEVELS[level_num]), font_size=20, multiline=True), anchor_x="center", anchor_y="top")
|
||||
self.task_label = self.anchor.add(arcade.gui.UILabel(text=generate_task_text(LEVELS[level_num]), font_size=20, multiline=True), anchor_x="center", anchor_y="top", align_y=-15)
|
||||
for requirement in LEVELS[level_num]:
|
||||
if requirement[1] == "INPUT":
|
||||
for _ in range(requirement[0]):
|
||||
@@ -80,7 +80,7 @@ class Game(arcade.gui.UIView):
|
||||
for _ in range(requirement[0]):
|
||||
self.add_gate(random.randint(300, self.window.width - 600), random.randint(200, self.window.height - 100), requirement[1])
|
||||
else:
|
||||
self.task_label = self.anchor.add(arcade.gui.UILabel(text="Task: Have fun! Do whatever you want!", font_size=20), anchor_x="center", anchor_y="top")
|
||||
self.task_label = self.anchor.add(arcade.gui.UILabel(text="Task: Have fun! Do whatever you want!", font_size=20), anchor_x="center", anchor_y="top", align_y=-15)
|
||||
|
||||
for gate in list(LOGICAL_GATES.keys()) + ["INPUT 0", "INPUT 1", "OUTPUT"]:
|
||||
button = self.tools_box.add(arcade.gui.UIFlatButton(width=self.window.width * 0.1, height=self.window.height * 0.075, text=f"Create {gate} gate", style=dropdown_style))
|
||||
@@ -104,6 +104,15 @@ class Game(arcade.gui.UIView):
|
||||
self.back_button.on_click = lambda event: self.main_exit()
|
||||
self.anchor.add(self.back_button, anchor_x="left", anchor_y="top", align_x=5, align_y=-5)
|
||||
|
||||
if os.path.exists("data.json"):
|
||||
with open("data.json", "r") as file:
|
||||
self.data = json.load(file)
|
||||
else:
|
||||
self.data = {}
|
||||
|
||||
if not "completed_levels" in self.data:
|
||||
self.data["completed_levels"] = []
|
||||
|
||||
def screenshot(self):
|
||||
self.tools_box.visible = False
|
||||
self.tools_box._requires_render = True
|
||||
@@ -169,6 +178,12 @@ class Game(arcade.gui.UIView):
|
||||
return
|
||||
else:
|
||||
process_nodes.remove(requirement[1])
|
||||
|
||||
self.data["completed_levels"].append(self.level_num)
|
||||
self.task_label.text = f"You Successfully Completed Level {self.level_num + 1}!"
|
||||
|
||||
with open("data.json", "w") as file:
|
||||
file.write(json.dumps(self.data, indent=4))
|
||||
|
||||
def select_output(self, gate_id):
|
||||
if self.gates[gate_id].output:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import arcade, arcade.gui
|
||||
import arcade, arcade.gui, os, json
|
||||
|
||||
from math import ceil
|
||||
|
||||
@@ -15,6 +15,15 @@ class LevelSelector(arcade.gui.UIView):
|
||||
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
|
||||
self.grid = self.anchor.add(arcade.gui.UIGridLayout(width=self.window.width / 2, height=self.window.height / 2, vertical_spacing=10, horizontal_spacing=10, column_count=5, row_count=ceil((len(LEVELS) + 1) / 5)), anchor_x="center", anchor_y="top", align_y=-self.window.height / 8)
|
||||
|
||||
if os.path.exists("data.json"):
|
||||
with open("data.json", "r") as file:
|
||||
self.data = json.load(file)
|
||||
else:
|
||||
self.data = {}
|
||||
|
||||
if not "completed_levels" in self.data:
|
||||
self.data["completed_levels"] = []
|
||||
|
||||
def on_show_view(self):
|
||||
super().on_show_view()
|
||||
|
||||
@@ -36,7 +45,9 @@ class LevelSelector(arcade.gui.UIView):
|
||||
else:
|
||||
difficulty = "Extra Hard"
|
||||
|
||||
level_button = self.grid.add(arcade.gui.UITextureButton(width=self.window.width / 8, height=self.window.height / 8, text=f"{difficulty} Level {n + 1}", texture=button_texture, texture_hovered=button_hovered_texture, style=button_style), row=row, column=col)
|
||||
completed_notice = '\n(Completed)' if n in self.data['completed_levels'] else ''
|
||||
|
||||
level_button = self.grid.add(arcade.gui.UITextureButton(width=self.window.width / 8, height=self.window.height / 8, text=f"{difficulty} Level {n + 1}{completed_notice}", texture=button_texture, texture_hovered=button_hovered_texture, style=button_style, multiline=True), row=row, column=col)
|
||||
level_button.on_click = lambda event, n=n: self.play(n)
|
||||
|
||||
row, col = (n + 1) // 5, (n + 1) % 5
|
||||
|
||||
Reference in New Issue
Block a user