some update

This commit is contained in:
沈瑗杰 2021-10-01 23:12:01 +08:00
parent f1d71b4861
commit c882d7901c
77 changed files with 180 additions and 207 deletions

View File

@ -15,27 +15,31 @@ hi = """Difficult Rocket is writen by shenjackyuanjie
mail: 3695888@qq.com or shyj3695888@163.com
QQ: 3695888"""
error_format = {
'TestError': '游戏正在调试中,某处引发了一个 TestError不是bug造成的原因',
'AssertionError': '游戏的某处检查未通过情报告issue',
'error.unknown': '游戏报错了现在输出报错信息请报告issue',
'error.happen': '游戏出现了一个报错!正在处理'
}
if __name__ == '__main__':
print("sys.path[0] = ", sys.path[0])
print("sys.argv[0] = ", sys.argv[0])
print("__file__ = ", __file__)
print("os.path.abspath(__file__) = ", os.path.abspath(__file__))
print("os.path.realpath(__file__) = ", os.path.realpath(__file__))
print("os.path.dirname(os.path.realpath(__file__)) = ", os.path.dirname(os.path.realpath(__file__)))
print("os.path.split(os.path.realpath(__file__)) = ", os.path.split(os.path.realpath(__file__)))
print("os.path.split(os.path.realpath(__file__))[0] = ", os.path.split(os.path.realpath(__file__))[0])
print("os.getcwd() = ", os.getcwd())
print(f'{__file__=}')
print(f'{sys.path[0]=}')
print(f'{sys.argv[0]=}')
print(f'{os.getcwd()=}')
print(f'{os.path.abspath(__file__)=}')
print(f'{os.path.realpath(__file__)=}')
# 输出一遍大部分文件位置相关信息 以后可能会加到logs里
file_path = os.path.split(os.path.realpath(__file__))[0]
os.chdir(file_path)
sys.path.append(f'{file_path}\\Difficult_Rocket')
sys.path.append(f'{file_path}\\libs')
sys.path.append(f'{file_path}/Difficult_Rocket')
sys.path.append(f'{file_path}/libs')
print(sys.path)
print(hi)
DEBUGGING = False
from Difficult_Rocket.api.Exp import *
print(multiprocessing.get_start_method())
try:
from Difficult_Rocket import crash
from Difficult_Rocket import main
@ -45,14 +49,15 @@ if __name__ == '__main__':
if DEBUGGING:
raise TestError('debugging')
except TestError:
print('the game is debugging. this crash is raise by TestError')
error = traceback.format_exc()
print(error)
crash.create_crash_report(error)
except:
print('the game has unknown error , now outputting error message')
except Exception as exp:
from Difficult_Rocket.api.translate import tr
print(error_format['error.happen'])
error = traceback.format_exc()
if (name := type(exp).__name__) in error_format:
print(error_format[name])
else:
print(error_format['error.unknown'])
print(error)
crash.create_crash_report(error)
else:

View File

