Skip to content

Commit

Permalink
feat: better design
Browse files Browse the repository at this point in the history
  • Loading branch information
Googlefan256 committed Oct 28, 2023
1 parent 2a54af9 commit cd3412b
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 38 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added assets/clock/electric.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/electric_locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/fire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/fire_locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/grass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/grass_locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/ice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/ice_locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/rock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/rock_locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/water.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/water_locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/wind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/clock/wind_locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion bin/bot/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,11 @@ pub fn create_components(
let format = CreateActionRow::SelectMenu(format);
let button = CreateActionRow::Buttons(vec![
CreateButton::new_link(format!("https://enka.network/u/{}", uid)).label("Enka Network"),
CreateButton::new_link(format!("https://ag.neody.land/generate?uid={}", uid))
.label(t!(locale, "main:general.webapp")),
/*CreateButton::new("end")
.style(ButtonStyle::Danger)
.label("終了"),*/
.label(t!(locale, "main:general.close")),*/
]);
vec![chara, score, format, button]
}
22 changes: 10 additions & 12 deletions bin/bot/src/events/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,17 @@ pub async fn handler(
}
select_menu.edit_response(&ctx.http, builder).await?;
}
/* if custom_id == "end" {
let e = select_menu.message.embeds.first();
if e.is_none() {
return Ok(());
/*if custom_id == "end" {
let msg = &select_menu.message;
if let Some(e) = msg.embeds.first() {
let e = CreateEmbed::from(e.to_owned());
let res = CreateInteractionResponseMessage::new()
.embed(e)
.components(vec![])
.files(vec![]);
let res = CreateInteractionResponse::UpdateMessage(res);
select_menu.create_response(&ctx.http, res).await?;
}
let e = e.unwrap();
let e = CreateEmbed::from(e.to_owned());
let res = CreateInteractionResponseMessage::new()
.embed(e)
.components(vec![])
.files(vec![]);
let res = CreateInteractionResponse::UpdateMessage(res);
select_menu.create_response(&ctx.http, res).await?;
}*/
}
_ => {}
Expand Down
3 changes: 2 additions & 1 deletion lib/gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ serde_json = { workspace = true }
serde = { workspace = true }
image = "0.24.7"
rusttype = "0.9.3"
imageproc = "0.23.0"
imageproc = "0.23.0"
tokio = { version = "1.33.0", features = ["rt", "macros", "fs"] }
35 changes: 35 additions & 0 deletions lib/gen/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,38 @@ pub fn get_scores_for_part(part: Option<ReliquaryType>) -> Scores {
},
}
}
const ELECTRIC: &[u8; 6968] = include_bytes!("../../../assets/clock/electric.png");
const ELECTRIC_LOCKED: &[u8; 7797] = include_bytes!("../../../assets/clock/electric_locked.png");
const FIRE: &[u8; 6599] = include_bytes!("../../../assets/clock/fire.png");
const FIRE_LOCKED: &[u8; 7447] = include_bytes!("../../../assets/clock/fire_locked.png");
const GRASS: &[u8; 6941] = include_bytes!("../../../assets/clock/grass.png");
const GRASS_LOCKED: &[u8; 7591] = include_bytes!("../../../assets/clock/grass_locked.png");
const ICE: &[u8; 6953] = include_bytes!("../../../assets/clock/ice.png");
const ICE_LOCKED: &[u8; 7761] = include_bytes!("../../../assets/clock/ice_locked.png");
const ROCK: &[u8; 6898] = include_bytes!("../../../assets/clock/rock.png");
const ROCK_LOCKED: &[u8; 7627] = include_bytes!("../../../assets/clock/rock_locked.png");
const WATER: &[u8; 6726] = include_bytes!("../../../assets/clock/water.png");
const WATER_LOCKED: &[u8; 7544] = include_bytes!("../../../assets/clock/water_locked.png");
const WIND: &[u8; 6071] = include_bytes!("../../../assets/clock/wind.png");
const WIND_LOCKED: &[u8; 7737] = include_bytes!("../../../assets/clock/wind_locked.png");

