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

Commit

Permalink
Made objects make sense
Browse files Browse the repository at this point in the history
  • Loading branch information
megamaz committed Mar 16, 2021
1 parent 445b656 commit fc9b3f8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 40 deletions.
69 changes: 30 additions & 39 deletions noodleExtensions/objects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Note:
def __init__(self, beat, index, layer, type, cutDirection, **customData):
def __init__(self, _time, _lineIndex, _lineLayer, _type, _cutDirection, **_customData):
'''a note object which contains info on a note.\n
`beat` - The beat of the note.\n
`index` - The lineIndex of the note\n
Expand All @@ -9,37 +9,33 @@ def __init__(self, beat, index, layer, type, cutDirection, **customData):
`customData` - The note's custom data\n
'''
newNote = {
"_time":beat,
"_lineIndex":index,
"_lineLayer":layer,
"_type":type,
"_cutDirection":cutDirection
"_time":_time,
"_lineIndex":_lineIndex,
"_lineLayer":_lineLayer,
"_type":_type,
"_cutDirection":_cutDirection
}

if customData != {}:
newNote["_customData"] = customData
if _customData != {}:
newNote["_customData"] = _customData

self.note = newNote

self._time = beat
self._lineIndex = index
self._lineLayer = layer
self._type = type
self._cutDirection = cutDirection
self._customData = customData
self._time = _time
self._lineIndex = _lineIndex
self._lineLayer = _lineLayer
self._type = _type
self._cutDirection = _cutDirection
self._customData = _customData

@classmethod # allows to call method without needing to call __init__
def fromDict(cls, data:dict):
'''Will return a Note object from a note dict data.'''
if data.get("_customData") is None: # fixing index error
noteObjFromDict = cls(data["_time"], data["_lineIndex"], data["_lineLayer"], data["_type"], data["_cutDirection"])
else:
noteObjFromDict = cls(data["_time"], data["_lineIndex"], data["_lineLayer"], data["_type"], data["_cutDirection"], **data["_customData"])

noteObjFromDict = cls(**data)
return noteObjFromDict

class Obstacle:
def __init__(self, beat, index, type, duration, width, **customData):
def __init__(self, _time, _lineIndex, _type, _duration, _width, **_customData):
'''a note object which contains info on a note.\n
`beat` - The start beat of the wall.\n
`index` - The starting left position of the wall.\n
Expand All @@ -49,32 +45,27 @@ def __init__(self, beat, index, type, duration, width, **customData):
`customData` - The note's custom data\n
'''
newWall = {
"_time":beat,
"_lineIndex":index,
"_type":type,
"_duration":duration,
"_width":width,
"_customData":{}
"_time":_time,
"_lineIndex":_lineIndex,
"_type":_type,
"_duration":_duration,
"_width":_width
}

if customData != {}:
newWall["_customData"] = customData
if _customData != {}:
newWall["_customData"] = _customData

self.obstacle = newWall

self._time = beat
self._lineIndex = index
self._type = type
self._duration = duration
self._width = width
self._customData = customData
self._time = _time
self._lineIndex = _lineIndex
self._type = _type
self._duration = _duration
self._width = _width
self._customData = _customData

@classmethod
def fromDict(cls, data:dict):
'''Will return a Obstacle object from dict data.'''
if data.get("_customData") is None:
noteObjFromDict = cls(data["_time"], data["_lineIndex"], data["_type"], data["_duration"], data["_width"])
else:
noteObjFromDict = cls(data["_time"], data["_lineIndex"], data["_type"], data["_duration"], data["_width"], **data["_customData"])

noteObjFromDict = cls(**data)
return noteObjFromDict
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="2.0.3",
version="2.1.0",
license='MIT license',
description="Edit Beat Saber Noodle Extensions level easily using this library.",
long_description=long_description,
Expand Down

0 comments on commit fc9b3f8

Please sign in to comment.