diff --git a/bin/client.py b/bin/client.py index b703c71..410f2b5 100644 --- a/bin/client.py +++ b/bin/client.py @@ -75,10 +75,12 @@ class window(pyglet.window.Window): self.view = 'space' self.net_mode = net_mode # FPS - self.max_fps = self.FPS - self.min_fps = self.FPS + self.max_fps = [self.FPS, time.time()] + self.min_fps = [self.FPS, time.time()] + self.fps_wait = 5 + # lang + self.lang = tools.config('sys_value/lang/%s.json5' % language, 'client') # configs - self.lang = tools.config('sys_value/lang/%s.json5' % language) self.view = tools.config('configs/view.json5') self.map_view = [configs.basic_poi(poi_type='chunk')] self.part_list = tools.config('sys_value/parts.json5') @@ -91,7 +93,7 @@ class window(pyglet.window.Window): self.label_batch = pyglet.graphics.Batch() self.runtime_batch = pyglet.graphics.Batch() # window - self.logger.info('client setup done!') + self.logger.info('%s' % self.lang['setup.done']) self.textures = {} # setup self.setup() @@ -108,6 +110,9 @@ class window(pyglet.window.Window): path = parts[part][2][0] part_image = image.load('textures/' + path) self.textures['part'][part] = part_image + pyglet.resource.path = ['textures'] + pyglet.resource.reindex() + self.trash_can = pyglet.resource.image('Editor/TrashCan.png') # tests self.info_label = pyglet.text.Label(text='test %s' % pyglet.clock.get_fps(), @@ -118,26 +123,34 @@ class window(pyglet.window.Window): # draws def update(self, ree): + self.FPS_update() + + def FPS_update(self): now_FPS = pyglet.clock.get_fps() - if now_FPS > self.max_fps: - self.max_fps = now_FPS - elif now_FPS < self.min_fps: - self.min_fps = now_FPS - self.info_label.text = 'now FPS: %03d \n max FPS: %02d \n min FPS: %02d' % (now_FPS, self.max_fps, self.min_fps) - self.info_label.anchor_x = 'left' - self.info_label.anchor_y = 'top' + if now_FPS > self.max_fps[0]: + self.max_fps = [now_FPS, time.time()] + elif now_FPS < self.min_fps[0]: + self.min_fps = [now_FPS, time.time()] + else: + if (time.time() - self.max_fps[1]) > self.fps_wait: + self.max_fps = [self.FPS, time.time()] + elif (time.time() - self.min_fps[1]) > self.fps_wait: + self.min_fps = [self.FPS, time.time()] + self.info_label.text = 'now FPS: %03d max FPS: %02d min FPS: %02d' % ( + now_FPS, self.max_fps[0], self.min_fps[0]) def on_draw(self): + self.clear() + self.build_draw() self.draw_batch() def draw_batch(self): - self.clear() self.part_batch.draw() self.runtime_batch.draw() self.label_batch.draw() def build_draw(self): - pass + self.trash_can.blit(x=self.width - 90, y=self.height - 90) def space_draw(self): # render parts diff --git a/bin/main.py b/bin/main.py index 4fdf745..49eb076 100644 --- a/bin/main.py +++ b/bin/main.py @@ -39,8 +39,7 @@ class Game: # lang_config self.language = tools.config('sys_value/basic_config.json5') self.language = self.language['language'] - self.lang = tools.config('sys_value/lang/%s.json5' % self.language) - self.lang = self.lang['main'] + self.lang = tools.config('sys_value/lang/%s.json5' % self.language, 'main') # logger self.log_config = tools.config('configs/logging.json5', 'file') self.log_filename = configs.name_handler(self.log_config['filename']['main'], diff --git a/bin/server.py b/bin/server.py index 07fc455..2f822d2 100644 --- a/bin/server.py +++ b/bin/server.py @@ -1,10 +1,16 @@ -''' +""" writen by shenjackyuanjie mail: 3695888@qq.com -''' +""" +import os import multiprocessing as mp +try: + from bin import tools +except (ModuleNotFoundError, ImportError, ImportWarning): + import tools + class server(mp.Process): def __init__(self, dev_list, dev_dic, logger, language='zh-cn', net_mode='local'): @@ -15,10 +21,13 @@ class server(mp.Process): # value self.process_id = 'Server' self.process_name = 'server process' + self.process_pid = os.getpid() + # lang + self.lang = tools.config('sys_value/lang/%s.json5' % language, 'server') # share memory self.dev_list = dev_list self.dev_dic = dev_dic - self.logger.info('server setup done!') + self.logger.info('%s' % self.lang['setup.done']) def run(self): pass diff --git a/bin/tools.py b/bin/tools.py index 5947a88..dc0e252 100644 --- a/bin/tools.py +++ b/bin/tools.py @@ -212,7 +212,7 @@ def config(file_name, stack=None): try: xml_load = parse(file_name) except FileNotFoundError as exp: - log = 'no config json(5) file \n file name : %s \n stack : %s' % ( + log = 'no config xml file \n file name : %s \n stack : %s' % ( file_name, stack) tools_logger.exception(log) raise FileNotFoundError(log) diff --git a/bin/unpack_textures.py b/bin/unpack_textures.py index 3ed30eb..1a0c3b9 100644 --- a/bin/unpack_textures.py +++ b/bin/unpack_textures.py @@ -39,7 +39,7 @@ def cut_and_save(config, save_path): print(exp) for config_ in configs['images']: config__ = configs['images'][config_] - save_name = 'textures/' + save_path + config_ + save_name = 'textures/%s/%s' % (save_path, config_) x, y, w, h, t = config__[0], config__[1], config__[2], config__[3], config__[4] crop_box = [x, y, x + w, y + h] pic_ = pic.crop(crop_box) @@ -53,3 +53,4 @@ def All_in_one_cut(xml, path): json_name = xml[:-4] + '.json5' rewrite_config(xml, json_name) cut_and_save(json_name, path) + diff --git a/sys_value/lang/zh-cn.json5 b/sys_value/lang/zh-cn.json5 index a9bbe36..7439a52 100644 --- a/sys_value/lang/zh-cn.json5 +++ b/sys_value/lang/zh-cn.json5 @@ -9,5 +9,11 @@ 'logger.logfile_fmt': '日志文件记录格式:', 'logger.logfile_datefmt': '日志文件日期格式:', 'game_start.at': '游戏主线程开始于:' + }, + 'client': { + 'setup.done': '客户端载入完成' + }, + 'server': { + 'setup.done': '服务端载入完成' } } \ No newline at end of file diff --git a/tests/test_image.py b/tests/test_image.py new file mode 100644 index 0000000..0c8d0a6 --- /dev/null +++ b/tests/test_image.py @@ -0,0 +1,18 @@ +import pyglet + +window = pyglet.window.Window(width=1000, height=1000) +# a_image = pyglet.image.load('textures/Runtime.png') +pyglet.resource.path = ['../textures'] +pyglet.resource.reindex() +b_image = pyglet.resource.image('Runtime.png') +c_image = pyglet.resource.image('Editor/TrashCan.png') + + +@window.event +def on_draw(): + window.clear() + b_image.blit(x=500, y=10) + c_image.blit(x=500, y=600) + + +pyglet.app.run() diff --git a/textures/Editor.json5 b/textures/Editor.json5 new file mode 100644 index 0000000..cc58afc --- /dev/null +++ b/textures/Editor.json5 @@ -0,0 +1,131 @@ +{ + image_name: "Editor.png", + images: { + "ButtonDarkSide.png": [ + 508, + 2, + 2, + 100, + null + ], + "ButtonLightSide.png": [ + 2, + 508, + 100, + 2, + "y" + ], + "DeleteButton.png": [ + 364, + 148, + 32, + 32, + null + ], + "DuplicateButton.png": [ + 406, + 84, + 80, + 80, + null + ], + "MirrorButton.png": [ + 324, + 14, + 80, + 80, + null + ], + "PartButton.png": [ + 2, + 2, + 320, + 100, + null + ], + "PartGroupHeader.png": [ + 2, + 104, + 45, + 320, + "y" + ], + "RotateButton.png": [ + 426, + 2, + 80, + 80, + null + ], + "ToolbarDark.png": [ + 324, + 8, + 100, + 4, + "y" + ], + "ToolbarIconAddPart.png": [ + 312, + 148, + 50, + 50, + null + ], + "ToolbarIconMenu.png": [ + 260, + 104, + 50, + 50, + null + ], + "ToolbarIconPlay.png": [ + 208, + 104, + 50, + 50, + null + ], + "ToolbarIconStaging.png": [ + 156, + 104, + 50, + 50, + null + ], + "ToolbarIconZoom.png": [ + 49, + 104, + 50, + 50, + null + ], + "ToolbarIconZoomIn.png": [ + 104, + 104, + 50, + 50, + null + ], + "ToolbarIconZoomOut.png": [ + 324, + 96, + 50, + 50, + null + ], + "ToolbarLight.png": [ + 324, + 2, + 100, + 4, + "y" + ], + "TrashCan.png": [ + 2, + 426, + 80, + 80, + null + ] + } +} \ No newline at end of file diff --git a/textures/Editor/ButtonDarkSide.png b/textures/Editor/ButtonDarkSide.png new file mode 100644 index 0000000..09b98bb Binary files /dev/null and b/textures/Editor/ButtonDarkSide.png differ diff --git a/textures/Editor/ButtonLightSide.png b/textures/Editor/ButtonLightSide.png new file mode 100644 index 0000000..4739a4e Binary files /dev/null and b/textures/Editor/ButtonLightSide.png differ diff --git a/textures/Editor/DeleteButton.png b/textures/Editor/DeleteButton.png new file mode 100644 index 0000000..826b06e Binary files /dev/null and b/textures/Editor/DeleteButton.png differ diff --git a/textures/Editor/DuplicateButton.png b/textures/Editor/DuplicateButton.png new file mode 100644 index 0000000..dc803b4 Binary files /dev/null and b/textures/Editor/DuplicateButton.png differ diff --git a/textures/Editor/MirrorButton.png b/textures/Editor/MirrorButton.png new file mode 100644 index 0000000..f4d9224 Binary files /dev/null and b/textures/Editor/MirrorButton.png differ diff --git a/textures/Editor/PartButton.png b/textures/Editor/PartButton.png new file mode 100644 index 0000000..f68376b Binary files /dev/null and b/textures/Editor/PartButton.png differ diff --git a/textures/Editor/PartGroupHeader.png b/textures/Editor/PartGroupHeader.png new file mode 100644 index 0000000..aaaceac Binary files /dev/null and b/textures/Editor/PartGroupHeader.png differ diff --git a/textures/Editor/RotateButton.png b/textures/Editor/RotateButton.png new file mode 100644 index 0000000..8be8776 Binary files /dev/null and b/textures/Editor/RotateButton.png differ diff --git a/textures/Editor/ToolbarDark.png b/textures/Editor/ToolbarDark.png new file mode 100644 index 0000000..d263334 Binary files /dev/null and b/textures/Editor/ToolbarDark.png differ diff --git a/textures/Editor/ToolbarIconAddPart.png b/textures/Editor/ToolbarIconAddPart.png new file mode 100644 index 0000000..8d0dc51 Binary files /dev/null and b/textures/Editor/ToolbarIconAddPart.png differ diff --git a/textures/Editor/ToolbarIconMenu.png b/textures/Editor/ToolbarIconMenu.png new file mode 100644 index 0000000..a4fb140 Binary files /dev/null and b/textures/Editor/ToolbarIconMenu.png differ diff --git a/textures/Editor/ToolbarIconPlay.png b/textures/Editor/ToolbarIconPlay.png new file mode 100644 index 0000000..d78b5ce Binary files /dev/null and b/textures/Editor/ToolbarIconPlay.png differ diff --git a/textures/Editor/ToolbarIconStaging.png b/textures/Editor/ToolbarIconStaging.png new file mode 100644 index 0000000..ecb087d Binary files /dev/null and b/textures/Editor/ToolbarIconStaging.png differ diff --git a/textures/Editor/ToolbarIconZoom.png b/textures/Editor/ToolbarIconZoom.png new file mode 100644 index 0000000..d5aef46 Binary files /dev/null and b/textures/Editor/ToolbarIconZoom.png differ diff --git a/textures/Editor/ToolbarIconZoomIn.png b/textures/Editor/ToolbarIconZoomIn.png new file mode 100644 index 0000000..5ddbe90 Binary files /dev/null and b/textures/Editor/ToolbarIconZoomIn.png differ diff --git a/textures/Editor/ToolbarIconZoomOut.png b/textures/Editor/ToolbarIconZoomOut.png new file mode 100644 index 0000000..a051bf3 Binary files /dev/null and b/textures/Editor/ToolbarIconZoomOut.png differ diff --git a/textures/Editor/ToolbarLight.png b/textures/Editor/ToolbarLight.png new file mode 100644 index 0000000..05a89f1 Binary files /dev/null and b/textures/Editor/ToolbarLight.png differ diff --git a/textures/Editor/TrashCan.png b/textures/Editor/TrashCan.png new file mode 100644 index 0000000..5418e0c Binary files /dev/null and b/textures/Editor/TrashCan.png differ diff --git a/textures/runtime/background.png b/textures/runtime/background.png new file mode 100644 index 0000000..008474f Binary files /dev/null and b/textures/runtime/background.png differ diff --git a/textures/runtime/background_ka1.jpg b/textures/runtime/background_ka1.jpg new file mode 100644 index 0000000..7d1689a Binary files /dev/null and b/textures/runtime/background_ka1.jpg differ diff --git a/textures/runtime/background_ka2.jpg b/textures/runtime/background_ka2.jpg new file mode 100644 index 0000000..07feb27 Binary files /dev/null and b/textures/runtime/background_ka2.jpg differ