Skip to content

Commit

Permalink
fix issues and verify lint
Browse files Browse the repository at this point in the history
  • Loading branch information
xinrin committed Apr 1, 2024
1 parent 2b6ce21 commit cd587b1
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 140 deletions.
2 changes: 1 addition & 1 deletion bemani/backend/hellopopn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
__all__ = [
"HelloPopnFactory",
"HelloPopnBase",
]
]
4 changes: 1 addition & 3 deletions bemani/backend/hellopopn/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from typing import Optional
from typing_extensions import Final
from bemani.backend.base import Base
from bemani.backend.core import CoreHandler, CardManagerHandler, PASELIHandler
from bemani.common import GameConstants, ValidatedDict
from bemani.protocol import Node
from bemani.common import GameConstants


class HelloPopnBase(CoreHandler, CardManagerHandler, PASELIHandler, Base):
Expand Down
2 changes: 1 addition & 1 deletion bemani/backend/hellopopn/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def create(cls, data: Data, config: Dict[str, Any], model: Model, parentmodel: O
return HelloPopnMusic(data, config, model)

# Unknown game version
return None
return None
120 changes: 56 additions & 64 deletions bemani/backend/hellopopn/hellopopn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from bemani.backend.hellopopn.base import HelloPopnBase
from bemani.backend.ess import EventLogHandler
from bemani.common import ValidatedDict, VersionConstants, Profile
from bemani.data import Score
from bemani.data import Score
from bemani.protocol import Node


class HelloPopnMusic(
EventLogHandler,
HelloPopnBase,
Expand All @@ -16,14 +17,11 @@ class HelloPopnMusic(
version = VersionConstants.HELLO_POPN_MUSIC

@classmethod

def get_settings(cls) -> Dict[str, Any]:
"""
Return all of our front-end modifiably settings.
"""
return {
"ints": [
],
'bools': [
{
'name': 'Force Song Unlock',
Expand All @@ -46,18 +44,18 @@ def handle_game_common_request(self, request: Node) -> Node:
flag.set_attribute("t", '1')

root.add_child(Node.u32("cnt_music", 36))

return root

def handle_game_shop_request(self, request: Node) -> Node:
root = Node.void('game')

return root

def handle_game_new_request(self, request: Node) -> Node:
#profile creation
# profile creation
root = Node.void('game')

userid = self.data.remote.user.from_refid(self.game, self.version, request.attribute('refid'))

defaultprofile = Profile(
Expand All @@ -66,46 +64,44 @@ def handle_game_new_request(self, request: Node) -> Node:
request.attribute('refid'),
0,
{
'name': "なし",
'chara': "0",
'music_id': "0",
'level': "0",
'style': "0",
'love': "0"
'name': "なし",
'chara': "0",
'music_id': "0",
'level': "0",
'style': "0",
'love': "0"
},
)
self.put_profile(userid, defaultprofile)

return root

def handle_game_load_request(self, request: Node) -> Node:
#Load profile values
# Load profile values
root = Node.void('game')


userid = self.data.remote.user.from_refid(self.game, self.version, request.attribute('refid'))
profile = self.get_profile(userid)

achievements = self.data.local.user.get_achievements(self.game, self.version, userid)

game_config = self.get_game_config()
force_unlock_songs = game_config.get_bool("force_unlock_songs")
#if we send all chara love as max, all songs will be unlocked
# if we send all chara love as max, all songs will be unlocked
if force_unlock_songs:
for n in range(12):
chara = Node.void('chara')
chara.set_attribute('id', str(n))
chara.set_attribute('love', "5")
root.add_child(chara)
for n in range(12):
chara = Node.void('chara')
chara.set_attribute('id', str(n))
chara.set_attribute('love', "5")
root.add_child(chara)
else:
#load chara love progress
for achievement in achievements:
if achievement.type == 'toki_love':
chara = Node.void('chara')
chara.set_attribute('id', str(achievement.id))
chara.set_attribute('love', achievement.data.get_str('love'))
root.add_child(chara)

# load chara love progress
for achievement in achievements:
if achievement.type == 'toki_love':
chara = Node.void('chara')
chara.set_attribute('id', str(achievement.id))
chara.set_attribute('love', achievement.data.get_str('love'))
root.add_child(chara)

last = Node.void('last')
root.add_child(last)
Expand All @@ -115,11 +111,11 @@ def handle_game_load_request(self, request: Node) -> Node:
last.set_attribute('style', profile.get_str('style'))

self.update_play_statistics(userid)

return root

def handle_game_load_m_request(self, request: Node) -> Node:
#Load scores
# Load scores
userid = self.data.remote.user.from_refid(self.game, self.version, request.attribute('refid'))
scores = self.data.remote.music.get_scores(self.game, self.version, userid)

Expand All @@ -129,7 +125,7 @@ def handle_game_load_m_request(self, request: Node) -> Node:
if score.id not in sortedscores:
sortedscores[score.id] = {}
sortedscores[score.id][score.chart] = score

for song in sortedscores:
for chart in sortedscores[song]:
score = sortedscores[song][chart]
Expand All @@ -152,7 +148,7 @@ def handle_game_load_m_request(self, request: Node) -> Node:
return root

def handle_game_save_request(self, request: Node) -> Node:
#Save profile data
# Save profile data
root = Node.void('game')

userid = self.data.remote.user.from_refid(self.game, self.version, request.attribute('refid'))
Expand All @@ -169,35 +165,32 @@ def handle_game_save_request(self, request: Node) -> Node:

self.put_profile(userid, newprofile)


game_config = self.get_game_config()
force_unlock_songs = game_config.get_bool("force_unlock_songs")
#if we were on force unlock mode, achievements will not be modified
# if we were on force unlock mode, achievements will not be modified
if force_unlock_songs is False:
achievements = self.data.local.user.get_achievements(self.game, self.version, userid)
love = last.attribute('love')
for achievement in achievements:
if achievement.type == 'toki_love' and achievement.id == int(last.attribute('chara')):
love = str(int(achievement.data["love"]) + 1)
if achievement.data["love"] == "5":
love = "5"


self.data.local.user.put_achievement(
self.game,
self.version,
userid,
int(last.attribute('chara')),
'toki_love',
{
'love': love,
},
)
achievements = self.data.local.user.get_achievements(self.game, self.version, userid)
chara = int(last.attribute('chara'))
for achievement in achievements:
if achievement.type == 'toki_love' and achievement.id == chara:
love = int(achievement.data["love"])
if love > 5:

This comment has been minimized.

Copy link
@DragonMinded

DragonMinded Apr 2, 2024

Owner

Shouldn't this be "if love < 5" ?

self.data.local.user.put_achievement(
self.game,
self.version,
userid,
chara,
'toki_love',
{
'love': str(love + 1),
},
)
break

return root

def handle_game_save_m_request(self, request: Node) -> Node:
#Score saving
# Score saving

clear_type = int(request.attribute('clear_type'))
level = int(request.attribute('level'))
Expand All @@ -206,8 +199,8 @@ def handle_game_save_m_request(self, request: Node) -> Node:
points = int(request.attribute('score'))

userid = self.data.remote.user.from_refid(self.game, self.version, refid)
#pull old score

# Pull old score
oldscore = self.data.local.music.get_score(
self.game,
self.version,
Expand All @@ -227,15 +220,14 @@ def handle_game_save_m_request(self, request: Node) -> Node:
highscore = points >= oldscore.points
points = max(oldscore.points, points)
scoredata = oldscore.data
#Clear type

# Clear type
scoredata.replace_int('clear_type', max(scoredata.get_int('clear_type'), clear_type))
history.replace_int('clear_type', clear_type)

# Look up where this score was earned
lid = self.get_machine_id()


# Write the new score back
self.data.local.music.put_score(
self.game,
Expand All @@ -261,7 +253,7 @@ def handle_game_save_m_request(self, request: Node) -> Node:
history,
highscore,
)

root = Node.void('game')

return root
return root
2 changes: 1 addition & 1 deletion bemani/client/hellopopn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

__all__ = [
"HelloPopnMuiscClient",
]
]
Loading

0 comments on commit cd587b1

Please sign in to comment.