Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Added custom Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
megamaz committed Jan 4, 2021
1 parent fb4ad28 commit f4fce2e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
14 changes: 7 additions & 7 deletions noodle_extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import json, os
from pathlib import Path
from enum import Enum
from . import constants
from . import constants, exceptions


PATHSWINDOWS = { # A list of internal Beat Saber download paths.
Expand Down Expand Up @@ -124,7 +124,7 @@ def updateDependencies(self, dependency:str) -> list:
return _difficultyBeatmaps["_customData"]["_requirements"]

def __init__(self, customLevelPath:str):
'''
'''The base editor for editing. This will not be animating.
- `customLevelPath` The path where the `level.dat` is. (include `.dat`)
'''
if not os.path.exists(customLevelPath):
Expand Down Expand Up @@ -210,7 +210,7 @@ def getBlock(self, beat:int, pos:tuple) -> dict:
for x in notes["_notes"]:
if x["_time"] == beat and x["_lineIndex"] == pos[0] and x["_lineLayer"] == pos[1]:
return x
raise ValueError("Could not find note")
raise exceptions.NoteNotFoundError("Could not find note")
def getWall(self, beat:int, index:int, length:int) -> dict:
'''Returns a wall's data.
- `beat` the beat at which the wall starts.
Expand All @@ -223,7 +223,7 @@ def getWall(self, beat:int, index:int, length:int) -> dict:
for x in notes["_obstacles"]:
if x["_time"] == beat and x["_lineIndex"] == index and x["_duration"] == length:
return x
raise ValueError("Could not find wall.")
raise exceptions.WallNotFoundError("Could not find wall.")
def removeEvent(self, time:int, eventType:str, track:str, animationType:str=None) -> dict:
'''Removes an event from the `_customEvents` list. (Returns the removed event's data)\n
If there is more than just the `animationType` provided in the event, it will only remove the `animationType` property of the animation.\n
Expand Down Expand Up @@ -294,10 +294,10 @@ def animate(self, eventType:str, animationType:str, data:list, track:str, start:
'''

if animationType not in ANIMATORTYPES:
raise IndexError(f"The provided animation type {animationType} is not valid.")
raise ValueError(f"The provided animation type {animationType} is not valid.")

if eventType not in EVENTTYPES:
raise IndexError(f"The provided event type {eventType} is not valid")
raise ValueError(f"The provided event type {eventType} is not valid")


if animationType == "_color":
Expand Down Expand Up @@ -404,7 +404,7 @@ def editTrack(self, eventType, time, tracks, parentTrack:str=None) -> dict:

tracks = tracks.split() if type(tracks) != list else tracks # Makes tracks a list if it is a string
if eventType == "AssignTrackParent" and parentTrack is None:
raise ValueError("Received AssignTrackParent but no parentTrack")
raise exceptions.NoParentTrack("Received AssignTrackParent but no parentTrack")

if eventType == "AssignTrackParent":
event = {
Expand Down
14 changes: 14 additions & 0 deletions noodle_extensions/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class NoteNotFoundError(Exception):

def __init__(self, message="The Specified note couldn't be found"):
super().__init__(message)

class WallNotFoundError(Exception):

def __init__(self, message="The Specified wall couldn't be found"):
super().__init__(message)

class NoParentTrack(Exception):

def __init__(self, message="The Specified wall couldn't be found"):
super().__init__(message)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="NoodleExtensions",
version="1.3.2",
version="1.3.3",
license='MIT license',
description="Edit Beat Saber Noodle Extensions level easily using this library.",
long_description=long_description,
Expand Down

0 comments on commit f4fce2e

Please sign in to comment.