pub fn get_clock_image(f: impl AsRef<str>, locked: bool) -> Option<DynamicImage> {
image::load_from_memory(match (f.as_ref().to_lowercase(), locked) {
(f, true) if f == "electric" || f == "elec" => ELECTRIC_LOCKED,
(f, true) if f == "fire" => FIRE_LOCKED,
(f, true) if f == "grass" => GRASS_LOCKED,
(f, true) if f == "ice" => ICE_LOCKED,
(f, true) if f == "rock" => ROCK_LOCKED,
(f, true) if f == "water" => WATER_LOCKED,
(f, true) if f == "wind" => WIND_LOCKED,
(f, false) if f == "electric" || f == "elec" => ELECTRIC,
(f, false) if f == "fire" => FIRE,
(f, false) if f == "grass" => GRASS,
(f, false) if f == "ice" => ICE,
(f, false) if f == "rock" => ROCK,
(f, false) if f == "water" => WATER,
(f, false) if f == "wind" => WIND,
_ => return None,
})
.ok()
}
33 changes: 9 additions & 24 deletions lib/gen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use crate::default::get_default;
use serde::Deserialize;

use crate::{
constants::{self, FONT},
constants::{self, get_clock_image, FONT},
dupe, locale,
};

Expand Down Expand Up @@ -242,30 +242,15 @@ pub async fn generate(
let clocks = data.talents();
let mut clock_y = 100;
for clock in clocks {
let img = clock.image(api).await.ok()?;
let mut img = img.into_rgba8();
let mut base_img = DynamicImage::new_rgba8(60, 60).into_rgba8();
if let Some(c) = icons.image("Const.svg", 5.0) {
image::imageops::overlay(&mut base_img, &c, 0, 0);
let locked_image = get_clock_image(data.element.fight_prop_name(), !clock.is_unlock())?;
let mut locked_image = resize(&locked_image, 70, 70, image::imageops::Triangle);
if clock.is_unlock() {
let img = clock.image(api).await.ok()?;
let img = img.into_rgba8();
let img = resize(&img, 35, 35, image::imageops::Triangle);
image::imageops::overlay(&mut locked_image, &img, 16, 15);
}
let unique_color = data.element.color_rgb();
if !clock.is_unlock() {
for p in img.pixels_mut() {
p.0 = [100, 100, 100, p.0[3]];
}
} else {
for p in img.pixels_mut() {
if p.0[0] == 255 && p.0[1] == 255 && p.0[2] == 255 {
p.0 = [255, 255, 255, p.0[3]];
p[0] = unique_color[0];
p[1] = unique_color[1];
p[2] = unique_color[2];
}
}
}
let img = resize(&img, 40, 40, image::imageops::Triangle);
image::imageops::overlay(&mut base_img, &img, 15, 15);
image::imageops::overlay(&mut image, &base_img, 680, clock_y as i64);
image::imageops::overlay(&mut image, &locked_image, 680, clock_y as i64);
clock_y += 80;
}

Expand Down
20 changes: 20 additions & 0 deletions lib/gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use enka_api::{api::Api, character::CharacterId};
use gen::gen::{generate, ImageFormat, Lang, ScoreCounter};
use tokio::fs::write;

const UID: i32 = 827106332;

#[tokio::main(flavor = "current_thread")]
async fn main() {
let api = Api::new();
let icons = api.icon_data();
let (user, _cached) = api.simple(UID).await.unwrap();
let character = user.character(CharacterId(10000031)).unwrap();
let format = ImageFormat::Png;
let counter = ScoreCounter::Hp;
let raw_lang = Lang::Ja;
let res = generate(character.clone(), &api, &raw_lang, &icons, counter, format)
.await
.unwrap();
write("test.png", res).await.unwrap();
}
2 changes: 2 additions & 0 deletions localization/en-US/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"general.linked": "Successfully linked your UID.",
"general.parseFailed": "Failed to parse data.",
"general.generated": "Stats of {{name}}",
"general.webapp": "Web Version",
"general.close": "Close",
"calculationMethod.attack": "ATK Calculation",
"calculationMethod.defense": "DEF Calculation",
"calculationMethod.hp": "HP Calculation",
Expand Down
2 changes: 2 additions & 0 deletions localization/ja/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"general.linked": "ユーザーidをリンクしました。",
"general.parseFailed": "解析に失敗しました。",
"general.generated": "{{name}}のステータス",
"general.webapp": "Web版",
"general.close": "閉じる",
"calculationMethod.attack": "攻撃型",
"calculationMethod.defense": "防御型",
"calculationMethod.hp": "HP型",
Expand Down

0 comments on commit cd3412b

Please sign in to comment.