fix issue on command
This commit is contained in:
parent
3784a32184
commit
0fd7bcf0f5
@ -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
|
from typing import Callable, Dict, List, TYPE_CHECKING, Optional
|
||||||
|
|
||||||
# third function
|
# third function
|
||||||
import rtoml
|
import rtoml
|
||||||
@ -122,6 +122,17 @@ def pyglet_load_fonts_folder(folder) -> None:
|
|||||||
pyglet_load_fonts_folder(os.path.join(folder, obj))
|
pyglet_load_fonts_folder(os.path.join(folder, obj))
|
||||||
|
|
||||||
|
|
||||||
|
def _call_back(call_back: Callable) -> Callable:
|
||||||
|
def wrapper(func):
|
||||||
|
@functools.wraps(func)
|
||||||
|
def warp(self: "ClientWindow", *args, **kwargs):
|
||||||
|
result = func(self, *args, **kwargs)
|
||||||
|
call_back(self)
|
||||||
|
return result
|
||||||
|
return warp
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def _call_screen_after(func: Callable) -> Callable:
|
def _call_screen_after(func: Callable) -> Callable:
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def warped(self: "ClientWindow", *args, **kwargs):
|
def warped(self: "ClientWindow", *args, **kwargs):
|
||||||
@ -306,8 +317,13 @@ class ClientWindow(Window):
|
|||||||
self.on_command(command_text)
|
self.on_command(command_text)
|
||||||
self.input_box.value = ''
|
self.input_box.value = ''
|
||||||
|
|
||||||
|
def new_command(self):
|
||||||
|
self.game.console.new_command()
|
||||||
|
|
||||||
|
@_call_back(new_command)
|
||||||
@_call_screen_after
|
@_call_screen_after
|
||||||
def on_command(self, command: line.CommandText):
|
def on_command(self, command: line.CommandText):
|
||||||
|
command.text = command.text.rstrip('\n')
|
||||||
self.logger.info(tr().window.command.text().format(command))
|
self.logger.info(tr().window.command.text().format(command))
|
||||||
command.find('/')
|
command.find('/')
|
||||||
if command.find('stop'):
|
if command.find('stop'):
|
||||||
@ -335,8 +351,9 @@ class ClientWindow(Window):
|
|||||||
except LanguageNotFound:
|
except LanguageNotFound:
|
||||||
self.logger.info(tr().language_available().format(os.listdir('./configs/lang')))
|
self.logger.info(tr().language_available().format(os.listdir('./configs/lang')))
|
||||||
self.save_info()
|
self.save_info()
|
||||||
|
elif command.find('mods'):
|
||||||
# self.command_tree.parse(command.plain_command)
|
for mod in self.game.mod_module:
|
||||||
|
self.logger.info(f"mod: {mod.name} id: {mod.mod_id} version: {mod.version}")
|
||||||
|
|
||||||
@_call_screen_after
|
@_call_screen_after
|
||||||
def on_message(self, message: line.CommandText):
|
def on_message(self, message: line.CommandText):
|
||||||
|
@ -65,6 +65,9 @@ class Console(Options):
|
|||||||
def get_command(self) -> Optional[str]:
|
def get_command(self) -> Optional[str]:
|
||||||
return self.caches.pop(0) if self.caches else None
|
return self.caches.pop(0) if self.caches else None
|
||||||
|
|
||||||
|
def new_command(self) -> None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Game(Options):
|
class Game(Options):
|
||||||
name = 'MainGame'
|
name = 'MainGame'
|
||||||
|
@ -7,8 +7,8 @@ fonts_folder = "libs/fonts"
|
|||||||
|
|
||||||
[window]
|
[window]
|
||||||
style = "None"
|
style = "None"
|
||||||
width = 2175
|
width = 1094
|
||||||
height = 1808
|
height = 1173
|
||||||
visible = true
|
visible = true
|
||||||
gui_scale = 1
|
gui_scale = 1
|
||||||
caption = "Difficult Rocket v{DR_version}"
|
caption = "Difficult Rocket v{DR_version}"
|
||||||
|
@ -128,3 +128,4 @@ if TYPE_CHECKING:
|
|||||||
def start(self) -> None: ...
|
def start(self) -> None: ...
|
||||||
def stop(self) -> bool: ...
|
def stop(self) -> bool: ...
|
||||||
def get_command(self) -> Optional[str]: ...
|
def get_command(self) -> Optional[str]: ...
|
||||||
|
def new_command(self) -> bool: ...
|
||||||
|
@ -228,6 +228,7 @@ pub mod translate {
|
|||||||
|
|
||||||
pub mod console {
|
pub mod console {
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
#[pyo3(name = "Console_rs")]
|
#[pyo3(name = "Console_rs")]
|
||||||
@ -251,7 +252,7 @@ pub mod console {
|
|||||||
let (stop_sender, stop_receiver) = std::sync::mpsc::channel();
|
let (stop_sender, stop_receiver) = std::sync::mpsc::channel();
|
||||||
let (keyboard_input_sender, keyboard_input_receiver) = std::sync::mpsc::channel();
|
let (keyboard_input_sender, keyboard_input_receiver) = std::sync::mpsc::channel();
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let std_in = std::io::stdin();
|
let std_in = io::stdin();
|
||||||
loop {
|
loop {
|
||||||
if let Ok(()) = stop_receiver.try_recv() {
|
if let Ok(()) = stop_receiver.try_recv() {
|
||||||
break;
|
break;
|
||||||
@ -261,9 +262,10 @@ pub mod console {
|
|||||||
if !input.is_empty() {
|
if !input.is_empty() {
|
||||||
keyboard_input_sender.send(input).unwrap();
|
keyboard_input_sender.send(input).unwrap();
|
||||||
}
|
}
|
||||||
print!(">>");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
print!("rs>");
|
||||||
|
io::stdout().flush().unwrap();
|
||||||
self.stop_sender = Some(stop_sender);
|
self.stop_sender = Some(stop_sender);
|
||||||
self.keyboard_input_receiver = Some(keyboard_input_receiver);
|
self.keyboard_input_receiver = Some(keyboard_input_receiver);
|
||||||
}
|
}
|
||||||
@ -276,6 +278,12 @@ pub mod console {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn new_command(&self) -> bool {
|
||||||
|
print!("rs>");
|
||||||
|
io::stdout().flush().unwrap();
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn get_command(&self) -> Option<String> {
|
fn get_command(&self) -> Option<String> {
|
||||||
// 获取输入
|
// 获取输入
|
||||||
if let Some(receiver) = &self.keyboard_input_receiver {
|
if let Some(receiver) = &self.keyboard_input_receiver {
|
||||||
|
@ -22,3 +22,6 @@ class RustConsole(Console):
|
|||||||
|
|
||||||
def get_command(self) -> str:
|
def get_command(self) -> str:
|
||||||
return self.console.get_command()
|
return self.console.get_command()
|
||||||
|
|
||||||
|
def new_command(self) -> None:
|
||||||
|
self.console.new_command()
|
||||||
|
Loading…
Reference in New Issue
Block a user