Skip to content

Commit

Permalink
Merge branch 'render'
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Mar 8, 2024
2 parents 3b2e131 + 245e60c commit cf2ad21
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 19 deletions.
31 changes: 28 additions & 3 deletions crates/client/option/src/enums/attack_indicator.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
//! Enum for attack indicator.

use std::fmt::Display;

use enum_iterator::Sequence;
use rimecraft_text::{format_localization_key, Localizable};

use super::ByUSizeId;

/// Represents the position of the attack indicator.
///
/// # MCJE Reference
///
/// This type represents `net.minecraft.client.option.AttackIndicator` (yarn).
#[derive(Debug)]
#[derive(Debug, Sequence)]
pub enum AttackIndicator {
/// No attack indicator.
None,
/// Attack indicator off.
Off,
/// Below crosshair.
Crosshair,
/// Next to hotbar.
Hotbar
}

impl ByUSizeId for AttackIndicator {}

impl Display for AttackIndicator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
AttackIndicator::Off => "off",
AttackIndicator::Crosshair => "crosshair",
AttackIndicator::Hotbar => "hotbar",
})
}
}

impl Localizable for AttackIndicator {
fn localization_key(&self) -> String {
format_localization_key!("options", "attack", format!("{}", self))
}
}
20 changes: 19 additions & 1 deletion crates/client/option/src/enums/cloud_render_mode.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
//! Enum for cloud render mode.

use std::fmt::Display;

use enum_iterator::Sequence;

use super::ByUSizeId;

/// Represents the rendering mode of clouds.
///
/// # MCJE Reference
///
/// This type represents `net.minecraft.client.option.CloudRenderMode` (yarn).
#[derive(Debug)]
#[derive(Debug, Sequence)]
pub enum CloudRenderMode {
/// Doesn't render clouds.
Off,
/// Render clouds faster.
Fast,
/// Render clouds fancier.
Fancy
}

impl ByUSizeId for CloudRenderMode {}

impl Display for CloudRenderMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
CloudRenderMode::Off => "off",
CloudRenderMode::Fast => "fast",
CloudRenderMode::Fancy => "fancy",
})
}
}
27 changes: 26 additions & 1 deletion crates/client/option/src/enums/graphics_mode.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
//! Enum for graphics mode.

use std::fmt::Display;

use enum_iterator::Sequence;
use rimecraft_text::{format_localization_key, Localizable};

use super::ByUSizeId;

/// Represents the mode for graphics.
///
/// # MCJE Reference
///
/// This type represents `net.minecraft.client.option.GraphicsMode` (yarn).
#[derive(Debug)]
#[derive(Debug, Sequence)]
pub enum GraphicsMode {
/// The fastest rendering speed with the worst picture.
Fast,
/// Not that fast but with a better picture.
Fancy,
/// Maybe slow, but with the best picture.
Fabulous
}

impl ByUSizeId for GraphicsMode {}

impl Display for GraphicsMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
GraphicsMode::Fast => "fast",
GraphicsMode::Fancy => "fancy",
GraphicsMode::Fabulous => "fabulous",
})
}
}

impl Localizable for GraphicsMode {
fn localization_key(&self) -> String {
format_localization_key!("options", "graphics", format!("{}", self))
}
}
2 changes: 1 addition & 1 deletion crates/client/option/src/enums/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod particles_mode;
pub mod perspective;

/// If a [`Sequence`], often enums, implements this, it will be allowed to get items directly through [`usize`] indexes. Wrapping behavior is configurable.
pub trait ByUIntId: Sequence {
pub trait ByUSizeId: Sequence {
/// Gets the [`usize`] id.
fn get_usize_id(&self) -> Option<usize> where Self: PartialEq {
let all = enum_iterator::all::<Self>().collect::<Vec<_>>();
Expand Down
46 changes: 44 additions & 2 deletions crates/client/option/src/enums/narrator_mode.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
//! Enum for narrator mode.

use std::fmt::Display;

use enum_iterator::Sequence;
use rimecraft_text::{format_localization_key, Localizable};

use super::ByUSizeId;

/// Represents the mode of narrator.
///
/// # MCJE Reference
///
/// This type represents `net.minecraft.client.option.NarratorMode` (yarn).
#[derive(Debug)]
#[derive(Debug, Sequence)]
pub enum NarratorMode {
/// Narrator off.
Off,
Expand All @@ -14,5 +21,40 @@ pub enum NarratorMode {
/// Narrates only chat messages.
Chat,
/// Narrates only system messages.
Sysyem
System
}

impl ByUSizeId for NarratorMode {}

impl Display for NarratorMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
NarratorMode::Off => "off",
NarratorMode::All => "all",
NarratorMode::Chat => "chat",
NarratorMode::System => "system",
})
}
}

