Code refactoring

- Code refactoring
- Fix a bug that the other player will not become the host of the room at once, when the player disconnect in link play.

> Maybe add many unknown bugs. XD
> The song database `arcsong.db` will not used in the future. You can use a tool in `tool` folder to import old data.
This commit is contained in:
Lost-MSth
2022-07-04 18:36:30 +08:00
parent 9de62d3645
commit 6fcca17918
49 changed files with 3663 additions and 3660 deletions

60
tools/update_song.py Normal file
View File

@@ -0,0 +1,60 @@
import sqlite3
class Connect():
# 数据库连接类,上下文管理
def __init__(self, file_path='./arcaea_database.db'):
"""
数据库连接默认连接arcaea_database.db\
接受:文件路径\
返回sqlite3连接操作对象
"""
self.file_path = file_path
def __enter__(self):
self.conn = sqlite3.connect(self.file_path)
self.c = self.conn.cursor()
return self.c
def __exit__(self, exc_type, exc_val, exc_tb) -> bool:
if exc_type is not None:
if self.conn:
self.conn.rollback()
if self.conn:
self.conn.commit()
self.conn.close()
return True
def insert(cursor, song_id, name, a, b, c, d):
'''Insert a new song into database.'''
cursor.execute(
'''select exists(select * from chart where song_id=?)''', (song_id, ))
if cursor.fetchone()[0]:
return None
cursor.execute(
'''insert into chart values (?,?,?,?,?,?)''', (song_id, name, a, b, c, d))
def old_to_new():
'''Update old database to new database.'''
with Connect('./arcsong.db') as c:
c.execute(
'''select sid, name_en, rating_pst, rating_prs, rating_ftr, rating_byn from songs''')
data = c.fetchall()
with Connect() as c:
for x in data:
insert(c, x[0], x[1], x[2], x[3], x[4], x[5])
def main():
old_to_new()
if __name__ == '__main__':
main()
print('Done.')
input()
exit()