Use Rc instead of Arc for fonts

This commit is contained in:
cool-mist
2026-01-21 00:07:48 +05:30
parent d7ec3d7096
commit 5dc87df1fc
4 changed files with 13 additions and 16 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
fmt::{self, Display, Formatter}, fmt::{self, Display, Formatter},
sync::Arc, rc::Rc,
}; };
mod button; mod button;
@@ -28,7 +28,7 @@ pub struct Game {
// Constants througout the game // Constants througout the game
texture_res: Texture2D, texture_res: Texture2D,
sounds: Sounds, sounds: Sounds,
font: Arc<Font>, font: Rc<Font>,
num_squares: usize, num_squares: usize,
heading_text: String, heading_text: String,
+3 -3
View File
@@ -1,4 +1,4 @@
use std::sync::Arc; use std::rc::Rc;
use macroquad::{audio::Sound, prelude::*}; use macroquad::{audio::Sound, prelude::*};
@@ -15,11 +15,11 @@ pub struct Button {
shadow_width: f32, shadow_width: f32,
pub color: UiColor, pub color: UiColor,
sound: Sound, sound: Sound,
font: Arc<Font>, font: Rc<Font>,
} }
impl Button { impl Button {
pub fn new(text: &str, rect: Rect, color: UiColor, sound: Sound, font: Arc<Font>) -> Self { pub fn new(text: &str, rect: Rect, color: UiColor, sound: Sound, font: Rc<Font>) -> Self {
Self { Self {
text: text.to_string(), text: text.to_string(),
is_down: false, is_down: false,
+6 -3
View File
@@ -1,4 +1,4 @@
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, rc::Rc};
use super::{ use super::{
constants, sound::Sounds, Board, BoardState, ButtonAction, Game, GameMode, GameSquare, constants, sound::Sounds, Board, BoardState, ButtonAction, Game, GameMode, GameSquare,
@@ -6,7 +6,10 @@ use super::{
}; };
use macroquad::prelude::*; use macroquad::prelude::*;
use sol_chess::{board, generator::{self, RandomRange}}; use sol_chess::{
board,
generator::{self, RandomRange},
};
impl Game { impl Game {
fn get(&mut self, i: usize, j: usize) -> &mut GameSquare { fn get(&mut self, i: usize, j: usize) -> &mut GameSquare {
@@ -299,7 +302,7 @@ impl Game {
window_height: 0., window_height: 0.,
window_width: 0., window_width: 0.,
square_width: 0., square_width: 0.,
font: Arc::new(font), font: Rc::new(font),
} }
} }
} }
+2 -8
View File
@@ -30,15 +30,9 @@ pub(crate) fn b64_decode_48(input: &[u8; 8], output: &mut [u8; 6]) {
const ALPHABET: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; const ALPHABET: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
fn lookup(idx: u8) -> char { fn lookup(idx: u8) -> char {
ALPHABET ALPHABET.chars().nth(idx as usize).unwrap()
.chars()
.nth(idx as usize)
.unwrap()
} }
fn reverse_lookup(c: char) -> u8 { fn reverse_lookup(c: char) -> u8 {
ALPHABET ALPHABET.chars().position(|x| x == c).unwrap() as u8
.chars()
.position(|x| x == c)
.unwrap() as u8
} }