终于搞完后台和logging了

开始写前端
This commit is contained in:
沈瑗杰 2021-02-16 22:28:13 +08:00
parent 2d2a8284de
commit 0e999409b5
5 changed files with 451 additions and 36 deletions

View File

@ -20,17 +20,8 @@ except (ModuleNotFoundError, ImportError, ImportWarning):
import tools
class client(mp.Process, pyglet.window.Window):
def __init__(self, logger, dev_dic=None, dev_list=None, path=None, net_mode='local'):
"""
:param path: 运行路径
:param dev_list: 共享内存
:param dev_dic: 共享内存
:param logger: logger
:param net_mode: 网络模式 # local / ip
"""
# do father class __init__()
class client(mp.Process):
def __init__(self, logger, dev_dic=None, dev_list=None, net_mode='local'):
mp.Process.__init__(self)
# logging
self.logger = logger
@ -42,37 +33,61 @@ class client(mp.Process, pyglet.window.Window):
self.process_name = 'Client process'
self.view = 'space'
self.net_mode = net_mode
# image
# configs
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')
self.window_config = tools.config('sys_value/window.json5')
# dic
self.ships = {} # all ship(part)
self.planet_system = tools.config('sys_value/planet.json5') # hole planet system
# list
# re stuff
# window
self.window = Window(width=int(self.window_config['width']),
self.window = window(logger=logger,
dev_dic=dev_dic,
dev_list=dev_list,
net_mode=net_mode,
width=int(self.window_config['width']),
height=int(self.window_config['height']),
fullscreen=tools.c_b(self.window_config['full_screen']),
caption=str(self.window_config['caption']),
visible=tools.c_b(self.window_config['visible']))
def start(self) -> None:
pyglet.app.run()
class window(pyglet.window.Window):
def __init__(self, logger, dev_dic=None, dev_list=None, net_mode='local', *args, **kwargs):
super(window, self).__init__(*args, **kwargs)
"""
:param dev_list: 共享内存
:param dev_dic: 共享内存
:param logger: logger
:param net_mode: 网络模式 # local / ip
"""
# logging
self.logger = logger
# share memory
self.dev_list = dev_list
self.dev_dic = dev_dic
# value
self.process_id = 'Client'
self.process_name = 'Client process'
self.view = 'space'
self.net_mode = net_mode
# configs
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')
# dic
self.ships = {} # all ship(part)
self.planet_system = tools.config('sys_value/planet.json5')
# hole planet system
# list
# re stuff
# window
self.logger.info('client setup done!')
self.textures = {}
# setup
self.setup()
def start_game(self):
pyglet.app.run()
return
def setup(self):
# net_mode
if self.net_mode == 'local':
pass
# textures
self.textures = {}
# parts
self.textures['part'] = {}
parts = tools.config('sys_value/parts.json5')
@ -85,7 +100,7 @@ class client(mp.Process, pyglet.window.Window):
# draws
def on_draw(self):
print('rua!')
return
def build_draw(self):
pass
@ -99,13 +114,19 @@ class client(mp.Process, pyglet.window.Window):
for part in ship:
pass
'''
def draw_label(self):
pass
"""
keyboard and mouse input
'''
"""
def on_mouse_motion(self, x, y, dx, dy):
pass
def on_mouse_press(self, x, y, button, modifiers):
pass
def on_key_press(self, symbol, modifiers):
pass

View File

@ -8,6 +8,7 @@ from multiprocessing import Manager as share
import sys
import time
import pyglet
import logging
try:
@ -83,4 +84,4 @@ class Game:
def start(self):
# start
self.client.start_game()
self.client.start()

View File

@ -221,3 +221,24 @@ def config(file_name, stack=None):
return xml_get
else:
return xml_load
def get_At(name, in_xml, need_type=str):
name_type = type(name)
if name_type == list:
At_list = []
for need_name in name:
if in_xml.hasAttribute(need_name):
get = in_xml.getAttribute(need_name)
At_list.append(need_type(get))
else:
continue
return At_list
elif name_type == str:
if in_xml.hasAttribute(name):
At = in_xml.getAttribute(name)
else:
return None
else:
raise TypeError('only str and list type is ok but you give me a' + name_type + 'type')
return need_type(At)

View File

@ -1,8 +1,35 @@
'''
"""
writen by shenjackyuanjie
mail: 3695888@qq.com
'''
"""
from xml.dom.minidom import parse
try:
from bin import tools
except (ModuleNotFoundError, ImportError, ImportWarning):
import tools
import json5
from pprint import pprint
from pyglet import image
def rewrite_config(name, save_name):
load_xml = tools.config(name)
load_xml = load_xml.documentElement
sprites = load_xml.getElementsByTagName('sprite')
pic_path = load_xml.getAttribute('imagePath')
poise = {'image_name': pic_path}
for sprite in sprites:
poi = tools.get_At(['x', 'y', 'w', 'h'], sprite, int)
poi.append(tools.get_At('r', sprite, str))
poise[tools.get_At('n', sprite, str)] = poi
with open(save_name, 'w') as file:
json5.dump(poise, file)
def cut_and_save(config):
with open(config, 'r') as cut:
cuts = json5.load(cut)
main = image.load()
rewrite_config('textures/Runtime.xml', 'textures/Runtime.json5')

345
textures/Runtime.json5 Normal file
View File

@ -0,0 +1,345 @@
{
"ActionButton.png": [
178,
349,
119,
46,
null
],
"ActionButtonSelected.png": [
182,
210,
46,
119,
"y"
],
"AltimeterControl.PNG": [
182,
132,
153,
76,
null
],
"Button.png": [
413,
138,
80,
80,
null
],
"ButtonIconActivateStage.png": [
110,
2,
35,
45,
null
],
"ButtonIconMapView.png": [
410,
220,
54,
54,
null
],
"ButtonIconMenu.png": [
110,
49,
35,
43,
"y"
],
"ButtonPressed.png": [
148,
404,
80,
80,
null
],
"FastForward.png": [
151,
282,
26,
38,
"y"
],
"ForwardButton.png": [
413,
70,
87,
66,
null
],
"ForwardButtonBottomBar.PNG": [
503,
2,
3,
102,
"y"
],
"ForwardButtonPressed.png": [
414,
2,
87,
66,
null
],
"ForwardButtonTopBar.png": [
2,
411,
6,
95,
"y"
],
"FuelDrainIcon.png": [
230,
318,
25,
26,
null
],
"FuelFillIcon.png": [
151,
322,
26,
25,
"y"
],
"MarkerApoapsis.png": [
338,
313,
43,
54,
null
],
"MarkerClosest.png": [
390,
276,
54,
43,
"y"
],
"MarkerEncounter.png": [
466,
220,
43,
54,
null
],
"MarkerPeriapsis.png": [
334,
268,
54,
43,
"y"
],
"PathSegment.png": [
83,
502,
4,
7,
"y"
],
"PlayButton.png": [
230,
210,
23,
26,
null
],
"RotateButton.png": [
337,
161,
71,
105,
"y"
],
"RotateButtonPressed.png": [
340,
54,
71,
105,
"y"
],
"SmokeParticle.PNG": [
148,
2,
32,
32,
null
],
"StageControlBottom.PNG": [
10,
411,
136,
89,
"y"
],
"StageControlStretch.PNG": [
10,
502,
71,
8,
null
],
"StageControlTop.PNG": [
182,
486,
71,
24,
null
],
"SteerButton.png": [
255,
397,
77,
106,
"y"
],
"SteerButtonPressed.png": [
255,
210,
77,
106,
"y"
],
"StopButton.png": [
257,
318,
25,
25,
null
],
"ThrottleControl.png": [
2,
2,
106,
407,
null
],
"ThrottleLevel1.png": [
151,
259,
27,
21,
"y"
],
"ThrottleLevel10.png": [
151,
349,
25,
48,
"y"
],
"ThrottleLevel2.png": [
110,
123,
28,
25,
"y"
],
"ThrottleLevel3.png": [
148,
201,
28,
27,
null
],
"ThrottleLevel4.png": [
148,
36,
31,
28,
null
],
"ThrottleLevel5.png": [
110,
94,
35,
27,
null
],
"ThrottleLevel6.png": [
148,
161,
28,
38,
"y"
],
"ThrottleLevel7.png": [
139,
230,
41,
27,
null
],
"ThrottleLevel8.png": [
148,
115,
28,
44,
"y"
],
"ThrottleLevel9.png": [
110,
214,
27,
48,
"y"
],
"TimeControl.PNG": [
110,
264,
39,
138,
"y"
],
"ToolbarSide.PNG": [
182,
54,
156,
76,
null
],
"ToolbarStretch.PNG": [
138,
502,
42,
4,
"y"
],
"UnlockHeading.png": [
182,
2,
230,
50,
null
],
"WarpBarSide.PNG": [
148,
66,
30,
47,
null
],
"WarpBarStretch.png": [
89,
502,
47,
6,
"y"
],
"WarpButton.png": [
110,
150,
27,
62,
"y"
],
"WarpSpeedButton.png": [
299,
318,
37,
62,
"y"
]
}