Skip to content

Commit

Permalink
A lot of animation stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
FluffyOMC committed May 29, 2024
1 parent 6c8ca91 commit a40a855
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
12 changes: 9 additions & 3 deletions psychtobase/src/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ def note(data:int, length:float, time:str) -> dict:
return {"d": data, "t": time} # This is how the base game charts handle it so...
return {"d": data, "l": length, "t": time}

def event(event:str, time:float, values:dict) -> dict:
def event(time:float, event:str, values:dict) -> dict:
"""
Function created for faster creation of events.
"""
return {"e": event, "t": time, "v": values}
return {"t": time, "e": event, "v": values}

def focusCamera(time:float, char:bool):
"""
Function created for faster creation of camera change events.
"""
return event("FocusCamera", time, {"char": "0" if char else "1"})
return event(time, "FocusCamera", {"char": "0" if char else "1"})

def playAnimation(time:float, target: str, anim: str, force: bool):
"""
Function created for faster creation of Play Animation events
"""
return event(time, "PlayAnimation", {"target": target, "anim": anim, "force": force})

def coolText(text:str) -> str:
length = max(30, len(text) + 5)
Expand Down
60 changes: 58 additions & 2 deletions psychtobase/src/tools/ChartTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, path: str, output:str) -> None:
self.difficulties:list = []

self.chart:dict = deepcopy(Constants.BASE_CHART)
self.chart["events"] = []

self.initCharts()

Expand All @@ -49,8 +50,7 @@ def initCharts(self):

if file.suffix == ".json":
if file.stem == "events":
# If file is events.json: skip
logging.warn(f'[{self.songFile}] events.json not supported yet! Sorry!')
self.convertEvents(file)
continue
else:
# If file isn't json: skip
Expand Down Expand Up @@ -113,6 +113,26 @@ def setMetadata(self):
metadata["ratings"] = {diff: 0 for diff in self.difficulties} # Ratings don't do much now so :P
metadata["timeChanges"] = [Utils.timeChange(0, self.startingBpm, 4, 4, 0, [4]*4)]

def convertEvents(self, file):
logging.info(f"Events conversion for {self.songName} started!")

file = file.with_suffix('')
fileJson = Paths.parseJson(file)
events_data = fileJson.get("song", {}).get("events", [])

for event in events_data:
time = event[0]
event_type = event[1][0][0]

if event_type == "Play Animation":
anim = event[1][0][1]
target = event[1][0][2].lower() # When the game is stupid and doesn't like capitalization
self.chart["events"].append(Utils.playAnimation(time, target, anim, True))
else:
logging.warn(f"Conversion for event {event_type} is not implemented!")

logging.info(f"Events conversion for {self.songName} complete!")

def convert(self):
logging.info(f"Chart conversion for {self.metadata.get('songName')} started!")

Expand All @@ -122,6 +142,8 @@ def convert(self):
events = self.chart["events"]
events.append(Utils.focusCamera(0, prevMustHit))

existing_play_anims = set()

for i, (diff, cChart) in enumerate(self.charts.items()):
# cChart - convert Chart
self.chart["scrollSpeed"][diff] = cChart.get("speed")
Expand Down Expand Up @@ -163,6 +185,23 @@ def convert(self):

prev_notes.add((strumTime, noteData))

# Alt Animation implementation using Play Animations!
if len(note) > 3 and note[3] == "Alt Animation":
target = "player" if noteData in range(4) else "opponent"
if noteData in [0, 4]:
anim = "singLEFT-alt"
elif noteData in [1, 5]:
anim = "singDOWN-alt"
elif noteData in [2, 6]:
anim = "singUP-alt"
elif noteData in [3, 7]:
anim = "singRIGHT-alt"
play_animation = (strumTime, target, anim, True)

if play_animation not in existing_play_anims:
events.append(Utils.playAnimation(strumTime, target, anim, True))
existing_play_anims.add(play_animation)

notes.append(Utils.note(noteData, length, strumTime))

if i == 0:
Expand Down Expand Up @@ -196,6 +235,23 @@ def convert(self):
if total_duplicates > 0:
logging.warn(f"We found {total_duplicates} duplicate notes in '{diff}' difficulty data! Notes were successfully removed.")

# Process events within the chart file becuz fuck us
if "events" in cChart:
for event in cChart["events"]:
time = event[0]
event_type = event[1][0][0]

if event_type == "Play Animation":
anim = event[1][0][1]
target = event[1][0][2].lower()
play_animation = (time, target, anim, True)

if play_animation not in existing_play_anims:
events.append(Utils.playAnimation(time, target, anim, True))
existing_play_anims.add(play_animation)
else:
logging.warn(f"Conversion for event {event_type} is not implemented!")

logging.info(f"Chart conversion for {self.metadata.get('songName')} was completed!")

def save(self):
Expand Down

0 comments on commit a40a855

Please sign in to comment.