Skip to content

Commit

Permalink
Merge branch 'main' of lupa.github.com:LupaDevStudio/Linconym
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed May 30, 2024
2 parents aad1ff0 + 12bd8f4 commit 56d76a1
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 28 deletions.
1 change: 1 addition & 0 deletions screens/boosters.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def on_pre_enter(self, *args):
if last_day_date != current_day_date:
USER_DATA.ads["current_day_date"] = current_day_date
USER_DATA.ads["number_daily_ads_left"] = 3
USER_DATA.ads["has_seen_daily_wheel"] = False

if last_week_date != current_week_date:
USER_DATA.ads["current_week_date"] = current_week_date
Expand Down
3 changes: 2 additions & 1 deletion screens/custom_widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
LevelUpPopup,
LoadingPopup,
RewardPopup,
ConversionPopup
ConversionPopup,
DailyWheelPopup
)

### Other widgets ###
Expand Down
1 change: 1 addition & 0 deletions screens/custom_widgets/popup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
from screens.custom_widgets.popup.loading_popup import LoadingPopup
from screens.custom_widgets.popup.reward_popup import RewardPopup
from screens.custom_widgets.popup.conversion_popup import ConversionPopup
from screens.custom_widgets.popup.daily_wheel_popup import DailyWheelPopup
65 changes: 65 additions & 0 deletions screens/custom_widgets/popup/daily_wheel_popup.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#:kivy 2.2.1



<DailyWheelPopup>:

RelativeLayout:
id: popup_layout

RelativeLayout:
size_hint: (0.8, 0.8)
pos_hint: {"center_x":0.5, "center_y": 0.625}

canvas.before:
PushMatrix
Rotate:
angle: root.angle
axis: 0, 0, 1
origin: self.width/2, self.height/2
canvas.after:
PopMatrix

Image:
id: my_image
source: "resources/images/front_daily_wheel.png"
size_hint: (1, 1)
pos_hint: {'center_x': 0.5, "center_y": 0.5}

Image:
id: image
source: "resources/images/back_daily_wheel.png"
size_hint: (0.8, 0.8)
pos_hint: {'center_x': 0.5, "center_y": 0.625}

# # Reward frame for Lincoins
# RewardFrame:
# pos_hint: {"center_x": 0.25, "top": 0.45} if root.win_linclues else {"center_x": 0.5, "top": 0.45}
# size_hint: (0.375, 0.15)
# reward: root.number_lincoins_won
# font_ratio: root.font_ratio
# plus_mode: True
# opacity: 1 if root.number_lincoins_won > 0 else 0

# # Reward frame for Linclues
# RewardFrame:
# pos_hint: {"center_x": 0.75, "top": 0.45}
# size_hint: (0.375, 0.15)
# reward: root.number_linclues_won
# font_ratio: root.font_ratio
# unit: "linclue"
# opacity: 1 if root.win_linclues else 0
# plus_mode: True

