reee DEMO 1%!

This commit is contained in:
沈瑗杰 2021-02-22 21:32:13 +08:00
parent 07735dc30f
commit 2a6b1507f3
29 changed files with 197 additions and 20 deletions

View File

@ -75,10 +75,12 @@ class window(pyglet.window.Window):
self.view = 'space' self.view = 'space'
self.net_mode = net_mode self.net_mode = net_mode
# FPS # FPS
self.max_fps = self.FPS self.max_fps = [self.FPS, time.time()]
self.min_fps = self.FPS self.min_fps = [self.FPS, time.time()]
self.fps_wait = 5
# lang
self.lang = tools.config('sys_value/lang/%s.json5' % language, 'client')
# configs # configs
self.lang = tools.config('sys_value/lang/%s.json5' % language)
self.view = tools.config('configs/view.json5') self.view = tools.config('configs/view.json5')
self.map_view = [configs.basic_poi(poi_type='chunk')] self.map_view = [configs.basic_poi(poi_type='chunk')]
self.part_list = tools.config('sys_value/parts.json5') 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.label_batch = pyglet.graphics.Batch()
self.runtime_batch = pyglet.graphics.Batch() self.runtime_batch = pyglet.graphics.Batch()
# window # window
self.logger.info('client setup done!') self.logger.info('%s' % self.lang['setup.done'])
self.textures = {} self.textures = {}
# setup # setup
self.setup() self.setup()
@ -108,6 +110,9 @@ class window(pyglet.window.Window):
path = parts[part][2][0] path = parts[part][2][0]
part_image = image.load('textures/' + path) part_image = image.load('textures/' + path)
self.textures['part'][part] = part_image self.textures['part'][part] = part_image
pyglet.resource.path = ['textures']
pyglet.resource.reindex()
self.trash_can = pyglet.resource.image('Editor/TrashCan.png')
# tests # tests
self.info_label = pyglet.text.Label(text='test %s' % pyglet.clock.get_fps(), self.info_label = pyglet.text.Label(text='test %s' % pyglet.clock.get_fps(),
@ -118,26 +123,34 @@ class window(pyglet.window.Window):
# draws # draws
def update(self, ree): def update(self, ree):
self.FPS_update()
def FPS_update(self):
now_FPS = pyglet.clock.get_fps() now_FPS = pyglet.clock.get_fps()
if now_FPS > self.max_fps: if now_FPS > self.max_fps[0]:
self.max_fps = now_FPS self.max_fps = [now_FPS, time.time()]
elif now_FPS < self.min_fps: elif now_FPS < self.min_fps[0]:
self.min_fps = now_FPS self.min_fps = [now_FPS, time.time()]
self.info_label.text = 'now FPS: %03d \n max FPS: %02d \n min FPS: %02d' % (now_FPS, self.max_fps, self.min_fps) else:
self.info_label.anchor_x = 'left' if (time.time() - self.max_fps[1]) > self.fps_wait:
self.info_label.anchor_y = 'top' 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): def on_draw(self):
self.clear()
self.build_draw()
self.draw_batch() self.draw_batch()
def draw_batch(self): def draw_batch(self):
self.clear()
self.part_batch.draw() self.part_batch.draw()
self.runtime_batch.draw() self.runtime_batch.draw()
self.label_batch.draw() self.label_batch.draw()
def build_draw(self): def build_draw(self):
pass self.trash_can.blit(x=self.width - 90, y=self.height - 90)
def space_draw(self): def space_draw(self):
# render parts # render parts

View File

@ -39,8 +39,7 @@ class Game:
# lang_config # lang_config
self.language = tools.config('sys_value/basic_config.json5') self.language = tools.config('sys_value/basic_config.json5')
self.language = self.language['language'] self.language = self.language['language']
self.lang = tools.config('sys_value/lang/%s.json5' % self.language) self.lang = tools.config('sys_value/lang/%s.json5' % self.language, 'main')
self.lang = self.lang['main']
# logger # logger
self.log_config = tools.config('configs/logging.json5', 'file') self.log_config = tools.config('configs/logging.json5', 'file')
self.log_filename = configs.name_handler(self.log_config['filename']['main'], self.log_filename = configs.name_handler(self.log_config['filename']['main'],

View File

@ -1,10 +1,16 @@
''' """
writen by shenjackyuanjie writen by shenjackyuanjie
mail: 3695888@qq.com mail: 3695888@qq.com
''' """
import os
import multiprocessing as mp import multiprocessing as mp
try:
from bin import tools
except (ModuleNotFoundError, ImportError, ImportWarning):
import tools
class server(mp.Process): class server(mp.Process):
def __init__(self, dev_list, dev_dic, logger, language='zh-cn', net_mode='local'): def __init__(self, dev_list, dev_dic, logger, language='zh-cn', net_mode='local'):
@ -15,10 +21,13 @@ class server(mp.Process):
# value # value
self.process_id = 'Server' self.process_id = 'Server'
self.process_name = 'server process' self.process_name = 'server process'
self.process_pid = os.getpid()
# lang
self.lang = tools.config('sys_value/lang/%s.json5' % language, 'server')
# share memory # share memory
self.dev_list = dev_list self.dev_list = dev_list
self.dev_dic = dev_dic self.dev_dic = dev_dic
self.logger.info('server setup done!') self.logger.info('%s' % self.lang['setup.done'])
def run(self): def run(self):
pass pass

View File

@ -212,7 +212,7 @@ def config(file_name, stack=None):
try: try:
xml_load = parse(file_name) xml_load = parse(file_name)
except FileNotFoundError as exp: 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) file_name, stack)
tools_logger.exception(log) tools_logger.exception(log)
raise FileNotFoundError(log) raise FileNotFoundError(log)

View File

@ -39,7 +39,7 @@ def cut_and_save(config, save_path):
print(exp) print(exp)
for config_ in configs['images']: for config_ in configs['images']:
config__ = configs['images'][config_] 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] x, y, w, h, t = config__[0], config__[1], config__[2], config__[3], config__[4]
crop_box = [x, y, x + w, y + h] crop_box = [x, y, x + w, y + h]
pic_ = pic.crop(crop_box) pic_ = pic.crop(crop_box)
@ -53,3 +53,4 @@ def All_in_one_cut(xml, path):
json_name = xml[:-4] + '.json5' json_name = xml[:-4] + '.json5'
rewrite_config(xml, json_name) rewrite_config(xml, json_name)
cut_and_save(json_name, path) cut_and_save(json_name, path)

View File

@ -9,5 +9,11 @@
'logger.logfile_fmt': '日志文件记录格式:', 'logger.logfile_fmt': '日志文件记录格式:',
'logger.logfile_datefmt': '日志文件日期格式:', 'logger.logfile_datefmt': '日志文件日期格式:',
'game_start.at': '游戏主线程开始于:' 'game_start.at': '游戏主线程开始于:'
},
'client': {
'setup.done': '客户端载入完成'
},
'server': {
'setup.done': '服务端载入完成'
} }
} }

18
tests/test_image.py Normal file
View File

@ -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()

131
textures/Editor.json5 Normal file
View File

@ -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
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 932 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 775 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1004 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB