Skip to content

Commit

Permalink
Included images in binary
Browse files Browse the repository at this point in the history
  • Loading branch information
arne-fuchs committed May 7, 2024
1 parent 1a9b6bb commit 43f583c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 63 deletions.
1 change: 0 additions & 1 deletion src/edcas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::edcas::backend::evm::edcas_contract::StationIdentity;
use crate::edcas::explorer::system::PlanetSignal;
use json::JsonValue;
use log::info;
use num_format::Locale::fo;

use crate::edcas::materials::MaterialState;
use crate::edcas::station::{Station, StationState};
Expand Down
23 changes: 2 additions & 21 deletions src/edcas/about.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
use eframe::egui::ColorImage;
//TODO remove egui dependency
pub struct About {
pub(crate) github_url: String,
pub(crate) logo: ColorImage,
pub(crate) discord_url: String
}

impl Default for About {
fn default() -> Self {
let mut logo_path = image::io::Reader::open("graphics\\logo\\edcas.png");
if cfg!(target_os = "linux") {
match image::io::Reader::open("/usr/share/edcas-client/graphics/logo/edcas.png") {
Ok(_) => {
logo_path =
image::io::Reader::open("/usr/share/edcas-client/graphics/logo/edcas.png");
}
Err(_) => {
logo_path = image::io::Reader::open("graphics/logo/edcas.png");
}
}
}
let image = logo_path.unwrap().decode().unwrap();
let size = [image.width() as _, image.height() as _];
let image_buffer = image.to_rgba8();
let pixels = image_buffer.as_flat_samples();
let color_image = ColorImage::from_rgba_unmultiplied(size, pixels.as_slice());
Self {
github_url: "https://github.com/arne-fuchs/edcas-client".to_owned(),
logo: color_image,
discord_url: "https://discord.gg/fsstTkAw".to_owned()
}
}
}
25 changes: 21 additions & 4 deletions src/edcas/backend/evm/journal_interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,14 @@ impl EvmInterpreter {
.timestamp()
.into(),
);
let _ = execute_send_repeatable(function_call).await;
match execute_send_repeatable(function_call).await {
Ok(receipt) => {
debug!("Call register_planet successfull {}-{}: {} - BlockNr.{:?}",system_address,body_id,receipt.transaction_hash,receipt.block_number);
}
Err(error) => {
debug!("Call register_planet failed {}-{}: {}",system_address,body_id,error);
}
}
} else {
//Star
//{"AbsoluteMagnitude":8.518448,"Age_MY":446,"AxialTilt":0,"BodyID":0,"BodyName":"Hyades Sector BB-N b7-5",
Expand All @@ -148,6 +155,9 @@ impl EvmInterpreter {
// "SurfaceTemperature":3367.0,"SystemAddress":11666070513017,"WasDiscovered":true,"WasMapped":false,"event":"Scan","horizons":true,
// "odyssey":true,"timestamp":"2024-03-26T21:27:53Z"}
debug!("Call register_star");
let body_id = json["BodyID"].as_u8().unwrap();
let system_address =
json["SystemAddress"].as_u64().unwrap();
let function_call: FunctionCall<
Arc<
SignerMiddleware<
Expand All @@ -158,8 +168,8 @@ impl EvmInterpreter {
SignerMiddleware<Provider<Http>, Wallet<SigningKey>>,
(),
> = contract.register_star(
json["SystemAddress"].as_u64().unwrap(),
json["BodyID"].as_u8().unwrap(),
system_address,
body_id,
json["BodyName"].to_string(),
json["WasDiscovered"].as_bool().unwrap(),
json["WasMapped"].as_bool().unwrap(),
Expand All @@ -172,7 +182,14 @@ impl EvmInterpreter {
.timestamp()
.into(),
);
let _ = execute_send_repeatable(function_call).await;
match execute_send_repeatable(function_call).await {
Ok(receipt) => {
debug!("Call register_planet successfull {}-{}: {} - BlockNr.{:?}",system_address,body_id,receipt.transaction_hash,receipt.block_number);
}
Err(error) => {
debug!("Call register_planet failed {}-{}: {}",system_address,body_id,error);
}
}
}
} else {
//TODO Interpret Belt Cluster and Ring
Expand Down
2 changes: 1 addition & 1 deletion src/edcas/backend/evm/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl EvmUpdater {
let mut planet_list = vec![];

let mut timestamp: U256 = U256::max_value();
let mut index = 1;
let mut index = 0;
while index <= highest_id
|| (highest_id == 0 && timestamp != U256::from(0)) {
debug!("Call star_map: {system_address}-{index}");
Expand Down
23 changes: 1 addition & 22 deletions src/edcas/news.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
use eframe::egui::ColorImage;
use log::error;
use select::document::Document;
use select::predicate::{Attr, Name, Predicate};

pub struct News {
pub(crate) articles: Vec<Article>,
pub logo: ColorImage,
}

impl Default for News {
fn default() -> Self {
let mut logo_path = image::io::Reader::open("graphics\\logo\\edcas.png");
if cfg!(target_os = "linux") {
match image::io::Reader::open("/usr/share/edcas-client/graphics/logo/edcas.png") {
Ok(_) => {
logo_path =
image::io::Reader::open("/usr/share/edcas-client/graphics/logo/edcas.png");
}
Err(_) => {
logo_path = image::io::Reader::open("graphics/logo/edcas.png");
}
}
}
let image = logo_path.unwrap().decode().unwrap();
let size = [image.width() as _, image.height() as _];
let image_buffer = image.to_rgba8();
let pixels = image_buffer.as_flat_samples();
let color_image = ColorImage::from_rgba_unmultiplied(size, pixels.as_slice());

let articles = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
Expand Down Expand Up @@ -70,8 +50,7 @@ impl Default for News {
});

Self {
articles,
logo: color_image,
articles
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ mod station;
impl App for EliteRustClient {
fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) {
if !self.settings.appearance_settings.applied {
egui_extras::install_image_loaders(ctx);

let mut style: egui::Style = (*ctx.style()).clone();
for (text_style, font_id) in style.text_styles.iter_mut() {
match text_style {
Expand Down
14 changes: 7 additions & 7 deletions src/gui/about.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use eframe::egui::TextureHandle;
use eframe::egui::{include_image};
use eframe::{egui, App};

impl App for crate::edcas::about::About {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.vertical_centered(|ui| {
let texture: TextureHandle =
ui.ctx()
.load_texture("logo", self.logo.clone(), egui::TextureOptions::LINEAR);
let image = egui::Image::new(&texture).max_width(512.0).rounding(10.0);
ui.add(image);
ui.add(
egui::Image::new(include_image!("../../graphics/logo/edcas.png"))
.max_width(512.0)
.rounding(10.0),
);
ui.label("Discord:");
ui.hyperlink("https://discord.gg/fsstTkAw");
ui.hyperlink(&self.discord_url);
ui.end_row();
ui.label("Github:");
ui.hyperlink(&self.github_url);
Expand Down
12 changes: 6 additions & 6 deletions src/gui/news.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use eframe::egui::TextureHandle;
use eframe::egui::{include_image};
use eframe::{egui, App};

impl App for crate::edcas::news::News {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
egui::ScrollArea::vertical().show(ui, |ui| {
let texture: TextureHandle =
ui.ctx()
.load_texture("logo", self.logo.clone(), egui::TextureOptions::LINEAR);
let image = egui::Image::new(&texture).max_width(512.0).rounding(10.0);
ui.vertical_centered(|ui| {
ui.add(image);
ui.add(
egui::Image::new(include_image!("../../graphics/logo/edcas.png"))
.max_width(512.0)
.rounding(10.0),
);
ui.heading("Galnet News");
});

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn main() {
image = image::open("/usr/share/edcas-client/graphics/logo/edcas_128.png");
}
Err(_) => {
image = image::open("graphics/logo/edcas.png");
image = image::open("edcas/graphics/logo/edcas.png");
}
}
}
Expand Down

0 comments on commit 43f583c

Please sign in to comment.