master
Bel LaPointe 2023-03-23 16:05:02 -06:00
parent 37e268a47f
commit d9bf3e5c90
3 changed files with 45 additions and 13 deletions

View File

@ -26,12 +26,27 @@ pub struct Engine {
pub kafka: Option<Kafka>,
pub device: Option<Device>,
pub udp: Option<UDP>,
pub gui: Option<GUI>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Device {
}
#[derive(Serialize, Deserialize, Debug)]
pub struct GUI {
pub up: String,
pub down: String,
pub left: String,
pub right: String,
pub a: String,
pub b: String,
pub x: String,
pub y: String,
pub l: String,
pub r: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Kafka {
pub addr: String,
@ -75,6 +90,18 @@ fn build_config_std() -> Config {
engine: Engine{
name: env::var("INPUT_NAME").unwrap_or(String::from("stdin")),
kafka: None,
gui: Some(GUI{
up: env::var("INPUT_GUI_BUTTON_UP").unwrap_or(String::from("up")),
down: env::var("INPUT_GUI_BUTTON_DOWN").unwrap_or(String::from("down")),
left: env::var("INPUT_GUI_BUTTON_LEFT").unwrap_or(String::from("left")),
right: env::var("INPUT_GUI_BUTTON_RIGHT").unwrap_or(String::from("right")),
a: env::var("INPUT_GUI_BUTTON_A").unwrap_or(String::from("a")),
b: env::var("INPUT_GUI_BUTTON_B").unwrap_or(String::from("b")),
x: env::var("INPUT_GUI_BUTTON_X").unwrap_or(String::from("x")),
y: env::var("INPUT_GUI_BUTTON_Y").unwrap_or(String::from("y")),
l: env::var("INPUT_GUI_BUTTON_L").unwrap_or(String::from("l")),
r: env::var("INPUT_GUI_BUTTON_R").unwrap_or(String::from("r")),
}),
device: None,
udp: Some(UDP{
host: Some(env::var("INPUT_UDP_HOST").unwrap_or(String::from("localhost"))),
@ -90,6 +117,7 @@ fn build_config_std() -> Config {
engine: Engine{
name: env::var("OUTPUT_NAME").unwrap_or(String::from("stdout")),
kafka: None,
gui: None,
device: None,
udp: Some(UDP{
host: Some(env::var("OUTPUT_UDP_HOST").unwrap_or(String::from("localhost"))),

View File

@ -6,12 +6,14 @@ use iced::subscription;
use iced::{Alignment, Element, Application, Settings, Subscription, Theme, Command};
use crate::stream::OutputStream;
use crate::config::GUI;
pub fn main(output_stream: Box<dyn OutputStream>) -> iced::Result {
pub fn main(cfg: GUI, output_stream: Box<dyn OutputStream>) -> iced::Result {
let def: iced::Settings<()> = Settings::default();
let settings = Settings{
flags: Flags {
output_stream: output_stream,
cfg: cfg,
},
antialiasing: def.antialiasing,
default_font: def.default_font,
@ -34,6 +36,7 @@ struct Main {
struct Flags {
output_stream: Box<dyn OutputStream>,
cfg: GUI,
}
struct Inputs {
@ -139,18 +142,19 @@ impl Application for Main {
modifiers: _,
..
}) => {
let nope = String::from("");
let s = match key_code {
_ if key_code == self.inputs.stick.up => String::from("up"),
_ if key_code == self.inputs.stick.down => String::from("down"),
_ if key_code == self.inputs.stick.left => String::from("left"),
_ if key_code == self.inputs.stick.right => String::from("right"),
_ if key_code == self.inputs.a => String::from("a"),
_ if key_code == self.inputs.b => String::from("b"),
_ if key_code == self.inputs.x => String::from("x"),
_ if key_code == self.inputs.y => String::from("y"),
_ if key_code == self.inputs.l => String::from("l"),
_ if key_code == self.inputs.r => String::from("r"),
_ => String::from(""),
_ if key_code == self.inputs.stick.up => &self.flags.cfg.up,
_ if key_code == self.inputs.stick.down => &self.flags.cfg.down,
_ if key_code == self.inputs.stick.left => &self.flags.cfg.left,
_ if key_code == self.inputs.stick.right => &self.flags.cfg.right,
_ if key_code == self.inputs.a => &self.flags.cfg.a,
_ if key_code == self.inputs.b => &self.flags.cfg.b,
_ if key_code == self.inputs.x => &self.flags.cfg.x,
_ if key_code == self.inputs.y => &self.flags.cfg.y,
_ if key_code == self.inputs.l => &self.flags.cfg.l,
_ if key_code == self.inputs.r => &self.flags.cfg.r,
_ => &nope,
};
if s.len() > 0 {
self.flags.output_stream.put(s.chars().collect());

View File

@ -6,7 +6,7 @@ fn main() {
let cfg = config::build_config().unwrap();
if cfg.streams.input.engine.name == "gui" {
let output_stream = stream::build_output_stream(&cfg.streams.output);
gui::main(output_stream).unwrap();
gui::main(cfg.streams.input.engine.gui.unwrap(), output_stream).unwrap();
} else {
main_cli(cfg);
}