mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-13 03:27:26 +08:00
Code refactoring
- Code refactoring mainly for API - Delete a useless option in `setting.py` - Change some constants in Link Play mode
This commit is contained in:
@@ -9,6 +9,12 @@ class Chart:
|
||||
self.set_chart(song_id, difficulty)
|
||||
self.defnum: int = None
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
'difficulty': self.difficulty,
|
||||
'chart_const': self.chart_const
|
||||
}
|
||||
|
||||
@property
|
||||
def chart_const(self) -> float:
|
||||
return self.defnum / 10 if self.defnum else -1
|
||||
@@ -37,6 +43,37 @@ class Song:
|
||||
self.name: str = None
|
||||
self.charts: dict = None
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
'song_id': self.song_id,
|
||||
'name': self.name,
|
||||
'charts': [chart.to_dict() for chart in self.charts]
|
||||
}
|
||||
|
||||
def from_list(self, x: list) -> 'Song':
|
||||
if self.song_id is None:
|
||||
self.song_id = x[0]
|
||||
self.name = x[1]
|
||||
self.charts = [Chart(self.c, self.song_id, 0), Chart(self.c, self.song_id, 1), Chart(
|
||||
self.c, self.song_id, 2), Chart(self.c, self.song_id, 3)]
|
||||
self.charts[0].defnum = x[2]
|
||||
self.charts[1].defnum = x[3]
|
||||
self.charts[2].defnum = x[4]
|
||||
self.charts[3].defnum = x[5]
|
||||
return self
|
||||
|
||||
def insert(self) -> None:
|
||||
self.c.execute(
|
||||
'''insert into chart values (?,?,?,?,?,?)''', (self.song_id, self.name, self.charts[0].defnum, self.charts[1].defnum, self.charts[2].defnum, self.charts[3].defnum))
|
||||
|
||||
def select(self, song_id: str = None) -> 'Song':
|
||||
if song_id is not None:
|
||||
self.song_id = song_id
|
||||
|
||||
self.c.execute('''select * from chart where song_id=:a''', {
|
||||
'a': self.song_id})
|
||||
x = self.c.fetchone()
|
||||
if x is None:
|
||||
raise NoData('The song `%s` does not exist.' % self.song_id)
|
||||
|
||||
return self.from_list(x)
|
||||
|
||||
Reference in New Issue
Block a user