ColoredRoundedButton:
id: button
size_hint: (0.4, 0.15)
pos_hint: {"center_x":0.5, "center_y":0.12}
font_ratio: root.font_ratio
font_size: SMALL_BUTTON_FONT_SIZE
text: root.button_label
text_font_name: PATH_TEXT_FONT
background_color: root.secondary_color
touch_color: root.primary_color
color_label: root.color_label_button
release_function: root.release_function
68 changes: 68 additions & 0 deletions screens/custom_widgets/popup/daily_wheel_popup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Module to create a popup to allow the user to regenerate lives.
"""

###############
### Imports ###
###############

### Python imports ###

import random as rd

### Kivy imports ###

from kivy.properties import (
StringProperty,
NumericProperty,
ColorProperty,
ObjectProperty
)
from kivy.animation import Animation, AnimationTransition

### Local imports ###

from screens.custom_widgets.popup.custom_popup import CustomPopup


#############
### Class ###
#############


class DailyWheelPopup(CustomPopup):

title = StringProperty()
angle = NumericProperty(0)
primary_color = ColorProperty()
secondary_color = ColorProperty()
color_label_button = ColorProperty((1, 1, 1, 1))
release_function = ObjectProperty(lambda: 1 + 1)
button_label = StringProperty()

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.title = "Daily Wheel"

def on_open(self):
self.release_function = self.start_animation
self.button_label = "Spin"
return super().on_open()

def on_angle(self, item, angle):
if angle == 360:
item.angle = 0

def start_animation(self):
number_of_turns = rd.randint(4, 8)
last_angle = rd.randint(0, 360) + 360 * number_of_turns
anim = Animation(angle=last_angle, duration=number_of_turns,
t=AnimationTransition.out_quad)
anim.start(self)
self.ids.button.disabled = True
anim.on_complete = self.finish_animation

def finish_animation(self, *args):
self.button_label = "Close"
self.ids.button.disabled = False
self.release_function = self.dismiss
5 changes: 4 additions & 1 deletion screens/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
from tools.linconym import (
ClassicGame
)
from tools.levels import (
compute_lincoins_when_level_up
)

#############
### Class ###
Expand Down Expand Up @@ -502,7 +505,7 @@ def display_success_popup(self, end_level_dict):
popup = LevelUpPopup(
primary_color=self.primary_color,
secondary_color=self.secondary_color,
number_lincoins_won=10, # TODO
number_lincoins_won=compute_lincoins_when_level_up(USER_DATA.user_profile["status"]),
has_changed_status=has_changed_status,
size_hint=size_hint_popup,
current_status=current_status,
Expand Down
25 changes: 24 additions & 1 deletion screens/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
### Imports ###
###############

### Python imports ###

from datetime import datetime

### Local imports ###

from tools.constants import (
SCREEN_TITLE,
SCREEN_BOTTOM_BAR,
Expand All @@ -16,7 +22,8 @@
music_mixer
)
from screens.custom_widgets import (
LinconymScreen
LinconymScreen,
DailyWheelPopup
)


Expand All @@ -40,6 +47,22 @@ def on_enter(self, *args):
current_music = USER_DATA.settings["current_music"]
if music_mixer.musics[current_music].state == "stop":
music_mixer.play(current_music, loop=True)

today_date = datetime.today().strftime('%m/%d/%Y')
if USER_DATA.ads["current_day_date"] != today_date:
USER_DATA.ads["current_day_date"] = today_date
USER_DATA.ads["number_daily_ads_left"] = 3
USER_DATA.ads["has_seen_daily_wheel"] = False

if not USER_DATA.ads["has_seen_daily_wheel"]:
USER_DATA.ads["has_seen_daily_wheel"] = True
popup = DailyWheelPopup(
font_ratio=self.font_ratio,
primary_color=self.primary_color,
secondary_color=self.secondary_color
)
popup.open()
USER_DATA.save_changes()
return super().on_enter(*args)

def open_classic_mode(self):
Expand Down
25 changes: 5 additions & 20 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
Image:
id: my_image
source: "resources/images/front_daily_wheel.png"
size_hint: None, None
size: 500, 500
size_hint: 0.5, 0.5
pos_hint: {'center_x': 0.5, "center_y": 0.5}
Image:
id: image
source: "resources/images/back_daily_wheel.png"
size_hint: None, None
size: 500, 500
size_hint: 0.5, 0.5
pos_hint: {'center_x': 0.5, "center_y": 0.5}
''')

Expand All @@ -41,23 +39,10 @@ class Loading(FloatLayout):
def __init__(self, **kwargs):

super(Loading, self).__init__(**kwargs)
# anim = Animation(angle=360, duration=0.5)
# anim += Animation(angle = 360, duration=0.51)
# anim += Animation(angle = 360, duration=0.525)
# anim += Animation(angle = 360, duration=0.55)
# anim += Animation(angle = 360, duration=0.6)
# anim += Animation(angle = 360, duration=0.65)
# anim += Animation(angle = 360, duration=0.7)
# anim += Animation(angle = 360, duration=0.85)
# anim += Animation(angle = 360, duration=1)
# anim += Animation(angle = 360, duration=1.5)
# anim += Animation(angle = 360, duration=2)
# anim += Animation(angle = 360, duration=2.5)
# anim += Animation(angle=360, duration=3)
last_angle = rd.randint(0, 360) + 360 * 4
anim = Animation(angle=last_angle, duration=5,
number_of_turns = rd.randint(4, 8)
last_angle = rd.randint(0, 360) + 360 * number_of_turns
anim = Animation(angle=last_angle, duration=number_of_turns+1,
t=AnimationTransition.out_quad)
# anim.repeat = True
anim.start(self)

def on_angle(self, item, angle):
Expand Down
4 changes: 3 additions & 1 deletion tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

# scale for experience awarded to the user
XP_PER_LEVEL: int = 100
LINCOINS_PER_LEVEL: int = 100

# Create the user data json if it does not exist
if not os.path.exists(PATH_USER_DATA):
Expand Down Expand Up @@ -133,7 +134,8 @@
"current_day_date": "",
"current_week_date": "",
"number_daily_ads_left": 3,
"number_weekly_ads_left": 1
"number_weekly_ads_left": 1,
"has_seen_daily_wheel": False
}
}
save_json_file(PATH_USER_DATA, default_user_data)
Expand Down
11 changes: 9 additions & 2 deletions tools/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from tools.constants import (
XP_PER_LEVEL,
USER_STATUS_DICT
USER_STATUS_DICT,
LINCOINS_PER_LEVEL
)

#################
Expand Down Expand Up @@ -87,10 +88,16 @@ def compute_xp_to_level_up(current_level: int):

current_rank = get_rank(current_level)
current_rank_id = convert_rank_name_to_int(current_rank)
xp_required = (1 + 2 * current_rank_id) * XP_PER_LEVEL
xp_required = (1 + 2 * current_rank_id) * LINCOINS_PER_LEVEL

return xp_required

def compute_lincoins_when_level_up(current_rank):

current_rank_id = convert_rank_name_to_int(current_rank)
xp_required = (1 + 2 * current_rank_id) * XP_PER_LEVEL

return xp_required

def get_level(total_xp: int, get_remaining_xp: bool = False):
"""
Expand Down
4 changes: 2 additions & 2 deletions tools/linconym.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,8 @@ def award_stars_xp(self, solution_found) -> None:
nb_words_previous_best)
previous_nb_stars = self.get_nb_stars(nb_words_previous_best)
# award newly acquired xp
self.xp_earned = int(
(xp_fraction - previous_xp_fraction) * XP_PER_LEVEL + 0.001)
self.xp_earned = int(round(
(xp_fraction - previous_xp_fraction) * XP_PER_LEVEL, 0))
USER_DATA.user_profile[XP_KEY] += self.xp_earned
# Award newly acquired lincoins
lincoins_earned_before = NB_LINCOINS_PER_STAR_DICT[previous_nb_stars]
Expand Down

0 comments on commit 56d76a1

Please sign in to comment.