implement card rendering with new card type and menu
This commit was merged in pull request #28.
This commit is contained in:
+187
-1
@@ -1,7 +1,10 @@
|
||||
use core::fmt::Display;
|
||||
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use num_enum::FromPrimitive;
|
||||
|
||||
use crate::card::decoder::{Events, decode_known_event, decode_packed_card_text, decode_secret};
|
||||
use embedded_graphics::pixelcolor::Rgb565;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct NfcPayload<'a> {
|
||||
@@ -29,6 +32,189 @@ pub enum CardType {
|
||||
Fairy = 7,
|
||||
}
|
||||
|
||||
impl Display for CardType {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match *self {
|
||||
CardType::Default => write!(f, "Default"),
|
||||
CardType::Blueprint => write!(f, "Blueprint"),
|
||||
CardType::CYBER => write!(f, "CYBER"),
|
||||
CardType::Nature => write!(f, "Nature"),
|
||||
CardType::Fossil => write!(f, "Fossil"),
|
||||
CardType::Ghost => write!(f, "Ghost"),
|
||||
CardType::Daemon => write!(f, "Daemon"),
|
||||
CardType::Fairy => write!(f, "Fairy"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type PrimaryColor = Rgb565;
|
||||
impl Into<PrimaryColor> for CardType {
|
||||
fn into(self) -> PrimaryColor {
|
||||
match self {
|
||||
CardType::Default => Rgb565::new(0xD8, 0x68, 0x30),
|
||||
CardType::Blueprint => Rgb565::new(0x6D, 0x81, 0xFF),
|
||||
CardType::CYBER => Rgb565::new(0xFF, 0xFF, 0x04),
|
||||
CardType::Nature => Rgb565::new(0x55, 0xA0, 0x58),
|
||||
CardType::Fossil => Rgb565::new(0xB9, 0x7A, 0x60),
|
||||
CardType::Ghost => Rgb565::new(0xAB, 0xAB, 0xAB),
|
||||
CardType::Daemon => Rgb565::new(0x60, 0x00, 0x88),
|
||||
CardType::Fairy => Rgb565::new(0xB0, 0xA9, 0xE4),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type Palette = [Rgb565; 16];
|
||||
impl Into<Palette> for CardType {
|
||||
fn into(self) -> Palette {
|
||||
match self {
|
||||
CardType::Default => [
|
||||
Rgb565::new(31, 23, 35),
|
||||
Rgb565::new(60, 47, 82),
|
||||
Rgb565::new(178, 39, 65),
|
||||
Rgb565::new(70, 86, 165),
|
||||
Rgb565::new(245, 70, 76),
|
||||
Rgb565::new(216, 104, 48),
|
||||
Rgb565::new(140, 127, 144),
|
||||
Rgb565::new(73, 149, 243),
|
||||
Rgb565::new(62, 197, 75),
|
||||
Rgb565::new(240, 149, 72),
|
||||
Rgb565::new(188, 176, 179),
|
||||
Rgb565::new(247, 156, 136),
|
||||
Rgb565::new(114, 222, 235),
|
||||
Rgb565::new(180, 230, 86),
|
||||
Rgb565::new(239, 208, 129),
|
||||
Rgb565::new(255, 255, 255),
|
||||
],
|
||||
CardType::Blueprint => [
|
||||
Rgb565::new(83, 67, 127),
|
||||
Rgb565::new(44, 111, 153),
|
||||
Rgb565::new(142, 88, 111),
|
||||
Rgb565::new(0, 188, 170),
|
||||
Rgb565::new(153, 104, 226),
|
||||
Rgb565::new(109, 129, 255),
|
||||
Rgb565::new(255, 84, 112),
|
||||
Rgb565::new(196, 143, 158),
|
||||
Rgb565::new(168, 159, 204),
|
||||
Rgb565::new(190, 155, 255),
|
||||
Rgb565::new(255, 155, 113),
|
||||
Rgb565::new(127, 206, 255),
|
||||
Rgb565::new(255, 155, 182),
|
||||
Rgb565::new(255, 217, 174),
|
||||
Rgb565::new(255, 217, 232),
|
||||
Rgb565::new(255, 255, 255),
|
||||
],
|
||||
CardType::CYBER => [
|
||||
Rgb565::new(0, 0, 0),
|
||||
Rgb565::new(0, 0, 126),
|
||||
Rgb565::new(0, 0, 255),
|
||||
Rgb565::new(126, 0, 0),
|
||||
Rgb565::new(126, 0, 126),
|
||||
Rgb565::new(4, 126, 0),
|
||||
Rgb565::new(254, 0, 0),
|
||||
Rgb565::new(4, 126, 126),
|
||||
Rgb565::new(254, 0, 255),
|
||||
Rgb565::new(126, 126, 0),
|
||||
Rgb565::new(126, 126, 126),
|
||||
Rgb565::new(6, 255, 4),
|
||||
Rgb565::new(6, 255, 255),
|
||||
Rgb565::new(190, 190, 190),
|
||||
Rgb565::new(255, 255, 4),
|
||||
Rgb565::new(255, 255, 255),
|
||||
],
|
||||
CardType::Nature => [
|
||||
Rgb565::new(35, 34, 40),
|
||||
Rgb565::new(40, 66, 97),
|
||||
Rgb565::new(30, 116, 83),
|
||||
Rgb565::new(117, 77, 69),
|
||||
Rgb565::new(95, 88, 84),
|
||||
Rgb565::new(36, 133, 166),
|
||||
Rgb565::new(198, 80, 70),
|
||||
Rgb565::new(85, 160, 88),
|
||||
Rgb565::new(135, 133, 115),
|
||||
Rgb565::new(84, 186, 210),
|
||||
Rgb565::new(161, 191, 65),
|
||||
Rgb565::new(230, 146, 138),
|
||||
Rgb565::new(184, 176, 149),
|
||||
Rgb565::new(227, 192, 84),
|
||||
Rgb565::new(195, 213, 199),
|
||||
Rgb565::new(255, 255, 255),
|
||||
],
|
||||
CardType::Fossil => [
|
||||
Rgb565::new(75, 61, 68),
|
||||
Rgb565::new(119, 66, 81),
|
||||
Rgb565::new(78, 84, 99),
|
||||
Rgb565::new(100, 83, 85),
|
||||
Rgb565::new(156, 82, 78),
|
||||
Rgb565::new(132, 109, 89),
|
||||
Rgb565::new(91, 125, 115),
|
||||
Rgb565::new(125, 123, 98),
|
||||
Rgb565::new(140, 124, 121),
|
||||
Rgb565::new(185, 122, 96),
|
||||
Rgb565::new(168, 138, 94),
|
||||
Rgb565::new(142, 159, 125),
|
||||
Rgb565::new(170, 162, 93),
|
||||
Rgb565::new(169, 156, 141),
|
||||
Rgb565::new(204, 168, 123),
|
||||
Rgb565::new(255, 255, 255),
|
||||
],
|
||||
CardType::Ghost => [
|
||||
Rgb565::new(0, 0, 0),
|
||||
Rgb565::new(24, 24, 24),
|
||||
Rgb565::new(40, 40, 40),
|
||||
Rgb565::new(56, 56, 56),
|
||||
Rgb565::new(71, 71, 71),
|
||||
Rgb565::new(86, 86, 86),
|
||||
Rgb565::new(100, 100, 100),
|
||||
Rgb565::new(113, 113, 113),
|
||||
Rgb565::new(126, 126, 126),
|
||||
Rgb565::new(140, 140, 140),
|
||||
Rgb565::new(155, 155, 155),
|
||||
Rgb565::new(171, 171, 171),
|
||||
Rgb565::new(189, 189, 189),
|
||||
Rgb565::new(209, 209, 209),
|
||||
Rgb565::new(231, 231, 231),
|
||||
Rgb565::new(255, 255, 255),
|
||||
],
|
||||
CardType::Daemon => [
|
||||
Rgb565::new(0, 3, 60),
|
||||
Rgb565::new(96, 0, 136),
|
||||
Rgb565::new(0, 56, 132),
|
||||
Rgb565::new(42, 46, 121),
|
||||
Rgb565::new(0, 82, 96),
|
||||
Rgb565::new(177, 5, 133),
|
||||
Rgb565::new(255, 0, 78),
|
||||
Rgb565::new(172, 41, 206),
|
||||
Rgb565::new(0, 157, 74),
|
||||
Rgb565::new(0, 138, 197),
|
||||
Rgb565::new(78, 110, 168),
|
||||
Rgb565::new(255, 92, 255),
|
||||
Rgb565::new(10, 255, 82),
|
||||
Rgb565::new(0, 247, 255),
|
||||
Rgb565::new(173, 212, 250),
|
||||
Rgb565::new(255, 255, 255),
|
||||
],
|
||||
CardType::Fairy => [
|
||||
Rgb565::new(40, 40, 46),
|
||||
Rgb565::new(108, 86, 113),
|
||||
Rgb565::new(135, 168, 137),
|
||||
Rgb565::new(249, 130, 132),
|
||||
Rgb565::new(176, 169, 228),
|
||||
Rgb565::new(222, 163, 139),
|
||||
Rgb565::new(172, 204, 228),
|
||||
Rgb565::new(254, 170, 228),
|
||||
Rgb565::new(217, 200, 191),
|
||||
Rgb565::new(255, 195, 132),
|
||||
Rgb565::new(176, 235, 147),
|
||||
Rgb565::new(179, 227, 218),
|
||||
Rgb565::new(233, 245, 157),
|
||||
Rgb565::new(255, 230, 198),
|
||||
Rgb565::new(255, 247, 160),
|
||||
Rgb565::new(255, 255, 255),
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Sprite {
|
||||
pub data: Vec<u8>,
|
||||
@@ -53,7 +239,7 @@ impl TryFrom<NfcPayload<'static>> for Card {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(payload: NfcPayload) -> Result<Self, Self::Error> {
|
||||
let uuid: String = str::from_utf8(payload.card_uuid).unwrap().into();
|
||||
let uuid: String = "empty for now".into(); //str::from_utf8(payload.card_uuid).unwrap().into();
|
||||
let event = decode_known_event(payload.event_encoding);
|
||||
let cardtype = CardType::from(payload.card_type);
|
||||
let (name, trait1, trait2, trait3) = decode_packed_card_text(payload.packed_card_text);
|
||||
|
||||
Reference in New Issue
Block a user