Skip to content

Commit

Permalink
add back function for buy image
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Dec 20, 2023
1 parent c7d5785 commit 868f4a5
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 63 deletions.
25 changes: 18 additions & 7 deletions data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,38 @@
"end_word": ""
},
"history": {},
"settings": {
"sound_volume": 0.5,
"music_volume": 0.5,
"current_theme_image": "lake",
"current_music": "",
"current_theme_colors": ""
},
"unlocked_themes": {
"japanese_1": {
"image": true,
"colors": true
},
"lake": {
"image": true,
"colors": false
},
"japanese_2": {
"image": false,
"colors": true
},
"japanese_3": {
"image": true,
"colors": false
}
},
"settings": {
"sound_volume": 0.5,
"music_volume": 0.5,
"current_theme_image": "japanese_1",
"current_music": "",
"current_theme_colors": ""
"unlocked_musics": {
"music_name": true
},
"user_profile": {
"status": "Beginner",
"level": 1,
"experience": 0,
"coins": 0
"coins": 1800
}
}
2 changes: 1 addition & 1 deletion resources/themes.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
},
"lake": {
"primary": [
0.5,
1,
0.49,
0.62
],
"secondary": [
Expand Down
76 changes: 52 additions & 24 deletions screens/custom_widgets/theme_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
from tools.constants import (
MAIN_COLOR,
SECOND_COLOR,
CUSTOMIZATION_LAYOUT_FONT_SIZE
CUSTOMIZATION_LAYOUT_FONT_SIZE,
USER_DATA,
THEMES_DICT
)

#############
Expand All @@ -51,49 +53,75 @@ class ThemeLayout(Image):

def __init__(
self,
theme_title: str = "",
theme_key: str = "",
text_font_name=PATH_TEXT_FONT,
font_size=CUSTOMIZATION_LAYOUT_FONT_SIZE,
primary_color=MAIN_COLOR,
secondary_color=SECOND_COLOR,
has_bought_image: bool = False,
has_bought_colors: bool = False,
is_using_image: bool = False,
is_using_colors: bool = False,
image_price: int = 0,
colors_price: int = 0,
font_ratio=None,
**kwargs):

self.theme_title = theme_title
if font_ratio is not None:
self.font_ratio = font_ratio

self.primary_color = primary_color
self.secondary_color = secondary_color
if theme_key not in THEMES_DICT:
theme_key = THEMES_DICT.keys()[0]

self.theme_key = theme_key
self.theme_title = THEMES_DICT[theme_key]["name"]
self.image_price = THEMES_DICT[theme_key]["image_price"]
self.colors_price = THEMES_DICT[theme_key]["colors_price"]
self.primary_color = THEMES_DICT[theme_key]["primary"]
self.secondary_color = THEMES_DICT[theme_key]["secondary"]

self.update_variables()

super().__init__(**kwargs)
self.text_font_name = text_font_name
self.font_size = font_size

self.has_bought_image = has_bought_image
self.has_bought_colors = has_bought_colors
self.is_using_image = is_using_image
self.is_using_colors = is_using_colors

self.image_price = image_price
self.colors_price = colors_price
def update_variables(self):
if self.theme_key in USER_DATA.unlocked_themes:
self.has_bought_image = USER_DATA.unlocked_themes[self.theme_key]["image"]
self.has_bought_colors = USER_DATA.unlocked_themes[self.theme_key]["colors"]
if USER_DATA.settings["current_theme_image"] == self.theme_key:
self.is_using_image = True
else:
self.is_using_image = False
if USER_DATA.settings["current_theme_colors"] == self.theme_key:
self.is_using_colors = True
else:
self.is_using_colors = False
else:
self.has_bought_image = False
self.has_bought_colors = False
self.is_using_image = False
self.is_using_colors = False

def update_display(self):
self.update_variables()
self.ids["buy_image_button"].price = self.image_price
self.ids["buy_image_button"].update_display()
self.ids["buy_colors_button"].price = self.colors_price
self.ids["buy_colors_button"].update_display()

def click_image(self):
print("image")
pass
if not self.has_bought_image:
bought_sucessfully = USER_DATA.buy_item(
self.theme_key, "image", self.image_price)
if bought_sucessfully:
self.get_root_window().children[0].get_screen(
"customization").update_coins()
self.has_bought_image = True
self.update_display()
elif self.has_bought_image and not self.is_using_image:
USER_DATA.change_theme_image(self.theme_key)
self.get_root_window().children[0].get_screen(
"customization").update_theme_layouts_display()

def click_colors(self):
print("colors")
pass
if not self.has_bought_colors:
USER_DATA.buy_item(self.theme_key, "colors", self.colors_price)
self.get_root_window().children[0].get_screen(
"customization").update_coins()
elif not self.is_using_colors:
pass
self.update_display()
2 changes: 1 addition & 1 deletion screens/customization.kv
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Coins counter
CoinsCounter:
size_hint: (0.6, 0.07)
pos_hint: {"center_x":0.5, "center_y":0.83}
pos_hint: {"center_x":0.5, "center_y":0.81}
font_ratio: root.font_ratio
coins_count: root.coins_count

Expand Down
40 changes: 10 additions & 30 deletions screens/customization.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,30 @@ def __init__(self, **kwargs) -> None:
self.fill_scrollview()

def on_pre_enter(self, *args):
self.coins_count = USER_DATA.user_profile["coins"] + 10000
self.coins_count = USER_DATA.user_profile["coins"]
return super().on_pre_enter(*args)

def on_resize(self, *args):
for act in self.THEME_LAYOUT_DICT:
self.THEME_LAYOUT_DICT[act].font_ratio = self.font_ratio
return super().on_resize(*args)

def update_coins(self):
self.coins_count = USER_DATA.user_profile["coins"]

def update_theme_layouts_display(self):
for theme in self.THEME_LAYOUT_DICT:
self.THEME_LAYOUT_DICT[theme].update_display()

def fill_scrollview(self):
scrollview_layout = self.ids["scrollview_layout"]
# Load the widgets
self.THEME_LAYOUT_DICT = {}
for theme in THEMES_DICT:
theme_title = THEMES_DICT[theme]["name"]
image_price = THEMES_DICT[theme]["image_price"]
primary_color = THEMES_DICT[theme]["primary"]
secondary_color = THEMES_DICT[theme]["secondary"]
if theme in USER_DATA.unlocked_themes:
has_bought_image = USER_DATA.unlocked_themes[theme]["image"]
has_bought_colors = USER_DATA.unlocked_themes[theme]["colors"]
if USER_DATA.settings["current_theme_image"] == theme:
is_using_image = True
else:
is_using_image = False
if USER_DATA.settings["current_theme_colors"] == theme:
is_using_colors = True
else:
is_using_colors = False
else:
has_bought_image = False
has_bought_colors = False
is_using_image = False
is_using_colors = False
current_theme_button = ThemeLayout(
theme_title=theme_title,
theme_key=theme,
source=PATH_BACKGROUNDS + THEMES_DICT[theme]["image"],
font_ratio=self.font_ratio * 0.8,
image_price=image_price,
has_bought_image=has_bought_image,
is_using_image=is_using_image,
has_bought_colors=has_bought_colors,
is_using_colors=is_using_colors,
primary_color=primary_color,
secondary_color=secondary_color)
font_ratio=self.font_ratio * 0.8)
current_theme_button.update_display()
self.THEME_LAYOUT_DICT[theme] = current_theme_button
scrollview_layout.add_widget(self.THEME_LAYOUT_DICT[theme])
29 changes: 29 additions & 0 deletions tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __init__(self) -> None:
self.history = data["history"]
self.settings = data["settings"]
self.unlocked_themes = data["unlocked_themes"]
self.unlocked_musics = data["unlocked_musics"]
self.user_profile = data["user_profile"]

def save_changes(self) -> None:
Expand All @@ -118,13 +119,41 @@ def save_changes(self) -> None:
data["history"] = self.history
data["settings"] = self.settings
data["unlocked_themes"] = self.unlocked_themes
data["unlocked_musics"] = self.unlocked_musics
data["user_profile"] = self.user_profile

# Save this dictionary
save_json_file(
file_path=PATH_USER_DATA,
dict_to_save=data)

def change_theme_image(self, theme):
USER_DATA.settings["current_theme_image"] = theme
self.save_changes()

def buy_item(self, theme, item_type, price):
if self.user_profile["coins"] >= price:
self.user_profile["coins"] = self.user_profile["coins"] - price
if item_type == "music":
self.unlocked_musics[theme] = True
elif item_type == "image":
if theme not in self.unlocked_themes:
self.unlocked_themes[theme] = {
"image": False,
"colors": False}
self.unlocked_themes[theme]["image"] = True
elif item_type == "colors":
if theme not in self.unlocked_themes:
self.unlocked_themes[theme] = {
"image": False,
"colors": False}
self.unlocked_themes[theme]["colors"] = True
else:
raise ValueError("Unrecognized item type.")
self.save_changes()
return True
return False


USER_DATA = UserData()

Expand Down

0 comments on commit 868f4a5

Please sign in to comment.