修改一些文件结构
啊啊啊
This commit is contained in:
parent
515b0f2501
commit
dc8ee0b4a5
@ -11,11 +11,10 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from libs.semver import VersionInfo
|
||||
from MCDR.version import Version
|
||||
|
||||
game_version = '0.6.2'
|
||||
game_version = Version("0.6.2")
|
||||
__version__ = game_version
|
||||
semver_game_version = VersionInfo.parse(game_version)
|
||||
|
||||
|
||||
playing = False
|
||||
|
@ -13,11 +13,11 @@ gitee: @shenjackyuanjie
|
||||
|
||||
# 单独导入的(或者就这一个有用的)
|
||||
from .delivery import Delivery
|
||||
from .new_thread import new_thread
|
||||
from utils.new_thread import new_thread
|
||||
|
||||
# lazy之后之前全部导入的(太多了写不动__all__了)
|
||||
from .Exp import *
|
||||
from .tools import *
|
||||
from utils.tools import *
|
||||
from .calculation import *
|
||||
from .scientific_unit import *
|
||||
|
||||
|
21
Difficult_Rocket/api/types/SR1/ship.py
Normal file
21
Difficult_Rocket/api/types/SR1/ship.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
# system function
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
# Difficult_Rocket function
|
||||
|
||||
# libs function
|
||||
|
||||
|
20
Difficult_Rocket/api/types/__init__.py
Normal file
20
Difficult_Rocket/api/types/__init__.py
Normal file
@ -0,0 +1,20 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
"""
|
||||
存档模块
|
||||
尽量同时兼容SR1和DR
|
||||
包含:
|
||||
解析存档文件
|
||||
创建存档文件
|
||||
"""
|
70
Difficult_Rocket/api/types/data_type.py
Normal file
70
Difficult_Rocket/api/types/data_type.py
Normal file
@ -0,0 +1,70 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
# system function
|
||||
|
||||
# Difficult_Rocket function
|
||||
|
||||
# libs function
|
||||
from MCDR.serializer import Serializable
|
||||
|
||||
"""
|
||||
DR 内部数据传输格式类型
|
||||
"""
|
||||
|
||||
|
||||
# 一艘船的数据格式
|
||||
class Ship(Serializable):
|
||||
data: dict
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
# 蓝图部件的数据格式
|
||||
class Blueprint(Serializable):
|
||||
data: dict
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
# 飞船上的单个部件的数据格式
|
||||
class Part(Serializable):
|
||||
data: dict
|
||||
|
||||
def __init__(self, part_type: str, **kwargs):
|
||||
super().__init__()
|
||||
self.type = part_type
|
||||
self.name = kwargs.get('name')
|
||||
|
||||
|
||||
# 整个存档的数据格式
|
||||
class Save(Serializable):
|
||||
data: dict
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
class PartType(Serializable):
|
||||
data: dict # 输出的数据格式
|
||||
|
||||
|
||||
|
||||
# 所有部件的格式的存储
|
||||
class PartTypes(Serializable):
|
||||
data: dict = {} # 所有部件的格式
|
||||
|
||||
def add_part(self, part_type: str, **kwargs):
|
||||
self.data[part_type] = Part(part_type, **kwargs)
|
@ -17,7 +17,6 @@ import sys
|
||||
import time
|
||||
import logging
|
||||
import traceback
|
||||
import configparser
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
@ -30,9 +29,10 @@ from Difficult_Rocket import translate
|
||||
from Difficult_Rocket.api.Exp import *
|
||||
from Difficult_Rocket.translate import tr
|
||||
from Difficult_Rocket.command import line
|
||||
from Difficult_Rocket.fps.fps_log import FpsLogger
|
||||
from Difficult_Rocket.guis.widgets import InputBox
|
||||
from Difficult_Rocket.api import tools, new_thread
|
||||
from Difficult_Rocket.api import new_thread
|
||||
from utils import tools
|
||||
from Difficult_Rocket.client.fps.fps_log import FpsLogger
|
||||
|
||||
# libs function
|
||||
local_lib = True
|
||||
@ -40,9 +40,11 @@ if local_lib:
|
||||
from libs import pyglet
|
||||
from libs.pyglet.window import Window
|
||||
from libs.pyglet.window import key, mouse
|
||||
from libs import toml
|
||||
else:
|
||||
import pyglet
|
||||
from pyglet.window import key, mouse
|
||||
import toml
|
||||
|
||||
|
||||
class Client:
|
||||
@ -51,7 +53,7 @@ class Client:
|
||||
# logging
|
||||
self.logger = logging.getLogger('client')
|
||||
# config
|
||||
self.config = tools.load_file('configs/main.config')
|
||||
self.config = tools.load_file('./configs/main.toml')
|
||||
# value
|
||||
self.process_id = 'Client'
|
||||
self.process_name = 'Client process'
|
||||
@ -95,9 +97,9 @@ class ClientWindow(Window):
|
||||
# configs
|
||||
pyglet.resource.path = ['/textures/']
|
||||
pyglet.resource.reindex()
|
||||
self.set_icon(pyglet.image.load('textures/icon.png'))
|
||||
self.main_config = tools.load_file('configs/main.config')
|
||||
self.game_config = tools.load_file('configs/game.config')
|
||||
self.set_icon(pyglet.image.load('./textures/icon.png'))
|
||||
self.main_config = tools.load_file('./configs/main.toml')
|
||||
self.game_config = tools.load_file('./configs/game.config')
|
||||
# dic
|
||||
self.environment = {}
|
||||
self.textures = {} # all textures
|
||||
@ -156,9 +158,13 @@ class ClientWindow(Window):
|
||||
# 从字体文件夹加载字体(或是字体类文件夹)
|
||||
if os.path.isfile(os.path.join(fonts_folder_path, fonts_folders, files)):
|
||||
# 如果是字体文件,则直接加载
|
||||
# self.logger.debug(tr.lang('window', 'fonts.load').format(os.path.join(fonts_folder_path, fonts_folders, files)))
|
||||
pyglet.font.add_file(os.path.join(fonts_folder_path, fonts_folders, files))
|
||||
else: # 否则,遍历加载字体类文件夹并加载
|
||||
for font in os.listdir(os.path.join(fonts_folder_path, fonts_folders, files)):
|
||||
if not font[-4:] == '.ttf':
|
||||
continue
|
||||
# self.logger.debug(tr.lang('window', 'fonts.load').format(os.path.join(fonts_folder_path, fonts_folders, files, font)))
|
||||
pyglet.font.add_file(os.path.join(fonts_folder_path, fonts_folders, files, font))
|
||||
|
||||
# @new_thread('window load_editor')
|
||||
@ -187,11 +193,11 @@ class ClientWindow(Window):
|
||||
|
||||
@new_thread('window save_info')
|
||||
def save_info(self):
|
||||
config_file = configparser.ConfigParser()
|
||||
config_file.read('configs/main.config')
|
||||
config_file['window']['width'] = str(self.width)
|
||||
config_file['window']['height'] = str(self.height)
|
||||
config_file.write(open('configs/main.config', 'w', encoding='utf-8'))
|
||||
print('save_info start')
|
||||
config_file = tools.load_file('./config/config.toml')
|
||||
config_file['window']['width'] = self.width
|
||||
config_file['window']['height'] = self.height
|
||||
toml.dump(config_file, open('./config/config.toml', 'w'))
|
||||
|
||||
"""
|
||||
draws and some event
|
@ -42,19 +42,17 @@ class FpsLogger:
|
||||
else:
|
||||
self.fps_list.append(1)
|
||||
if len(self.fps_list) > self.count:
|
||||
self.fps_list = self.fps_list[-self.count + 1:]
|
||||
self.fps_list = self.fps_list[-self.count + 1:] # 整个列表往前挪一位
|
||||
if len(self.get_fps_list) > self.count:
|
||||
self.get_fps_list = self.get_fps_list[-self.count + 1:]
|
||||
self.get_fps_list = self.get_fps_list[-self.count + 1:] # 整个列表往前挪一位
|
||||
try:
|
||||
self._fps = statistics.geometric_mean(self.fps_list[-100:])
|
||||
self.middle_fps = statistics.median(self.fps_list)
|
||||
self._fps = statistics.geometric_mean(self.fps_list[-100:]) # 取最后100个值的平均值
|
||||
self.middle_fps = statistics.median(self.fps_list) # 取中间值
|
||||
except Exception:
|
||||
print(self.fps_list)
|
||||
raise
|
||||
self._max_fps = max(self.fps_list)
|
||||
self._min_fps = min(self.fps_list)
|
||||
# 获取新fps
|
||||
del now_fps
|
||||
|
||||
@property
|
||||
def max_fps(self):
|
@ -17,14 +17,13 @@ import time
|
||||
import logging
|
||||
import logging.config
|
||||
import multiprocessing
|
||||
from multiprocessing import Manager as share
|
||||
|
||||
if __name__ == '__main__': # been start will not run this
|
||||
sys.path.append('/bin/libs')
|
||||
sys.path.append('/bin')
|
||||
|
||||
from Difficult_Rocket import client, server
|
||||
from Difficult_Rocket.api import tools
|
||||
from utils import tools
|
||||
from Difficult_Rocket.translate import tr
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@ gitee: @shenjackyuanjie
|
||||
from typing import Tuple
|
||||
|
||||
# from libs
|
||||
from semver import VersionInfo
|
||||
from MCDR.version import Version
|
||||
from MCDR.serializer import Serializable
|
||||
|
||||
# from DR
|
||||
@ -25,7 +25,7 @@ from Difficult_Rocket import semver_game_version
|
||||
mod系统参数
|
||||
"""
|
||||
MOD_loader_version = "0.0.1" # mod系统版本 版本号遵守semver2.0.0
|
||||
semver_loader_version = VersionInfo.parse(MOD_loader_version)
|
||||
semver_loader_version = Version(MOD_loader_version)
|
||||
|
||||
|
||||
"""
|
||||
@ -40,7 +40,7 @@ class MODInfo(Serializable):
|
||||
"""
|
||||
"""基本信息"""
|
||||
name: str # mod名称
|
||||
version: VersionInfo # mod版本
|
||||
version: Version # mod版本
|
||||
dependencies: list = [] # mod依赖
|
||||
|
||||
"""作者、描述"""
|
||||
@ -50,9 +50,9 @@ class MODInfo(Serializable):
|
||||
info: str = "" # 其他信息 (可以很多很多)
|
||||
|
||||
"""版本兼容信息"""
|
||||
write_version: VersionInfo # mod编写版本
|
||||
write_loader_version: VersionInfo # mod编写的加载器版本
|
||||
compatible_version: Tuple[VersionInfo, VersionInfo] = (semver_game_version, semver_game_version) # mod兼容版本
|
||||
write_version: Version # mod编写版本
|
||||
write_loader_version: Version # mod编写的加载器版本
|
||||
compatible_version: Tuple[Version, Version] = (semver_game_version, semver_game_version) # mod兼容版本
|
||||
# 第一个是最低兼容版本,第二个是最高兼容版本
|
||||
# 例如: ("1.0.0", "1.1.0") 表示从1.0.0版本开始兼容,到1.1.0版本结束兼容
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# -------------------------------
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie
|
||||
# All rights reserved
|
||||
@ -11,17 +11,17 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
|
||||
if __name__ == '__main__': # been start will not run this
|
||||
sys.path.append('/bin/libs')
|
||||
sys.path.append('/bin')
|
||||
|
||||
from Difficult_Rocket.api import tools
|
||||
from utils import tools
|
||||
from Difficult_Rocket.api.delivery import Delivery
|
||||
from Difficult_Rocket.api.new_thread import new_thread
|
||||
from utils.new_thread import new_thread
|
||||
|
||||
|
||||
# TODO 改变服务端启动逻辑 0.6.0会写完的(
|
@ -13,7 +13,7 @@ gitee: @shenjackyuanjie
|
||||
|
||||
from typing import Union
|
||||
|
||||
from Difficult_Rocket.api import tools
|
||||
from utils import tools
|
||||
from Difficult_Rocket.api.Exp import *
|
||||
|
||||
"""
|
||||
|
@ -11,7 +11,7 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from Difficult_Rocket.api import tools
|
||||
from utils import tools
|
||||
import os
|
||||
|
||||
import PIL.Image
|
||||
|
12
Difficult_Rocket/utils/__init__.py
Normal file
12
Difficult_Rocket/utils/__init__.py
Normal file
@ -0,0 +1,12 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
@ -21,9 +21,11 @@ import configparser
|
||||
|
||||
from xml.dom.minidom import parse
|
||||
|
||||
if __name__ == '__main__': # been start will not run this
|
||||
sys.path.append('/bin/libs')
|
||||
sys.path.append('/bin')
|
||||
if __name__ == '__main__': # 如果是直接运行该文件,则将工作目录切换到该文件所在目录
|
||||
sys.path.append('./libs')
|
||||
sys.path.append('./')
|
||||
|
||||
import toml
|
||||
|
||||
from libs import json5
|
||||
|
||||
@ -38,31 +40,31 @@ file_error = {'FileNotFoundError': 'no {filetype} file was founded!:\n file name
|
||||
'Error': 'get some unknown error when read {filetype} file {filename}! \n file type: {} \n file name: {} \n stack: {stack}'}
|
||||
|
||||
|
||||
def load_file(file_name: str, stack=None) -> dict:
|
||||
def load_file(file_name: str, stack=None):
|
||||
f_type = file_name[file_name.rfind('.') + 1:] # 从最后一个.到末尾 (截取文件格式)
|
||||
try:
|
||||
rd = NotImplementedError('解析失败,请检查文件类型/文件内容/文件是否存在!')
|
||||
get_file = NotImplementedError('解析失败,请检查文件类型/文件内容/文件是否存在!')
|
||||
if (f_type == 'json5') or (f_type == 'json'):
|
||||
try:
|
||||
with open(file_name, 'r', encoding='utf-8') as jf: # jf -> json file
|
||||
rd = json5.load(jf, encoding='uft-8')
|
||||
get_file = json5.load(jf, encoding='uft-8')
|
||||
except UnicodeDecodeError:
|
||||
with open(file_name, 'r', encoding='gbk') as jf:
|
||||
rd = json5.load(jf)
|
||||
get_file = json5.load(jf)
|
||||
tools_logger.info('文件 %s 解码错误,已重新使用gbk编码打开' % file_name)
|
||||
if stack is not None:
|
||||
rd = rd[stack]
|
||||
get_file = get_file[stack]
|
||||
elif f_type == 'xml':
|
||||
xml_load = parse(file_name)
|
||||
if stack is not None:
|
||||
rd = xml_load.getElementsByTagName(stack)
|
||||
get_file = xml_load.getElementsByTagName(stack)
|
||||
elif (f_type == 'config') or (f_type == 'conf') or (f_type == 'ini'):
|
||||
cd = configparser.ConfigParser()
|
||||
cd.read(file_name)
|
||||
get_file = configparser.ConfigParser()
|
||||
get_file.read(file_name)
|
||||
if stack:
|
||||
rd = cd[stack]
|
||||
else:
|
||||
rd = cd
|
||||
get_file = get_file[stack]
|
||||
elif f_type == 'toml':
|
||||
get_file = toml.load(file_name)
|
||||
except Exception as exp:
|
||||
error_type = type(exp).__name__
|
||||
if error_type in file_error:
|
||||
@ -70,7 +72,7 @@ def load_file(file_name: str, stack=None) -> dict:
|
||||
else:
|
||||
tools_logger.error(file_error['Error'].format(filetype=f_type, filename=file_name, stack=stack))
|
||||
raise
|
||||
return rd
|
||||
return get_file
|
||||
|
||||
|
||||
# main config
|
@ -41,6 +41,7 @@
|
||||
'libs.local': '正在使用本地 pyglet 库 版本为: {}',
|
||||
'libs.outer': '正在使用全局 pyglet 库 版本为: {}\n(可能会造成bug,因为本地库版本为2.0dev9)',
|
||||
'fonts.found': '在字体列表中找到以下字体库: {}',
|
||||
'fonts.load': '正在加载字体: {}',
|
||||
'game.input_stop': '控制台',
|
||||
'game.command_stop': '游戏内命令行',
|
||||
'game.window_stop': '窗口',
|
||||
|
21
configs/main.toml
Normal file
21
configs/main.toml
Normal file
@ -0,0 +1,21 @@
|
||||
[runtime]
|
||||
fps = 60
|
||||
version = "0.6.1"
|
||||
language = "zh-CN"
|
||||
date_fmt = '%Y-%m-%d %H-%M-%S'
|
||||
write_py_v = "3.8.10"
|
||||
fonts_folder = 'libs/fonts'
|
||||
|
||||
[window]
|
||||
style = "None"
|
||||
width = 1300
|
||||
height = 931
|
||||
visible = true
|
||||
caption = "Difficult Rocket {version}"
|
||||
resizable = true
|
||||
full_screen = false
|
||||
|
||||
[window.default]
|
||||
width = 1024
|
||||
height = 768
|
||||
|
49
docs/howto/game/命名.md
Normal file
49
docs/howto/game/命名.md
Normal file
@ -0,0 +1,49 @@
|
||||
# 关于命名的设计文档
|
||||
|
||||
## 命名规则
|
||||
|
||||
## 命名空间
|
||||
|
||||
- DR: Difficult Rocket
|
||||
- DR单独的部件、格式、结构的命名空间
|
||||
- 例子
|
||||
- `DR:pod-1`
|
||||
- `DR:solar.expand`
|
||||
- `DR:wheel.big`
|
||||
- `DR:planet.smearth`
|
||||
- `DR:planet.smars`
|
||||
- SR: SimpleRockets
|
||||
- SR的原生组件、格式、结构的命名空间(大概不会用多少)
|
||||
- 例子
|
||||
- `SR:pod-1`
|
||||
- `SR:wheel.small`
|
||||
- 其他:
|
||||
- 命名规则:
|
||||
- 可以包含
|
||||
- `ABC`
|
||||
- `abc`
|
||||
- `-` `_`
|
||||
- `123`
|
||||
- `从前有座山`
|
||||
- `Unicode表情`
|
||||
- 各种中文标点符号
|
||||
- 中文的啊!
|
||||
- `,` `。` `、` `·`
|
||||
- `;` `:`
|
||||
- `?` `!`
|
||||
- `(` `)`
|
||||
- `【` `】`
|
||||
- `《` `》`
|
||||
- `“` `”`
|
||||
- `‘` `’`
|
||||
- 不能以数字开头
|
||||
- 不能包含
|
||||
- `.` `/` `:`
|
||||
- `<` `>`
|
||||
- `|` `*` `?`
|
||||
- `"` `'`
|
||||
- 例子:
|
||||
- `Simple_Mod`
|
||||
- `真·简单mod`
|
||||
- `啊啊啊啊,↑↓Jundroo!`
|
||||
- mod添加的部件、格式、结构的命名空间
|
15
docs/howto/mod/loader.md
Normal file
15
docs/howto/mod/loader.md
Normal file
@ -0,0 +1,15 @@
|
||||
# MOD加载器设计文档
|
||||
|
||||
## v1-20220307
|
||||
|
||||
### __init__.py
|
||||
|
||||
- MODInfo类
|
||||
- MODInfo类的属性
|
||||
- 一些基本的MOD信息
|
||||
- 版本类信息
|
||||
- MOD版本号
|
||||
- DR MOD加载器兼容版本
|
||||
- DR 内容兼容版本
|
||||
- 需要的MOD版本号
|
||||
-
|
@ -19,9 +19,13 @@
|
||||
|
||||
### Add
|
||||
|
||||
- 添加模块 `semver` 和协议 (`LICENSE.txt`)
|
||||
- Add modules `semver` Add LICENSE (`LICENSE.txt`)
|
||||
[然后就很快被替换成MCDR的了]: <> (- 添加模块 `semver` 和协议 (`LICENSE.txt`))
|
||||
[Add soon been replace by MCDR]: <> ( - Add modules `semver` Add LICENSE (`LICENSE.txt`))
|
||||
- 添加了 `libs.MCDR` 文件夹 (`new_thread`没有包含在内)
|
||||
- Add `libs.MCDR` folder (`new_thread` not included)
|
||||
- 添加对 mod 的支持(还在写啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊)
|
||||
- 计划写个设计文档
|
||||
- Plan to write a design document
|
||||
|
||||
|
||||
## ~~202111 202112xx 20220119~~ 20220207 V 0.6.1
|
||||
|
@ -1,5 +1,6 @@
|
||||
# 本文件以 GNU Lesser General Public License v3.0(GNU LGPL v3) 开源协议进行授权 (谢谢狐狸写出这么好的MCDR)
|
||||
# 顺便说一句,我把所有的tab都改成了空格,因为我觉得空格比tab更好看(草,后半句是github copilot自动填充的)
|
||||
# 节选自MCDReforged(5a92965,2022年1月),略有改动[doge]
|
||||
|
||||
import copy
|
||||
from abc import ABC
|
||||
@ -7,8 +8,7 @@ from enum import EnumMeta
|
||||
from threading import Lock
|
||||
from typing import Union, TypeVar, List, Dict, Type, get_type_hints, Any
|
||||
|
||||
from semver import VersionInfo as semver_VersionInfo
|
||||
from libs.semver import VersionInfo as lib_semver_VersionInfo
|
||||
from MCDR.version import Version
|
||||
|
||||
"""
|
||||
This part of code come from MCDReforged(https://github.com/Fallen-Breath/MCDReforged)
|
||||
@ -41,13 +41,13 @@ def _get_args(cls: Type) -> tuple:
|
||||
return getattr(cls, '__args__', ())
|
||||
|
||||
|
||||
_BASIC_CLASSES = (type(None), bool, int, float, str, list, dict, lib_semver_VersionInfo, semver_VersionInfo)
|
||||
_BASIC_CLASSES = (type(None), bool, int, float, str, list, dict, Version)
|
||||
|
||||
|
||||
def serialize(obj) -> _BASIC_CLASSES:
|
||||
if type(obj) in (type(None), int, float, str, bool):
|
||||
return obj
|
||||
elif isinstance(obj, lib_semver_VersionInfo) or isinstance(obj, semver_VersionInfo):
|
||||
elif isinstance(obj, Version):
|
||||
return obj
|
||||
elif isinstance(obj, list) or isinstance(obj, tuple):
|
||||
return list(map(serialize, obj))
|
||||
@ -87,6 +87,9 @@ def deserialize(data, cls: Type[T], *, error_at_missing=False, error_at_redundan
|
||||
# For list and dict, since it doesn't have any type hint, we choose to simply return the data
|
||||
elif cls in _BASIC_CLASSES and type(data) is cls:
|
||||
return data
|
||||
# Version
|
||||
elif isinstance(cls, Version):
|
||||
return data
|
||||
# float thing
|
||||
elif cls is float and isinstance(data, int):
|
||||
return float(data)
|
||||
|
@ -1,27 +0,0 @@
|
||||
Copyright (c) 2013, Konstantine Rybnikov
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
Neither the name of the {organization} nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
File diff suppressed because it is too large
Load Diff
12
mods/DR/__init__.py
Normal file
12
mods/DR/__init__.py
Normal file
@ -0,0 +1,12 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
12
mods/DR/type_data.py
Normal file
12
mods/DR/type_data.py
Normal file
@ -0,0 +1,12 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
@ -11,18 +11,14 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
import cProfile
|
||||
import time
|
||||
|
||||
|
||||
def run():
|
||||
一个很大的整数 = 11111111111111111111111111111111111111111111111 * 111111235111
|
||||
|
||||
一个很大的浮点数 = 1111111111111111111111111111111111111111.1111111 * 11111123.5111
|
||||
print(一个很大的整数, '\n', 一个很大的浮点数)
|
||||
start_time = time.perf_counter_ns()
|
||||
print(*[x for x in range(1, 100000) if sum([int(i)**len(str(x)) for i in str(x)]) == x])
|
||||
print(time.perf_counter_ns() - start_time)
|
||||
|
||||
|
||||
cProfile.run("run")
|
||||
cProfile.run("run()")
|
||||
|
||||
"""
|
||||
1234569279011111111111111111111111111111111111098765418321
|
||||
1.234569279011111e+46
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user