Skip to content

Commit

Permalink
Added settings screenshot
Browse files Browse the repository at this point in the history
strip whitespaces from examples
import cleanup
  • Loading branch information
Fus3n committed Feb 26, 2024
1 parent e91de70 commit 17178d9
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/build
/venv
inf_config.json
game-data.json
/output
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Create your own infinite Crafting game
## Screenshots

<p>
<img src="./screenshots/screen-1.png" width="55%" />
<img src="./screenshots/screen-2.png" width="40%" />
<img src="./screenshots/screen-1.png" width="45%" />
<img src="./screenshots/screen-2.png" width="45%" />
</p>


Expand Down
Binary file modified screenshots/screen-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions src/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def convert_examples(self):
for example in self.examples:
self.final_examples.extend(
[
{"role": "user", "content": f'"{example["from_str"]}"'},
{"role": "assistant", "content": example["result_str"]},
{"role": "user", "content": f'"{example["from_str"].strip()}"'},
{"role": "assistant", "content": example["result_str"].strip()},
]
)

Expand All @@ -74,7 +74,6 @@ def generate_result(self, first: str, second: str) -> tuple[str | None, str | No
]
messages.extend(self.final_examples)
messages.append({"role": "user", "content": result})
print(messages)

try:
response = self.__client.chat.completions.create(
Expand Down
6 changes: 2 additions & 4 deletions src/game_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
from PySide6.QtWidgets import (
QGraphicsView,
QGraphicsScene,
QGraphicsTextItem,
QStyleOptionGraphicsItem,
QWidget
)

from PySide6.QtCore import Qt, Signal
Expand Down Expand Up @@ -90,4 +87,5 @@ def generate_finished(self, chip1: ChipGraphicsItem, chip2: ChipGraphicsItem, re
return

chip = Chip(result, self.add_chip, self.theme)
self.main_window.chips_list.addChip(chip)
self.main_window.chips_list.add_chip(chip)
self.main_window.save_chips()
70 changes: 56 additions & 14 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Literal
import sys, os
import sys, os, json

from PySide6.QtWidgets import (
QApplication,
Expand Down Expand Up @@ -28,7 +28,7 @@

class ChipList(QListWidget):

def addChip(self, chip: Chip):
def add_chip(self, chip: Chip):
item = QListWidgetItem()
item.setSizeHint(chip.sizeHint())
item.setFlags(Qt.NoItemFlags)
Expand All @@ -48,6 +48,9 @@ def __init__(self) -> None:
# set theme here
self.theme: Literal["dark"] | Literal["light"] = "dark"

# Game
self.game_file = "./game-data.json"

self.frame = QFrame()

self.lay = QHBoxLayout()
Expand Down Expand Up @@ -88,23 +91,52 @@ def __init__(self) -> None:
self.sidebar.addWidget(self.chips_list)
self.sidebar.addWidget(self.search_bar)

self.populate_default_chips()
self.load_game_data()

self.lay.addLayout(self.sidebar)
self.setCentralWidget(self.frame)

self.init_menu()

def load_game_data(self):
if os.path.exists(self.game_file):
self.load_chips()
return

self.populate_default_chips()
self.save_chips()

def load_chips(self):
with open(self.game_file, "r") as f:
data = json.load(f)
if not data:
self.populate_default_chips()
return

for chip in data:
chip = Chip(chip, self.game_view.add_chip, self.theme)
self.chips_list.add_chip(chip)

def save_chips(self):
chips = []
for idx in range(self.chips_list.count()):
item = self.chips_list.item(idx)
widget = self.chips_list.itemWidget(item)
chips.append(widget.text())

with open(self.game_file, "w") as f:
json.dump(chips, f)

def populate_default_chips(self):
earth_chip = Chip("🌍 Earth", self.game_view.add_chip, self.theme)
water_chip = Chip("💧 Water",self.game_view.add_chip, self.theme)
fire_chip = Chip("🔥 Fire", self.game_view.add_chip, self.theme)
air_chip = Chip("💨 Air", self.game_view.add_chip, self.theme)

self.chips_list.addChip(earth_chip)
self.chips_list.addChip(water_chip)
self.chips_list.addChip(fire_chip)
self.chips_list.addChip(air_chip)
self.chips_list.add_chip(earth_chip)
self.chips_list.add_chip(water_chip)
self.chips_list.add_chip(fire_chip)
self.chips_list.add_chip(air_chip)

def reset_list(self):
dialog = QMessageBox()
Expand Down Expand Up @@ -137,16 +169,12 @@ def init_menu(self):
app_menu = menu.addMenu("App")
theme_menu = menu.addMenu("Theme")

# File menu
# App menu
settings_window_action = app_menu.addAction("Settings")
settings_window_action.triggered.connect(self.open_settings)

# select_model_action = file_menu.addAction("Select Model")
# select_model_action.triggered.connect(lambda: print("sys"))

# set_base_url_action = file_menu.addAction("Set Base URL")
# set_base_url_action.triggered.connect(self.set_base_url)

reset_all_action = app_menu.addAction("Reset All")
reset_all_action.triggered.connect(self.reset_chips)

# Theme menu
dark_action = theme_menu.addAction("Dark")
Expand Down Expand Up @@ -211,6 +239,20 @@ def open_settings(self):
settings = Settings(self)
settings.exec()

def reset_chips(self):
msg = QMessageBox()
msg.setWindowTitle("Reset Confirmation")
msg.setText("Are you sure you want to reset everything? This will remove all the cips you created.")
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)

result = msg.exec()
if result == QMessageBox.Yes:
self.chips_list.clear()
self.populate_default_chips()
self.game_view.sc.clear()
self.save_chips()
self.game_view.update()


if __name__ == "__main__":
app = QApplication(sys.argv)
Expand Down

0 comments on commit 17178d9

Please sign in to comment.