-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello Pop'n Music support #87
Open
xinrin
wants to merge
3
commits into
DragonMinded:trunk
Choose a base branch
from
xinrin:trunk
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from bemani.backend.hellopopn.factory import HelloPopnFactory | ||
from bemani.backend.hellopopn.base import HelloPopnBase | ||
|
||
__all__ = [ | ||
"HelloPopnFactory", | ||
"HelloPopnBase", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 | ||
|
||
|
||
class HelloPopnBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): | ||
""" | ||
Base game class for all Hello Pop'n Music versions. Handles common functionality for | ||
getting profiles based on refid, creating new profiles, looking up and saving | ||
scores. | ||
""" | ||
|
||
game = GameConstants.HELLO_POPN | ||
|
||
# Chart type, as saved into/loaded from the DB, and returned to game | ||
CHART_TYPE_EASY: Final[int] = 0 | ||
CHART_TYPE_NORMAL: Final[int] = 1 | ||
CHART_TYPE_HARD: Final[int] = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Dict, Optional, Any | ||
|
||
from bemani.backend.base import Base, Factory | ||
from bemani.backend.hellopopn.hellopopn import HelloPopnMusic | ||
from bemani.common import Model | ||
from bemani.data import Data | ||
|
||
|
||
class HelloPopnFactory(Factory): | ||
|
||
MANAGED_CLASSES = [ | ||
HelloPopnMusic, | ||
] | ||
|
||
@classmethod | ||
def register_all(cls) -> None: | ||
for game in ['JMP']: | ||
Base.register(game, HelloPopnFactory) | ||
|
||
@classmethod | ||
def create(cls, data: Data, config: Dict[str, Any], model: Model, parentmodel: Optional[Model]=None) -> Optional[Base]: | ||
|
||
if model.gamecode == 'JMP': | ||
return HelloPopnMusic(data, config, model) | ||
|
||
# Unknown game version | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
# vim: set fileencoding=utf-8 | ||
import copy | ||
from typing import Any, Dict | ||
|
||
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.protocol import Node | ||
|
||
class HelloPopnMusic( | ||
EventLogHandler, | ||
HelloPopnBase, | ||
): | ||
name = "Hello! Pop'n Music" | ||
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', | ||
'tip': 'Force unlock all songs.', | ||
'category': 'game_config', | ||
'setting': 'force_unlock_songs', | ||
}, | ||
], | ||
} | ||
|
||
def handle_game_common_request(self, request: Node) -> Node: | ||
root = Node.void('game') | ||
|
||
flag = Node.void('flag') | ||
root.add_child(flag) | ||
|
||
flag.set_attribute("id", '1') | ||
flag.set_attribute("s1", '1') | ||
flag.set_attribute("s2", '1') | ||
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 | ||
root = Node.void('game') | ||
|
||
userid = self.data.remote.user.from_refid(self.game, self.version, request.attribute('refid')) | ||
|
||
defaultprofile = Profile( | ||
self.game, | ||
self.version, | ||
request.attribute('refid'), | ||
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 | ||
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 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) | ||
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) | ||
|
||
|
||
last = Node.void('last') | ||
root.add_child(last) | ||
last.set_attribute('chara', profile.get_str('chara')) | ||
last.set_attribute('level', profile.get_str('level')) | ||
last.set_attribute('music_id', profile.get_str('music_id')) | ||
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 | ||
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) | ||
|
||
root = Node.void('game') | ||
sortedscores: Dict[int, Dict[int, Score]] = {} | ||
for score in scores: | ||
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] | ||
|
||
music = Node.void('music') | ||
root.add_child(music) | ||
music.set_attribute('music_id', str(score.id)) | ||
|
||
style = Node.void('style') | ||
music.add_child(style) | ||
style.set_attribute('id', "0") | ||
|
||
level = Node.void('level') | ||
style.add_child(level) | ||
|
||
level.set_attribute('id', str(score.chart)) | ||
level.set_attribute('score', str(score.points)) | ||
level.set_attribute('clear_type', str(score.data.get_int('clear_type'))) | ||
|
||
return root | ||
|
||
def handle_game_save_request(self, request: Node) -> Node: | ||
#Save profile data | ||
root = Node.void('game') | ||
|
||
userid = self.data.remote.user.from_refid(self.game, self.version, request.attribute('refid')) | ||
oldprofile = self.get_profile(userid) | ||
|
||
newprofile = copy.deepcopy(oldprofile) | ||
|
||
last = request.child('last') | ||
newprofile.replace_str('chara', last.attribute('chara')) | ||
newprofile.replace_str('level', last.attribute('level')) | ||
newprofile.replace_str('music_id', last.attribute('music_id')) | ||
newprofile.replace_str('style', last.attribute('style')) | ||
newprofile.replace_str('love', last.attribute('love')) | ||
|
||
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 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, | ||
}, | ||
) | ||
|
||
return root | ||
|
||
def handle_game_save_m_request(self, request: Node) -> Node: | ||
#Score saving | ||
|
||
clear_type = int(request.attribute('clear_type')) | ||
level = int(request.attribute('level')) | ||
songid = int(request.attribute('music_id')) | ||
refid = request.attribute('refid') | ||
points = int(request.attribute('score')) | ||
|
||
userid = self.data.remote.user.from_refid(self.game, self.version, refid) | ||
|
||
#pull old score | ||
oldscore = self.data.local.music.get_score( | ||
self.game, | ||
self.version, | ||
userid, | ||
songid, | ||
level, | ||
) | ||
|
||
history = ValidatedDict({}) | ||
|
||
if oldscore is None: | ||
# If it is a new score, create a new dictionary to add to | ||
scoredata = ValidatedDict({}) | ||
highscore = True | ||
else: | ||
# Set the score to any new record achieved | ||
highscore = points >= oldscore.points | ||
points = max(oldscore.points, points) | ||
scoredata = oldscore.data | ||
|
||
#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, | ||
self.version, | ||
userid, | ||
songid, | ||
level, | ||
lid, | ||
points, | ||
scoredata, | ||
highscore, | ||
) | ||
|
||
# Save score history | ||
self.data.local.music.put_attempt( | ||
self.game, | ||
self.version, | ||
userid, | ||
songid, | ||
level, | ||
lid, | ||
points, | ||
history, | ||
highscore, | ||
) | ||
|
||
root = Node.void('game') | ||
|
||
return root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from bemani.client.hellopopn.hellopopn import HelloPopnMuiscClient | ||
|
||
|
||
__all__ = [ | ||
"HelloPopnMuiscClient", | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about the purpose of this. It loads all achievements, overwrites the love given by the client with the achievement that we stored plus one, and then also attempts to cap at 5 in a weird way. What's the intent with this section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since server only sends what chara we level up, server side needs to plus 1, 5 is the max level, so if its more than 5 should stay as 5, ill try to make a cleaner form