@ -18,7 +18,6 @@ from typing import List, Optional
from decimal import Decimal
# linear_algebra
@ -159,7 +158,7 @@ def distance(A, B):
formats:
A & B format: docs.basic_config:basic_poi
"""
poi_dis = configs.basic_poi()
poi_dis = basic_poi()
for x in A, B:
x = decimal.Decimal(str(x))
xd = A[0] - B[0]
@ -179,7 +178,7 @@ def _BasicNumber(int_num=0, float_num=1, unit1=None, unit2=None) -> list:
unit1 = []
if unit2 is None:
unit2 = []
if tools.is_decimal(float_num): # is decimal class?
if is_decimal(float_num): # is decimal class?
return [int_num, float_num, unit1, unit2] # is just return
else:
return [int_num, decimal.Decimal(str(float_num)), unit1, unit2] # no create a decimal class
@ -296,3 +295,6 @@ class ScientificNumber:
self.multi_unit = []
else:
self.multi_unit = multi_unit
self.floats = floats
self.integer = integer

View File

@ -352,5 +352,3 @@ def distance(A, B):
poi_dis.append(poi_dis[0] + poi_dis[1])
poi_dis[2] **= 0.5
return poi_dis[2]
# def

View File

@ -83,16 +83,24 @@ class Lang:
raise LanguageError(f'there\'s no key {args} in both {self.language} and zh-CN')
try:
tr = Lang('zh-CN')
except FileNotFoundError:
import os
tr = Lang('zh-CN')
os.chdir('..')
os.chdir('..')
tr = Lang('zh-CN')
# font's value
HOS = 'HarmonyOS_Sans'
HOS_S = 'HarmonyOS_Sans_SC'
HOS_T = 'HarmonyOS_Sans_TC'
HOS_I = 'HarmonyOS_Sans_Italic'
HOS_C = 'HarmonyOS_Sans_Condensed'
HOS_CI = 'HarmonyOS_Sans_Condensed_Italic'
HOS_NA = 'HarmonyOS_Sans_Naskh_Arabic'
HOS_NAU = 'HarmonyOS_Sans_Naskh_Arabic_UI'
def test():
print(tr)
assert tr.language == 'zh-CN'
鸿蒙字体 = HOS
鸿蒙简体 = HOS_S
鸿蒙繁体 = HOS_T
鸿蒙斜体 = HOS_I
鸿蒙窄体 = HOS_C
鸿蒙斜窄体 = HOS_CI
鸿蒙阿拉伯 = HOS_NA
鸿蒙阿拉伯UI = HOS_NAU

View File

@ -33,7 +33,7 @@ if __name__ == '__main__': # been start will not run this
from Difficult_Rocket import crash
from Difficult_Rocket.api.Exp import *
from Difficult_Rocket.api.translate import tr
from Difficult_Rocket.drag_sprite import DragSprite
from Difficult_Rocket.graphics import widgets
from Difficult_Rocket.api import tools, load_file, new_thread, thread
# libs function
@ -48,12 +48,11 @@ else:
class Client:
def __init__(self, net_mode='local'):
start_time = time.time_ns()
# logging
self.logger = logging.getLogger('client')
# config
self.config = tools.load_file('configs/main.config')
# lang
self.lang = tools.load_file('configs/lang/%s.json5' % self.config['runtime']['language'], 'client')
# value
self.process_id = 'Client'
self.process_name = 'Client process'
@ -67,7 +66,11 @@ class Client:
caption=self.caption,
resizable=tools.format_bool(self.config['window']['resizable']),
visible=tools.format_bool(self.config['window']['visible']))
self.logger.info(tr['client']['setup.done'])
self.logger.info(tr.lang('client', 'setup.done'))
end_time = time.time_ns()
self.use_time = end_time - start_time
self.logger.info(tr.lang('client', 'setup.use_time').format(Decimal(self.use_time) / 1000000000))
self.logger.debug(tr.lang('client', 'setup.use_time_ns').format(self.use_time))
def start(self):
self.window.start_game() # 游戏启动
@ -77,7 +80,7 @@ class Client:
class ClientWindow(pyglet.window.Window):
def __init__(self, net_mode='local', *args, **kwargs):
self.times = [time.time()]
start_time = time.time_ns()
super().__init__(*args, **kwargs)
"""
:param dev_list: 共享内存
@ -96,8 +99,6 @@ class ClientWindow(pyglet.window.Window):
self.config_file = tools.load_file('configs/main.config')
self.FPS = Decimal(int(self.config_file['runtime']['fps']))
self.SPF = Decimal('1') / self.FPS
# lang
self.lang = tools.load_file('configs/lang/%s.json5' % self.config_file['runtime']['language'], 'client')
# dic
self.environment = {}
self.textures = {} # all textures
@ -111,41 +112,40 @@ class ClientWindow(pyglet.window.Window):
self.label_batch = pyglet.graphics.Batch()
# frame
self.frame = pyglet.gui.Frame(self)
self.M_frame = pyglet.gui.MovableFrame(self)
self.M_frame = pyglet.gui.MovableFrame(self, modifier=key.LCTRL)
# setup
self.setup()
self.info_label = pyglet.text.Label(x=10, y=self.height - 10,
anchor_x='left', anchor_y='top',
batch=self.label_batch)
pyglet.clock.schedule_interval(self.update, float(self.SPF))
self.logger.info(self.lang['setup.done'])
@new_thread('client_load_environment')
def load_environment(self) -> None:
# load parts info
self.environment['parts'] = load_file('configs/sys_value/parts.json5')
try:
self.load_textures()
except TexturesError:
raise
@new_thread('client_load_textures')
def load_textures(self) -> None:
# load parts
self.textures['parts'] = {}
for part in self.environment['parts']:
pass
self.logger.info(tr.lang('window', 'setup.done'))
end_time = time.time_ns()
self.use_time = end_time - start_time
self.logger.info(tr.lang('window', 'setup.use_time').format(Decimal(self.use_time) / 1000000000))
self.logger.debug(tr.lang('window', 'setup.use_time_ns').format(self.use_time))
def setup(self):
self.logger.info(tr.lang('window', 'os.pid_is').format(os.getpid(), os.getppid()))
image = pyglet.image.load('textures/Editor/PartButton.png')
self.textures['test'] = DragSprite(10, 20, image, batch=self.label_batch, drag_by_all=False, drag_out_window=True)
self.load_environment()
self.load_fonts()
@new_thread('client load_fonts')
def load_fonts(self):
file_path = './libs/fonts/HarmonyOS Sans/'
ttf_files = os.listdir(file_path)
self.logger.info(tr.lang('window', 'fonts.found').format(ttf_files))
for ttf_file in ttf_files:
pyglet.font.add_directory(f'{file_path}{ttf_file}')
@new_thread('client load_editor')
def load_Editor(self):
pass
def start_game(self) -> None:
self.run_input = True
# self.input_line = threading.Thread(target=self.read_input, name='client_read_line', daemon=True)
# self.input_line.start()
# self.read_thread = threading.Thread(target=self.read_input, name='client_read_input')
# self.read_thread.start()
# crash.all_thread.append(self.read_thread)
pyglet.app.run()
def read_input(self):
@ -162,9 +162,10 @@ class ClientWindow(pyglet.window.Window):
"""
def update(self, tick: float):
self.FPS_update(tick)
decimal_tick = Decimal(tick)
self.FPS_update(decimal_tick)
def FPS_update(self, tick: float):
def FPS_update(self, tick: Decimal):
now_FPS = pyglet.clock.get_fps()
if now_FPS > self.max_fps[0]:
self.max_fps = [now_FPS, time.time()]
@ -199,20 +200,13 @@ class ClientWindow(pyglet.window.Window):
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers) -> None:
# self.logger.debug('按键拖拽 %s %s %s %s %s %s' % (x, y, dx, dy, buttons, modifiers))
self.textures['test'].on_mouse_drag(x, y, dx, dy, buttons, modifiers)
pass
def on_mouse_press(self, x, y, button, modifiers) -> None:
if button == mouse.LEFT:
self.logger.debug(self.lang['mouse.press'].format([x, y], self.lang['mouse.left']))
elif button == mouse.RIGHT:
self.logger.debug(self.lang['mouse.press'].format([x, y], self.lang['mouse.right']))
self.textures['test']._sprite.rotation = random.randint(0, 360)
self.textures['test'].on_mouse_press(x, y, button, modifiers)
self.logger.debug(tr.lang('window', 'mouse.press').format([x, y], tr.lang('window', 'mouse.{}'.format(mouse.buttons_string(button)))))
def on_mouse_release(self, x, y, button, modifiers) -> None:
self.logger.debug(tr.lang('window', 'mouse.release').format([x, y], tr.lang('window', 'mouse.right')))
self.textures['test'].on_mouse_release(x, y, button, modifiers)
self.logger.debug(tr.lang('window', 'mouse.release').format([x, y], tr.lang('window', 'mouse.{}'.format(mouse.buttons_string(button)))))
def on_key_press(self, symbol, modifiers) -> None:
if symbol == key.ESCAPE and not (modifiers & ~(key.MOD_NUMLOCK |

View File

@ -1,105 +0,0 @@
"""
writen by shenjackyuanjie
mail: 3695888@qq.com
github: @shenjackyuanjie
gitee: @shenjackyuanjie
"""
import sys
if __name__ == '__main__': # been start will not run this
sys.path.append('/bin/libs')
sys.path.append('/bin')
import pyglet
from pyglet.window import mouse
from pyglet.gui.widgets import WidgetBase
class DragSprite(WidgetBase):
"""Instance of a drag button.
Triggers the event 'on_press' when it is clicked by the mouse.
Triggers the event 'on_release' when the mouse is released.
Triggers the event 'on_drag' when it is drag by mouse.
"""
# TODO make it More standardized
# TODO add group thing again(i don't know how to)
# by shenjack
def __init__(self,
x: int,
y: int,
image: pyglet.image.AbstractImage,
drag_by_all: bool = False,
drag_out_window: bool = False,
batch: pyglet.graphics.Batch = None,
group: pyglet.graphics.Group = None):
"""Create a draggable sprite.
:Parameters:
`x` : int
X coordinate of the push button.
`y` : int
Y coordinate of the push button.
`image` : `~pyglet.image.AbstractImage`
Image to display when the sprite is pressed.
`drag_by_all` : bool
If True then sprite will move whatever witch mouse button drag the sprite,
or the sprite will only move when Left mouse button drag.
`drag_out_window` : bool
If True then sprite will move out of the window with the mouse dragging,
or the sprite will only stop on the edge of the window.
`batch` : `~pyglet.graphics.Batch`
Optional batch to add the sprite to.
`group` : `~pyglet.graphics.Group`
Optional parent group of the sprite.
"""
super().__init__(x, y, image.width, image.height)
self._image = image
self._batch = batch or pyglet.graphics.Batch()
self._sprite = pyglet.sprite.Sprite(self._image, x, y, batch=batch, group=group)
self.drag_by_all = drag_by_all
self.drag_out_window = drag_out_window
self.dragging = False
def _check_hit(self, x, y):
return self._x < x < self._x + self._width and self._y < y < self._y + self._height
def on_mouse_press(self, x, y, buttons, modifiers):
if (buttons == mouse.LEFT) or self.drag_by_all:
if self._check_hit(x, y):
self.dragging = True
self.dispatch_event('on_press', buttons, self.dragging)
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
if self.dragging:
# TODO find a way to get window height and width
if (self._x + dx) < 0 and not self.drag_out_window:
self._sprite.x = 0
self._x = 0
else:
self._sprite.x += dx
self._x += dx
if (self._y + dy) < 0 and not self.drag_out_window:
self._sprite.y = 0
self._y = 0
else:
self._sprite.y += dy
self._y += dy
self.dispatch_event('on_drag', x, y, dx, dy, buttons, modifiers)
def draw(self):
self._sprite.draw()
# just use self.draw can draw
def on_mouse_release(self, x, y, buttons, modifiers):
if self.dragging:
self.dragging = not self.dragging
self.dispatch_event('on_release', x, y, buttons, modifiers)
DragSprite.register_event_type('on_drag')
DragSprite.register_event_type('on_press')
DragSprite.register_event_type('on_release')

View File

@ -0,0 +1,12 @@
# -------------------------------
# Difficult Rocket
# Copyright © 2021 by shenjackyuanjie
# All rights reserved
# -------------------------------
"""
writen by shenjackyuanjie
mail: 3695888@qq.com
github: @shenjackyuanjie
gitee: @shenjackyuanjie
"""

View File

@ -0,0 +1,35 @@
# -------------------------------
# Difficult Rocket
# Copyright © 2021 by shenjackyuanjie
# All rights reserved
# -------------------------------
"""
writen by shenjackyuanjie
mail: 3695888@qq.com
github: @shenjackyuanjie
gitee: @shenjackyuanjie
"""
from libs import pyglet
from libs.pyglet.gui import widgets
from libs.pyglet.sprite import Sprite
from libs.pyglet.graphics import Batch
from libs.pyglet.image import AbstractImage
class Parts(widgets.WidgetBase):
"""
parts
"""
def __init__(self,
x: int,
y: int,
width: int,
height: int,
textures: AbstractImage,
batch: Batch,
parts_data: dict):
super().__init__(x, y, width, height)
self.sprite = Sprite(img=textures, x=x, y=y, batch=batch)
self._value = 0

View File

@ -4,7 +4,7 @@
[![Generic badge](https://img.shields.io/badge/SemVer-2.0.0-blue.svg)](https://Semver.org/)
[![Generic badge](https://img.shields.io/badge/Write_with_Python-3.8.10-blue.svg)](https://Python.org)
[![Generic badge](https://img.shields.io/badge/Python-3.6_|_3.7_|_3.8_|_3.9-blue.svg)](https://Python.org)
[![Generic badge](https://img.shields.io/badge/Python-_3.8_|_3.9-blue.svg)](https://Python.org)
## Version
@ -12,7 +12,7 @@
<br/>[![Generic badge](https://img.shields.io/badge/Pre_Release-0.4.6-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases/v0.4.6)
<br/>![Generic badge](https://img.shields.io/badge/Devloping-0.5.2-blue.svg)
## 中文README请移步 [这里](./docs/README-cn.md)
## 中文README请移步 [这里](/docs/README-cn.md)
> It's a Simple Rocket liked game build with Python
@ -20,9 +20,9 @@
> Lighter than Vanilla SR
## [Plan feature list](./docs/plan_features)
## [Plan feature list](/docs/plan_features)
## [Update logs](./docs/update_logs.md)
## [Update logs](/docs/update_logs.md)
## Environment (been tested / develop on)
@ -31,9 +31,10 @@
- `Python 3.8.10`
- `Windows10 x64`
- `pyglet 2.0.dev9`
- `Json5 0.9.5`
- `Json5 0.9.6`
- `pillow 8.1.0`
- `AMD R5 5600X`
- `AMD RX 550 4G`
-
- `Develop platform 2 - macOS Big Sur`
- `Python 3.8.7`

View File

@ -16,19 +16,22 @@
},
'client': {
'setup.done': '客户端载入完成',
'setup.use_time': '客户端载入花费: {} 秒'
'setup.use_time': '客户端载入花费: {} 秒',
'setup.use_time_ns': '客户端载入花费: {} 纳秒'
},
'window': {
'setup.done': '游戏窗口载入完成',
'setup.use_time': '游戏窗口载入消耗时间: {} 秒',
'setup.use_time_ns': '游戏窗口载入消耗时间: {} 纳秒',
'os.pid_is': '游戏窗口 PID: {} PPID: {}',
'button.been_press': '按钮被按下,目前状态为:',
'mouse.press': '鼠标在 {} 被按下,按键为:{}',
'mouse.release': '鼠标在 {} 释放,按键为:{}',
'mouse.right': '右键',
'mouse.left': '左键',
'mouse.RIGHT': '右键',
'mouse.LEFT': '左键',
'libs.local': '正在使用本地 pyglet 库 版本为: {}',
'libs.outer': '正在使用全局 pyglet 库 版本为: {}\n(可能会造成bug因为本地库版本为2.0dev9)'
'libs.outer': '正在使用全局 pyglet 库 版本为: {}\n(可能会造成bug因为本地库版本为2.0dev9)',
'fonts.found': '在字体列表中找到以下字体库: {}'
},
'server': {
'setup.done': '服务端载入完成',

View File

@ -1,26 +1,31 @@
{
'Editor': {
'runtime': {
'toolbar.dark': 'Editor/ToolbarDark.png',
'toolbar.light': 'Editor/ToolbarLight.png',
'button_side.dark': 'Editor/ButtonDarkSide.png',
'button_side.light': 'Editor/ButtonLightSide.png'
'toolbar.dark': 'ToolbarDark.png',
'toolbar.light': 'ToolbarLight.png',
'button_side.dark': 'ButtonDarkSide.png',
'button_side.light': 'ButtonLightSide.png'
},
'toggle_button': {
'stage': 'Editor/ToolbarIconStaging.png',
'add_part': 'Editor/ToolbarIconAddPart.png',
'menu': 'Editor/ToolbarIconMenu.png'
'stage': 'ToolbarIconStaging.png',
'add_part': 'ToolbarIconAddPart.png',
'menu': 'ToolbarIconMenu.png'
},
'push_button': {
'zoom': 'Editor/ToolbarIconZoom.png',
'zoom.in': 'Editor/ToolbarIconZoomIn.png',
'zoom.out': 'Editor/ToolbarIconZoomOut.png',
'play': 'Editor/ToolbarIconPlay.png',
'rotate': 'Editor/RotateButton.png',
'trash_can': 'Editor/TrashCan.png'
'zoom': 'ToolbarIconZoom.png',
'zoom.in': 'ToolbarIconZoomIn.png',
'zoom.out': 'ToolbarIconZoomOut.png',
'play': 'ToolbarIconPlay.png',
'rotate': 'RotateButton.png',
'trash_can': 'TrashCan.png'
}
},
'Runtime': {
},
'Parts': {
'battery': 'Battery.png',
'beam': 'Beam.png',
'cover_bottom': 'CoverBottom.png',
'nose_cone': 'NoseCone.png'
}
}

View File

@ -5,7 +5,7 @@
[![Generic badge](https://img.shields.io/badge/SemVer-2.0.0-blue.svg)](https://Semver.org/)
[![Generic badge](https://img.shields.io/badge/编写_Python_版本-3.8.10-blue.svg)](https://Python.org)
[![Generic badge](https://img.shields.io/badge/Python-3.6_|_3.7_|_3.8_|_3.9-blue.svg)](https://Python.org)
[![Generic badge](https://img.shields.io/badge/Python-_3.8_|_3.9-blue.svg)](https://Python.org)
## 版本
@ -32,9 +32,10 @@
- `Python 3.8.10`
- `Windows10 x64`
- `pyglet 2.0.dev9`
- `Json5 0.9.5`
- `Json5 0.9.6`
- `pillow 8.1.0`
- `AMD R5 5600X(AMD YES!)`
- `AMD RX 550 4G`
-
- `开发平台2 macOS Big Sur`
- `Python 3.8.7`

View File

@ -3,13 +3,27 @@
## Readme
##### most badge can be clicked and jump
[![Generic badge](https://img.shields.io/badge/SemVer-2.0.0-blue.svg)](https://Semver.org/)
![Generic badge](https://img.shields.io/badge/Version-0.5.1-yellow.svg)
![Generic badge](https://img.shields.io/badge/Version-0.5.3-yellow.svg)
- [![Readme-github](https://img.shields.io/badge/Readme-Github-blue.svg?style=flat-square&logo=Github)](https://github.com/shenjackyuanjie/Difficult-Rocket)
- [![Readme-gitee](https://img.shields.io/badge/Readme-Gitee-blue.svg?style=flat-square&logo=Gitee)](https://gitee.com/shenjackyuanjie/Difficult-Rocket)
- [![Readme-gitee](https://img.shields.io/badge/Readme-中文(点我!)-blue.svg?style=flat-square)](README-cn.md)
- Using [SemVer 2.0.0](https://semver.org/) to manage version
## 202110 V 0.5.3
### Change
- now `Difficult Rocket` will only fit python3.8+
- because `:=`
- now main crash report handler have new way to handler crash
### Add
- `Difficult_Rocket.graphics.widgets.Parts`
- have many costume value
- `libs/fonts` now have `HarmonyOS_Sans`
## 20210928 V 0.5.2
### Change

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.