remove useless
This commit is contained in:
parent
1e342ce0a8
commit
0baf74492a
@ -15,7 +15,7 @@ import traceback
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import Callable, Dict, List, TYPE_CHECKING, Optional
|
from typing import Callable, Dict, List, TYPE_CHECKING, Optional, Type
|
||||||
|
|
||||||
# third function
|
# third function
|
||||||
import rtoml
|
import rtoml
|
||||||
@ -269,9 +269,9 @@ class ClientWindow(Window):
|
|||||||
try:
|
try:
|
||||||
pyglet.app.event_loop.run(1 / self.main_config['runtime']['fps'])
|
pyglet.app.event_loop.run(1 / self.main_config['runtime']['fps'])
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("==========client stop. KeyboardInterrupt info==========")
|
self.logger.warn("==========client stop. KeyboardInterrupt info==========")
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print("==========client stop. KeyboardInterrupt info end==========")
|
self.logger.warn("==========client stop. KeyboardInterrupt info end==========")
|
||||||
self.dispatch_event("on_close", 'input')
|
self.dispatch_event("on_close", 'input')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
@ -289,9 +289,12 @@ class ClientWindow(Window):
|
|||||||
client api
|
client api
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def add_sub_screen(self, title: str, sub_screen: type(BaseScreen)):
|
def add_sub_screen(self, title: str, sub_screen: Type[BaseScreen]):
|
||||||
self.screen_list[title] = sub_screen(self)
|
self.screen_list[title] = sub_screen(self)
|
||||||
|
|
||||||
|
def remove_sub_screen(self, title: str):
|
||||||
|
self.screen_list.pop(title)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
draws and some event
|
draws and some event
|
||||||
"""
|
"""
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
* -------------------------------
|
* -------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mod logger;
|
|
||||||
mod plugin;
|
mod plugin;
|
||||||
mod python;
|
mod python;
|
||||||
mod simulator;
|
mod simulator;
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
/*
|
|
||||||
* -------------------------------
|
|
||||||
* Difficult Rocket
|
|
||||||
* Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
|
||||||
* All rights reserved
|
|
||||||
* -------------------------------
|
|
||||||
*/
|
|
@ -12,7 +12,7 @@ import traceback
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from xml.etree.ElementTree import Element
|
from xml.etree.ElementTree import Element
|
||||||
from typing import List, TYPE_CHECKING, Union, Dict, Optional, Generator
|
from typing import List, TYPE_CHECKING, Union, Dict, Optional, Generator, Type
|
||||||
from defusedxml.ElementTree import parse
|
from defusedxml.ElementTree import parse
|
||||||
|
|
||||||
from pyglet.math import Vec4
|
from pyglet.math import Vec4
|
||||||
@ -99,14 +99,6 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.need_update_parts = False
|
self.need_update_parts = False
|
||||||
self.dx = 0
|
self.dx = 0
|
||||||
self.dy = 0
|
self.dy = 0
|
||||||
self.debug_line = Line(main_window.width / 2, main_window.height / 2,
|
|
||||||
main_window.width / 2, main_window.height / 2,
|
|
||||||
width=3, color=(200, 10, 200, 255))
|
|
||||||
self.debug_line.visible = SR1ShipRender_Option.debug_d_pos
|
|
||||||
self.debug_mouse_line = Line(main_window.width / 2, main_window.height / 2,
|
|
||||||
main_window.width / 2, main_window.height / 2,
|
|
||||||
width=3, color=(10, 200, 200, 255))
|
|
||||||
self.debug_mouse_line.visible = SR1ShipRender_Option.debug_mouse_pos
|
|
||||||
self.debug_mouse_delta_line = Line(main_window.width / 2, main_window.height / 2,
|
self.debug_mouse_delta_line = Line(main_window.width / 2, main_window.height / 2,
|
||||||
main_window.width / 2, main_window.height / 2,
|
main_window.width / 2, main_window.height / 2,
|
||||||
width=2, color=(200, 200, 10, 255))
|
width=2, color=(200, 200, 10, 255))
|
||||||
@ -114,9 +106,6 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.debug_d_pos_label = Label('debug label NODATA', font_name=Fonts.微软等宽无线,
|
self.debug_d_pos_label = Label('debug label NODATA', font_name=Fonts.微软等宽无线,
|
||||||
x=main_window.width / 2, y=main_window.height / 2)
|
x=main_window.width / 2, y=main_window.height / 2)
|
||||||
self.debug_d_pos_label.visible = SR1ShipRender_Option.debug_d_pos
|
self.debug_d_pos_label.visible = SR1ShipRender_Option.debug_d_pos
|
||||||
self.debug_mouse_label = Label('debug mouse_label NODATA', font_name=Fonts.微软等宽无线,
|
|
||||||
x=main_window.width / 2, y=main_window.height / 2)
|
|
||||||
self.debug_mouse_label.visible = SR1ShipRender_Option.debug_mouse_pos
|
|
||||||
self.textures: Union[SR1Textures, None] = None
|
self.textures: Union[SR1Textures, None] = None
|
||||||
# self.xml_name = 'configs/dock1.xml'
|
# self.xml_name = 'configs/dock1.xml'
|
||||||
# self.xml_doc: ElementTree = parse('configs/dock1.xml')
|
# self.xml_doc: ElementTree = parse('configs/dock1.xml')
|
||||||
@ -153,12 +142,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.xml_root = self.xml_doc.getroot()
|
self.xml_root = self.xml_doc.getroot()
|
||||||
self.xml_name = file_path
|
self.xml_name = file_path
|
||||||
if DR_mod_runtime.use_DR_rust:
|
if DR_mod_runtime.use_DR_rust:
|
||||||
try:
|
self.rust_ship = SR1Ship_rs(file_path, 'configs/PartList.xml', 'a_new_ship')
|
||||||
self.rust_ship = SR1Ship_rs(file_path, 'configs/PartList.xml', 'a_new_ship')
|
|
||||||
print(self.rust_ship.name)
|
|
||||||
print(self.rust_ship.img_pos)
|
|
||||||
except Exception:
|
|
||||||
traceback.print_exc()
|
|
||||||
logger.info(sr_tr().sr1.ship.xml.load_done())
|
logger.info(sr_tr().sr1.ship.xml.load_done())
|
||||||
logger.info(sr_tr().sr1.ship.xml.load_time().format(
|
logger.info(sr_tr().sr1.ship.xml.load_time().format(
|
||||||
(time.time_ns() - start_time) / 1000000000))
|
(time.time_ns() - start_time) / 1000000000))
|
||||||
@ -277,9 +261,6 @@ class SR1ShipRender(BaseScreen):
|
|||||||
def update_parts(self) -> bool:
|
def update_parts(self) -> bool:
|
||||||
if not self.rendered:
|
if not self.rendered:
|
||||||
return False
|
return False
|
||||||
self.debug_line.x2, self.debug_line.y2 = self.camera.dx + (
|
|
||||||
self.window_pointer.width / 2), self.camera.dy + (
|
|
||||||
self.window_pointer.height / 2)
|
|
||||||
self.debug_d_pos_label.text = f'x: {self.camera.dx} y: {self.camera.dy}'
|
self.debug_d_pos_label.text = f'x: {self.camera.dx} y: {self.camera.dy}'
|
||||||
self.debug_d_pos_label.position = self.camera.dx + (self.window_pointer.width / 2), self.camera.dy + (
|
self.debug_d_pos_label.position = self.camera.dx + (self.window_pointer.width / 2), self.camera.dy + (
|
||||||
self.window_pointer.height / 2) + 10, 0
|
self.window_pointer.height / 2) + 10, 0
|
||||||
@ -307,12 +288,6 @@ class SR1ShipRender(BaseScreen):
|
|||||||
|
|
||||||
self.debug_label.draw()
|
self.debug_label.draw()
|
||||||
|
|
||||||
if SR1ShipRender_Option.debug_d_pos:
|
|
||||||
self.debug_line.draw()
|
|
||||||
self.debug_d_pos_label.draw()
|
|
||||||
if SR1ShipRender_Option.debug_mouse_pos:
|
|
||||||
self.debug_mouse_line.draw()
|
|
||||||
self.debug_mouse_label.draw()
|
|
||||||
if SR1ShipRender_Option.debug_mouse_d_pos:
|
if SR1ShipRender_Option.debug_mouse_d_pos:
|
||||||
self.debug_mouse_delta_line.draw()
|
self.debug_mouse_delta_line.draw()
|
||||||
|
|
||||||
@ -320,11 +295,6 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.debug_label.y = height - 100
|
self.debug_label.y = height - 100
|
||||||
if not self.rendered:
|
if not self.rendered:
|
||||||
return
|
return
|
||||||
self.debug_line.x = width / 2
|
|
||||||
self.debug_line.y = height / 2
|
|
||||||
self.debug_mouse_line.x = width / 2
|
|
||||||
self.debug_mouse_line.y = height / 2
|
|
||||||
self.debug_mouse_delta_line.x = width / 2
|
|
||||||
self.debug_mouse_delta_line.y = height / 2
|
self.debug_mouse_delta_line.y = height / 2
|
||||||
self.update_parts()
|
self.update_parts()
|
||||||
|
|
||||||
@ -353,15 +323,11 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.camera.dx += mouse_dx_d
|
self.camera.dx += mouse_dx_d
|
||||||
self.camera.dy += mouse_dy_d
|
self.camera.dy += mouse_dy_d
|
||||||
|
|
||||||
self.debug_mouse_line.x2, self.debug_mouse_line.y2 = x, y
|
|
||||||
self.debug_mouse_delta_line.x2 = (mouse_dx - self.camera.dx) * (1 - (0.5 ** scroll_y)) + (
|
self.debug_mouse_delta_line.x2 = (mouse_dx - self.camera.dx) * (1 - (0.5 ** scroll_y)) + (
|
||||||
window.width / 2)
|
window.width / 2)
|
||||||
self.debug_mouse_delta_line.y2 = (mouse_dy - self.camera.dy) * (1 - (0.5 ** scroll_y)) + (
|
self.debug_mouse_delta_line.y2 = (mouse_dy - self.camera.dy) * (1 - (0.5 ** scroll_y)) + (
|
||||||
window.height / 2)
|
window.height / 2)
|
||||||
self.debug_mouse_label.text = f'x: {mouse_dx} y: {mouse_dy}'
|
|
||||||
self.debug_mouse_label.position = x, y + 10, 0
|
|
||||||
self.need_update_parts = True
|
self.need_update_parts = True
|
||||||
# self.update_parts()
|
|
||||||
|
|
||||||
def on_command(self, command: CommandText, window: "ClientWindow"):
|
def on_command(self, command: CommandText, window: "ClientWindow"):
|
||||||
if command.find('render'):
|
if command.find('render'):
|
||||||
@ -374,22 +340,10 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.need_draw = True
|
self.need_draw = True
|
||||||
print('应该渲染飞船的')
|
print('应该渲染飞船的')
|
||||||
elif command.find('debug'):
|
elif command.find('debug'):
|
||||||
if command.find('delta'):
|
if command.find('mouse'):
|
||||||
# SR1ShipRender_Option.debug_d_pos = not SR1ShipRender_Option.debug_mouse_d_pos
|
self.debug_mouse_delta_line.visible = not self.debug_mouse_delta_line.visible
|
||||||
self.debug_line.visible = not self.debug_line.visible
|
SR1ShipRender_Option.debug_mouse_d_pos = self.debug_mouse_delta_line.visible
|
||||||
self.debug_d_pos_label.visible = not self.debug_d_pos_label.visible
|
logger.debug(f'sr1 mouse {SR1ShipRender_Option.debug_mouse_d_pos}')
|
||||||
SR1ShipRender_Option.debug_d_pos = self.debug_line.visible
|
|
||||||
logger.debug('sr1 delta')
|
|
||||||
elif command.find('mouse'):
|
|
||||||
if command.find('delta'):
|
|
||||||
SR1ShipRender_Option.debug_mouse_pos = not SR1ShipRender_Option.debug_mouse_pos
|
|
||||||
self.debug_mouse_line.visible = SR1ShipRender_Option.debug_mouse_pos
|
|
||||||
self.debug_mouse_label.visible = SR1ShipRender_Option.debug_mouse_pos
|
|
||||||
logger.debug(f'sr1 mouse delta {SR1ShipRender_Option.debug_mouse_pos}')
|
|
||||||
else:
|
|
||||||
self.debug_mouse_delta_line.visible = not self.debug_mouse_delta_line.visible
|
|
||||||
SR1ShipRender_Option.debug_mouse_d_pos = self.debug_mouse_delta_line.visible
|
|
||||||
logger.debug(f'sr1 mouse {SR1ShipRender_Option.debug_mouse_d_pos}')
|
|
||||||
elif command.find('ship'):
|
elif command.find('ship'):
|
||||||
if self.rendered:
|
if self.rendered:
|
||||||
for index, sprite in self.parts_sprite.items():
|
for index, sprite in self.parts_sprite.items():
|
||||||
@ -398,17 +352,13 @@ class SR1ShipRender(BaseScreen):
|
|||||||
elif command.find('get_buf'):
|
elif command.find('get_buf'):
|
||||||
|
|
||||||
def screenshot(window):
|
def screenshot(window):
|
||||||
from libs.pyglet.gl import GLubyte, GL_RGBA, GL_UNSIGNED_BYTE, \
|
from pyglet.gl import GLubyte, GL_RGBA, GL_UNSIGNED_BYTE, \
|
||||||
glReadPixels
|
glReadPixels
|
||||||
import pyglet
|
import pyglet
|
||||||
|
|
||||||
width = window.width
|
|
||||||
height = window.height
|
|
||||||
format_str = "RGBA"
|
format_str = "RGBA"
|
||||||
|
buf = (GLubyte * (len(format_str) * window.width * window.height))()
|
||||||
buf = (GLubyte * (len(format_str) * width * height))()
|
glReadPixels(0, 0, window.width, window.height, GL_RGBA, GL_UNSIGNED_BYTE, buf)
|
||||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buf)
|
return pyglet.image.ImageData(window.width, window.height, format_str, buf)
|
||||||
return pyglet.image.ImageData(width, height, format_str, buf)
|
|
||||||
|
|
||||||
image_data = screenshot(self.window_pointer)
|
image_data = screenshot(self.window_pointer)
|
||||||
image_data.save('test.png')
|
image_data.save('test.png')
|
||||||
@ -422,7 +372,6 @@ class SR1ShipRender(BaseScreen):
|
|||||||
img_size = (img_box[2] - img_box[0] + 1000, img_box[3] - img_box[1] + 1000)
|
img_size = (img_box[2] - img_box[0] + 1000, img_box[3] - img_box[1] + 1000)
|
||||||
# 中心点是左上角坐标
|
# 中心点是左上角坐标
|
||||||
img_center = (abs(img_box[0]), abs(img_box[3]))
|
img_center = (abs(img_box[0]), abs(img_box[3]))
|
||||||
print(f"img_box: {img_box} img_size: {img_size} img_center: {img_center}")
|
|
||||||
try:
|
try:
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
Loading…
Reference in New Issue
Block a user