impl NarratorMode {
pub fn should_narrate_chat(&self) -> bool {
match self {
NarratorMode::All | NarratorMode::Chat => true,
_ => false
}
}

pub fn should_narrate_system(&self) -> bool {
match self {
NarratorMode::All | NarratorMode::System => true,
_ => false
}
}
}

impl Localizable for NarratorMode {
fn localization_key(&self) -> String {
format_localization_key!("options", "narrator", format!("{}", self))
}
}
21 changes: 15 additions & 6 deletions crates/client/option/src/enums/particles_mode.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! Enum for particles mode.

use std::fmt::Display;

use enum_iterator::Sequence;
use rimecraft_text::{format_localization_key, Localizable};

use super::ByUIntId;
use super::ByUSizeId;

/// Represents the rendering mode of particles.
///
Expand All @@ -19,14 +22,20 @@ pub enum ParticlesMode {
Minimal
}

impl ByUIntId for ParticlesMode {}
impl ByUSizeId for ParticlesMode {}

impl ParticlesMode {
fn translation_key(&self) -> String {
String::from("options.particles.") + match self {
impl Display for ParticlesMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
ParticlesMode::All => "all",
ParticlesMode::Decreased => "decreased",
ParticlesMode::Minimal => "minimal",
}
})
}
}

impl Localizable for ParticlesMode {
fn localization_key(&self) -> String {
format_localization_key!("options", "particles", format!("{}", self))
}
}
20 changes: 16 additions & 4 deletions crates/client/option/src/enums/perspective.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Enum for perspective.

use std::fmt::Display;

use enum_iterator::Sequence;

use super::ByUIntId;
use super::ByUSizeId;

/// Represents the perspective.
///
Expand All @@ -19,17 +21,27 @@ pub enum Perspective {
ThirdPersonFront
}

impl ByUIntId for Perspective {}
impl ByUSizeId for Perspective {}

impl Display for Perspective {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
Perspective::FirstPerson => "first_person",
Perspective::ThirdPersonBack => "third_person_back",
Perspective::ThirdPersonFront => "third_person_front",
})
}
}

impl Perspective {
fn is_first_person(&self) -> bool {
pub fn is_first_person(&self) -> bool {
match self {
Perspective::FirstPerson => true,
_ => false
}
}

fn is_front_view(&self) -> bool {
pub fn is_front_view(&self) -> bool {
match self {
Perspective::ThirdPersonBack => false,
_ => true
Expand Down
3 changes: 2 additions & 1 deletion crates/core/text/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ rimecraft-fmt = { path = "../../util/fmt" }
serde = { version = "1.0", features = ["derive"], optional = true }

[features]
default = []
default = ["macros"]
serde = ["dep:serde"]
macros = []

[lints]
workspace = true
11 changes: 11 additions & 0 deletions crates/core/text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,16 @@ where
}
}

pub trait Localizable {
fn localization_key(&self) -> String;

fn localized_name(&self) -> Text<(), ()> {
todo!()
}
}

#[cfg(test)]
mod tests;

#[cfg(feature = "macros")]
mod macros;
28 changes: 28 additions & 0 deletions crates/core/text/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//! Macro rules.

/// Creates a new localization key with literals.
///
/// # Examples
///
/// ```
/// use rimecraft_identifier::format_localization_key;
///
/// let key = format_localization_key!(
/// "category", "id", "path"
/// );
/// assert_eq!("category.id.path", key);
/// ```
#[macro_export]
macro_rules! format_localization_key {
($($word:expr),*) => {
{
let mut words: Vec<String> = Vec::new();

$(
words.push($word.to_string());
)*

words.into_iter().filter(|s| s.len() > 0).collect::<Vec<String>>().join(".")
}
};
}
9 changes: 9 additions & 0 deletions crates/util/identifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ pub struct Identifier<N, P> {
path: P,
}

/// A generics wrapper for [`Identifier`].
/// The associated types [`Identifiers::N`] and [`Identifiers::P`] should be applied to [`Identifier`] when used.
pub trait Identifiers {
/// Generic `N` that should be applied to [`Identifier`].
type N;
/// Generic `P` that should be applied to [`Identifier`].
type P;
}

impl<N, P> Identifier<N, P> {
/// Creates a new [`Identifier`].
#[inline]
Expand Down

0 comments on commit cf2ad21

Please sign in to comment.