aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--locale/tools/src/main.rs76
-rw-r--r--pixel-client/src/game.rs10
-rw-r--r--pixel-client/src/main.rs5
-rw-r--r--pixel-client/src/menu/credits.rs2
-rw-r--r--pixel-client/src/menu/main.rs2
-rw-r--r--pixel-client/src/menu/settings.rs2
-rw-r--r--pixel-client/src/profiler.rs6
-rw-r--r--pixel-client/src/render/font.rs1
-rw-r--r--pixel-client/src/ui.rs2
-rw-r--r--server/bot/src/algos/customer.rs7
-rw-r--r--server/bot/src/algos/frank.rs10
-rw-r--r--server/bot/src/algos/mod.rs7
-rw-r--r--server/bot/src/algos/test.rs10
-rw-r--r--server/bot/src/main.rs2
-rw-r--r--server/client-lib/src/lib.rs31
-rw-r--r--server/src/data/index.rs13
-rw-r--r--server/src/data/mod.rs6
-rw-r--r--server/src/entity/bot.rs2
-rw-r--r--server/src/interaction.rs105
-rw-r--r--server/src/server.rs2
-rw-r--r--server/src/state.rs11
21 files changed, 141 insertions, 171 deletions
diff --git a/locale/tools/src/main.rs b/locale/tools/src/main.rs
index 9b63a73e..4fe3c12c 100644
--- a/locale/tools/src/main.rs
+++ b/locale/tools/src/main.rs
@@ -3,6 +3,7 @@ use anyhow::{anyhow, Context, Result};
use clap::Parser;
use std::{
collections::BTreeMap,
+ fmt::Write as W2,
fs::{read_to_string, File},
io::Write,
path::{Path, PathBuf},
@@ -33,7 +34,7 @@ enum Args {
},
}
-static NATIVE_LANGUAGE_NAMES: &[(&'static str, &'static str)] = &[
+static NATIVE_LANGUAGE_NAMES: &[(&str, &str)] = &[
("en", "English"),
("de", "Deutsch"),
("fr", "Français"),
@@ -64,6 +65,7 @@ fn main() -> Result<()> {
if let Some(fallback) = fallback {
let f = load_ini(&fallback)?;
for (k, v) in f {
+ #[allow(clippy::map_entry)]
if !ini.contains_key(&k) {
eprintln!("fallback: key {k:?} is missing");
ini.insert(k, v);
@@ -88,19 +90,21 @@ msgstr ""
{}"#,
input.file_stem().unwrap().to_string_lossy(),
ini.into_iter()
- .map(|(mut key, value)| {
+ .fold(String::new(), |mut a, (mut key, value)| {
if let Some(id_map) = &id_map {
if let Some(new_id) = id_map.get(&key) {
key = new_id.to_owned()
}
}
- format!(
+ writeln!(
+ a,
"msgid {}\nmsgstr {}\n\n",
serde_json::to_string(&key).unwrap(),
serde_json::to_string(&value).unwrap(),
)
+ .unwrap();
+ a
})
- .collect::<String>()
)
.as_bytes(),
)?;
@@ -134,21 +138,21 @@ msgstr ""
}
File::create(output)?.write_all(
- format!(
- "id,{}\n{}",
- langs.join(","),
- tr_tr
- .into_iter()
- .map(|(k, v)| format!(
- "{k},{}\n",
+ tr_tr
+ .into_iter()
+ .fold(format!("id,{}\n", langs.join(",")), |mut a, (k, v)| {
+ writeln!(
+ a,
+ "{k},{}",
v.values()
.map(|s| serde_json::to_string(s).unwrap())
.collect::<Vec<_>>()
.join(",")
- ))
- .collect::<String>()
- )
- .as_bytes(),
+ )
+ .unwrap();
+ a
+ })
+ .as_bytes(),
)?;
Ok(())
}
@@ -196,7 +200,7 @@ msgstr ""
line = rest;
msgstr = String::new();
mode = 2;
- } else if let Some(_) = line.strip_prefix("msgctxt ") {
+ } else if line.starts_with("msgctxt ") {
mode = 0;
eprintln!("warning: msgctxt not implemented (line {})", i + 1);
continue;
@@ -212,14 +216,13 @@ msgstr ""
}
File::create(output)?.write_all(
- format!(
- "[hurrycurry]\n{}",
- outmap
- .into_iter()
- .map(|(k, v)| format!("{k}={v}\n"))
- .collect::<String>()
- )
- .as_bytes(),
+ outmap
+ .into_iter()
+ .fold("[hurrycurry]\n".to_string(), |mut a, (k, v)| {
+ writeln!(a, "{k}={v}").unwrap();
+ a
+ })
+ .as_bytes(),
)?;
Ok(())
@@ -248,10 +251,8 @@ msgstr ""
continue;
}
if let Some(rest) = line.strip_prefix("msgid ") {
- if !msgid.is_empty() {
- if !output_flip.contains_key(&msgid) {
- output_flip.insert(msgid.replace("\n", "\\n"), format!("unknown{i}"));
- }
+ if !msgid.is_empty() && !output_flip.contains_key(&msgid) {
+ output_flip.insert(msgid.replace("\n", "\\n"), format!("unknown{i}"));
}
line = rest;
id = true;
@@ -273,14 +274,13 @@ msgstr ""
.collect::<BTreeMap<_, _>>();
File::create(output)?.write_all(
- format!(
- "[hurrycurry]\n{}",
- output_unflip
- .into_iter()
- .map(|(k, v)| format!("{k}={v}\n"))
- .collect::<String>()
- )
- .as_bytes(),
+ output_unflip
+ .into_iter()
+ .fold("[hurrycurry]\n".to_string(), |mut a, (k, v)| {
+ writeln!(a, "{k}={v}").unwrap();
+ a
+ })
+ .as_bytes(),
)?;
Ok(())
@@ -289,12 +289,12 @@ msgstr ""
}
fn load_ini(path: &Path) -> Result<BTreeMap<String, String>> {
- Ok(read_to_string(path)?
+ read_to_string(path)?
.lines()
.skip(1)
.map(|l| {
let (k, v) = l.split_once("=").ok_or(anyhow!("'=' missing"))?;
Ok::<_, anyhow::Error>((k.to_owned(), v.replace("%n", "\n")))
})
- .try_collect()?)
+ .try_collect()
}
diff --git a/pixel-client/src/game.rs b/pixel-client/src/game.rs
index fb81ba90..780cde42 100644
--- a/pixel-client/src/game.rs
+++ b/pixel-client/src/game.rs
@@ -371,12 +371,10 @@ impl Game {
PacketC::Communicate {
player,
message,
- timeout,
+ timeout: Some(timeout),
} => {
- if let Some(timeout) = timeout {
- if let Some(player) = self.players.get_mut(&player) {
- player.message_persist = message.map(|m| (m, timeout));
- }
+ if let Some(player) = self.players.get_mut(&player) {
+ player.message_persist = message.map(|m| (m, timeout));
}
}
PacketC::Error { message } => {
@@ -496,7 +494,7 @@ impl Player {
}
}
if let Some(item) = &self.item {
- item.draw(ctx, &item_sprites)
+ item.draw(ctx, item_sprites)
}
}
}
diff --git a/pixel-client/src/main.rs b/pixel-client/src/main.rs
index eee426b1..8b0887e5 100644
--- a/pixel-client/src/main.rs
+++ b/pixel-client/src/main.rs
@@ -163,10 +163,7 @@ fn main() -> Result<()> {
State::MainMenu(menu) => menu.keyboard_event(keycode, true),
_ => (),
},
- Event::TextInput { text, .. } => match &mut state {
- State::MainMenu(menu) => menu.ui_state.text_input(text),
- _ => (),
- },
+ Event::TextInput { text, .. } => if let State::MainMenu(menu) = &mut state { menu.ui_state.text_input(text) },
_ => {}
}
}
diff --git a/pixel-client/src/menu/credits.rs b/pixel-client/src/menu/credits.rs
index 1b3128e5..b0a74478 100644
--- a/pixel-client/src/menu/credits.rs
+++ b/pixel-client/src/menu/credits.rs
@@ -47,6 +47,6 @@ impl CreditsMenu {
});
});
- return back;
+ back
}
}
diff --git a/pixel-client/src/menu/main.rs b/pixel-client/src/menu/main.rs
index 7045931e..ce5518e2 100644
--- a/pixel-client/src/menu/main.rs
+++ b/pixel-client/src/menu/main.rs
@@ -86,7 +86,7 @@ impl MainMenu {
if ui.button(80., "Join") {
self.next_state = Some(Box::new(State::Ingame(Box::new(Game::new(
Network::connect(&self.server_address).unwrap(),
- &config,
+ config,
ui.renderer.atlas_layout(),
)))))
}
diff --git a/pixel-client/src/menu/settings.rs b/pixel-client/src/menu/settings.rs
index aef56f2f..d497ff48 100644
--- a/pixel-client/src/menu/settings.rs
+++ b/pixel-client/src/menu/settings.rs
@@ -60,6 +60,6 @@ impl SettingsMenu {
});
});
- return back;
+ back
}
}
diff --git a/pixel-client/src/profiler.rs b/pixel-client/src/profiler.rs
index 98bf8196..11703fa3 100644
--- a/pixel-client/src/profiler.rs
+++ b/pixel-client/src/profiler.rs
@@ -25,6 +25,12 @@ pub struct ProfilerOverlay {
fps: f32,
}
+impl Default for ProfilerOverlay {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl ProfilerOverlay {
pub fn new() -> Self {
Self {
diff --git a/pixel-client/src/render/font.rs b/pixel-client/src/render/font.rs
index 79e54753..54c760f1 100644
--- a/pixel-client/src/render/font.rs
+++ b/pixel-client/src/render/font.rs
@@ -27,7 +27,6 @@ impl FontTextures {
pub fn init(layout: &AtlasLayout) -> Self {
FontTextures {
glyphs: (0..128)
- .into_iter()
.map(|n| {
layout
.get(&format!("letter_{n}+a"))
diff --git a/pixel-client/src/ui.rs b/pixel-client/src/ui.rs
index 9e3e1a3e..a77d2856 100644
--- a/pixel-client/src/ui.rs
+++ b/pixel-client/src/ui.rs
@@ -204,7 +204,7 @@ impl<'a, 'b> Ui<'a, 'b> {
let margin = Vec2::splat(4.);
let text_size = self
.renderer
- .draw_text(self.cursor + margin, &content, 1., None);
+ .draw_text(self.cursor + margin, content, 1., None);
let size = margin + Vec2::new(w, text_size.y) + margin;
self.index += 1;
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs
index 61a79dbc..1b1315c6 100644
--- a/server/bot/src/algos/customer.rs
+++ b/server/bot/src/algos/customer.rs
@@ -25,7 +25,9 @@ use log::info;
use rand::{random, seq::IndexedRandom, thread_rng};
#[derive(Debug, Clone)]
+#[derive(Default)]
pub enum Customer {
+ #[default]
New,
Entering {
path: Path,
@@ -50,11 +52,6 @@ pub enum Customer {
},
}
-impl Default for Customer {
- fn default() -> Self {
- Customer::New
- }
-}
impl BotAlgo for Customer {
fn tick(&mut self, me: PlayerID, game: &Game, dt: f32) -> BotInput {
diff --git a/server/bot/src/algos/frank.rs b/server/bot/src/algos/frank.rs
index 980d8c08..95718d4c 100644
--- a/server/bot/src/algos/frank.rs
+++ b/server/bot/src/algos/frank.rs
@@ -35,13 +35,13 @@ pub struct Frank {
const MESSAGES: &[fn(&str) -> String] = &[
|_name| format!("Work faster, {_name}!"),
- |_name| format!("Quick! There is no time for chit-chat!"),
- |_name| format!("Look what a mess you've made! Clean this up immediatly!"),
- |_name| format!("Don't let the customers starve!"),
+ |_name| "Quick! There is no time for chit-chat!".to_string(),
+ |_name| "Look what a mess you've made! Clean this up immediatly!".to_string(),
+ |_name| "Don't let the customers starve!".to_string(),
|_name| format!("You are wasting me money, {_name}!"),
- |_name| format!("I'm not paying you to stand around!"),
+ |_name| "I'm not paying you to stand around!".to_string(),
|_name| format!("Get back to work, {_name}!"),
- |_name| format!("You're FIRED!"),
+ |_name| "You're FIRED!".to_string(),
];
impl BotAlgo for Frank {
diff --git a/server/bot/src/algos/mod.rs b/server/bot/src/algos/mod.rs
index bb1d615b..dea31406 100644
--- a/server/bot/src/algos/mod.rs
+++ b/server/bot/src/algos/mod.rs
@@ -16,18 +16,19 @@
*/
mod customer;
+mod frank;
mod simple;
mod test;
mod waiter;
-pub mod frank;
pub use customer::Customer;
+pub use frank::Frank;
pub use simple::Simple;
pub use test::Test;
pub use waiter::Waiter;
-pub use frank::Frank;
-pub const ALGO_CONSTRUCTORS: &'static [(&'static str, fn() -> crate::DynBotAlgo)] = &[
+#[allow(clippy::type_complexity)]
+pub const ALGO_CONSTRUCTORS: &[(&str, fn() -> crate::DynBotAlgo)] = &[
("test", || Box::new(Test::default())),
("simple", || Box::new(Simple::default())),
("waiter", || Box::new(Waiter::default())),
diff --git a/server/bot/src/algos/test.rs b/server/bot/src/algos/test.rs
index 73368de2..7cfafc29 100644
--- a/server/bot/src/algos/test.rs
+++ b/server/bot/src/algos/test.rs
@@ -43,12 +43,10 @@ impl BotAlgo for Test {
interact: None,
..Default::default()
};
- } else {
- if let Some((item, near)) = find_demand(game) {
- info!("demand {item:?} near {near}");
- if let Some(path) = find_path_to_neighbour(&game.walkable, pos.as_ivec2(), near) {
- self.path = Some(path);
- }
+ } else if let Some((item, near)) = find_demand(game) {
+ info!("demand {item:?} near {near}");
+ if let Some(path) = find_path_to_neighbour(&game.walkable, pos.as_ivec2(), near) {
+ self.path = Some(path);
}
}
BotInput::default()
diff --git a/server/bot/src/main.rs b/server/bot/src/main.rs
index bb30cb68..d4d21d35 100644
--- a/server/bot/src/main.rs
+++ b/server/bot/src/main.rs
@@ -76,7 +76,7 @@ fn main() -> Result<()> {
.iter()
.find(|(n, _)| n == &args.algo)
.map(|(_, c)| c())
- .expect(&format!("unknown algo {:?}", args.algo)),
+ .unwrap_or_else(|| panic!("unknown algo {:?}", args.algo)),
}),
PacketC::Error { message } => {
warn!("server error message: {message}");
diff --git a/server/client-lib/src/lib.rs b/server/client-lib/src/lib.rs
index b4cb0724..fc0f8ae6 100644
--- a/server/client-lib/src/lib.rs
+++ b/server/client-lib/src/lib.rs
@@ -15,7 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#![feature(map_many_mut)]
+#![feature(map_many_mut, let_chains)]
pub mod network;
pub mod spatial_index;
@@ -60,6 +60,7 @@ pub struct Player {
pub movement: MovementBase,
}
+#[derive(Default)]
pub struct Game {
pub data: Arc<Gamedata>,
pub tiles: HashMap<IVec2, Tile>,
@@ -73,22 +74,6 @@ pub struct Game {
pub score: Score,
}
-impl Default for Game {
- fn default() -> Self {
- Self {
- data: Default::default(),
- tiles: HashMap::new(),
- walkable: HashSet::new(),
- players: HashMap::new(),
- players_spatial_index: SpatialIndex::default(),
- end: None,
- lobby: false,
- environment_effects: HashSet::new(),
- score: Score::default(),
- }
- }
-}
-
impl Game {
pub fn apply_packet(&mut self, packet: PacketC) {
match packet {
@@ -176,10 +161,10 @@ impl Game {
message,
timeout,
} => {
- if let Some(timeout) = &timeout {
- if let Some(player) = self.players.get_mut(&player) {
- player.communicate_persist = message.to_owned().map(|m| (m, *timeout));
- }
+ if let Some(timeout) = &timeout
+ && let Some(player) = self.players.get_mut(&player)
+ {
+ player.communicate_persist = message.to_owned().map(|m| (m, *timeout));
}
}
PacketC::Score(score) => {
@@ -211,14 +196,14 @@ impl Game {
.update_entry(pid, player.movement.position);
}
- for (_, player) in &mut self.players {
+ for player in self.players.values_mut() {
if let Some(item) = &mut player.item {
if let Some(active) = &mut item.active {
active.position += active.speed;
}
}
}
- for (_, tile) in &mut self.tiles {
+ for tile in self.tiles.values_mut() {
if let Some(item) = &mut tile.item {
if let Some(active) = &mut item.active {
active.position += active.speed;
diff --git a/server/src/data/index.rs b/server/src/data/index.rs
index 1c206d83..e056cfc0 100644
--- a/server/src/data/index.rs
+++ b/server/src/data/index.rs
@@ -11,14 +11,11 @@ impl GamedataIndex {
self.recipe_passive_by_input.clear();
for (ri, r) in data.recipes() {
- match r {
- Recipe::Passive { input, .. } => {
- self.recipe_passive_by_input
- .entry(*input)
- .or_default()
- .push(ri);
- }
- _ => (),
+ if let Recipe::Passive { input, .. } = r {
+ self.recipe_passive_by_input
+ .entry(*input)
+ .or_default()
+ .push(ri);
}
}
}
diff --git a/server/src/data/mod.rs b/server/src/data/mod.rs
index 246f695e..91b32a42 100644
--- a/server/src/data/mod.rs
+++ b/server/src/data/mod.rs
@@ -152,14 +152,12 @@ impl DataIndex {
&self
.read_recipes(
map_in
- .recipes
- .as_ref()
- .map(|a| a.as_str())
+ .recipes.as_deref()
.unwrap_or("default"),
)
.await?,
)?;
- Ok(build_data(&self.maps, map.to_string(), map_in, recipes_in)?)
+ build_data(&self.maps, map.to_string(), map_in, recipes_in)
}
}
diff --git a/server/src/entity/bot.rs b/server/src/entity/bot.rs
index cc67f640..79ca97f1 100644
--- a/server/src/entity/bot.rs
+++ b/server/src/entity/bot.rs
@@ -55,7 +55,7 @@ impl<T: BotAlgo> Entity for BotDriver<T> {
})
}
- let input = self.algo.tick(self.id, &c.game, c.dt);
+ let input = self.algo.tick(self.id, c.game, c.dt);
if input.leave {
info!("leave {:?}", self.id);
c.packet_in.push_back(PacketS::Leave { player: self.id });
diff --git a/server/src/interaction.rs b/server/src/interaction.rs
index 0721fa81..3a950fba 100644
--- a/server/src/interaction.rs
+++ b/server/src/interaction.rs
@@ -22,6 +22,7 @@ use std::collections::VecDeque;
use crate::data::index::GamedataIndex;
+#[allow(clippy::too_many_arguments)]
pub fn interact(
data: &Gamedata,
edge: bool,
@@ -108,32 +109,30 @@ pub fn interact(
}
if this.is_none() {
if let Some(item) = &other {
- if item.kind == *input {
- if item.active.is_none() {
- let mut item = other.take().unwrap();
- info!("start active recipe {ri:?}");
- item.active = Some(Involvement {
- player,
- recipe: ri,
- speed: *speed,
- position: 0.,
- warn: false,
- });
- *this = Some(item);
- score.active_recipes += 1;
- packet_out.push_back(PacketC::MoveItem {
- from: other_loc,
- to: this_loc,
- });
- packet_out.push_back(PacketC::SetProgress {
- player,
- item: this_loc,
- position: 0.,
- speed: *speed,
- warn: false,
- });
- return;
- }
+ if item.kind == *input && item.active.is_none() {
+ let mut item = other.take().unwrap();
+ info!("start active recipe {ri:?}");
+ item.active = Some(Involvement {
+ player,
+ recipe: ri,
+ speed: *speed,
+ position: 0.,
+ warn: false,
+ });
+ *this = Some(item);
+ score.active_recipes += 1;
+ packet_out.push_back(PacketC::MoveItem {
+ from: other_loc,
+ to: this_loc,
+ });
+ packet_out.push_back(PacketC::SetProgress {
+ player,
+ item: this_loc,
+ position: 0.,
+ speed: *speed,
+ warn: false,
+ });
+ return;
}
}
}
@@ -194,7 +193,6 @@ pub fn interact(
from: this_loc,
to: other_loc,
});
- return;
}
}
}
@@ -209,6 +207,7 @@ pub enum TickEffect {
Produce,
}
+#[allow(clippy::too_many_arguments)]
pub fn tick_slot(
dt: f32,
data: &Gamedata,
@@ -273,34 +272,31 @@ pub fn tick_slot(
warn: a.warn,
item: slot_loc,
});
- return;
}
- } else {
- if let Some(recipes) = data_index.recipe_passive_by_input.get(&item.kind) {
- for &ri in recipes {
- let recipe = data.recipe(ri);
- if recipe.supports_tile(tile) {
- if let Recipe::Passive {
- input, warn, speed, ..
- } = recipe
- {
- if *input == item.kind {
- item.active = Some(Involvement {
- player: None,
- recipe: ri,
- position: 0.,
- warn: *warn,
- speed: *speed,
- });
- packet_out.push_back(PacketC::SetProgress {
- player: None,
- position: 0.,
- speed: *speed,
- warn: *warn,
- item: slot_loc,
- });
- return;
- }
+ } else if let Some(recipes) = data_index.recipe_passive_by_input.get(&item.kind) {
+ for &ri in recipes {
+ let recipe = data.recipe(ri);
+ if recipe.supports_tile(tile) {
+ if let Recipe::Passive {
+ input, warn, speed, ..
+ } = recipe
+ {
+ if *input == item.kind {
+ item.active = Some(Involvement {
+ player: None,
+ recipe: ri,
+ position: 0.,
+ warn: *warn,
+ speed: *speed,
+ });
+ packet_out.push_back(PacketC::SetProgress {
+ player: None,
+ position: 0.,
+ speed: *speed,
+ warn: *warn,
+ item: slot_loc,
+ });
+ return;
}
}
}
@@ -309,6 +305,7 @@ pub fn tick_slot(
}
}
+#[allow(clippy::too_many_arguments)]
fn produce(
player: Option<PlayerID>,
this_had_item: bool,
diff --git a/server/src/server.rs b/server/src/server.rs
index fd7db5b5..01460cb9 100644
--- a/server/src/server.rs
+++ b/server/src/server.rs
@@ -399,7 +399,7 @@ impl Server {
let last_position_update = self
.last_movement_update
.entry(player)
- .or_insert_with(|| Instant::now());
+ .or_insert_with(Instant::now);
let dt = last_position_update.elapsed();
*last_position_update += dt;
let diff = pos - pd.movement.position;
diff --git a/server/src/state.rs b/server/src/state.rs
index e368317c..b9a43f6b 100644
--- a/server/src/state.rs
+++ b/server/src/state.rs
@@ -76,15 +76,12 @@ impl Server {
self.packet_in(packet, &mut replies)?;
for p in &replies {
- match p {
- PacketC::Joined { id } => {
- self.connections.entry(conn).or_default().insert(*id);
- }
- _ => (),
+ if let PacketC::Joined { id } = p {
+ self.connections.entry(conn).or_default().insert(*id);
}
}
- if self.count_chefs() <= 0 && !self.game.lobby {
+ if self.count_chefs() == 0 && !self.game.lobby {
self.tx
.send(PacketC::ServerMessage {
text: "Game was aborted due to a lack of players".to_string(),
@@ -97,7 +94,7 @@ impl Server {
pub async fn disconnect(&mut self, conn: ConnectionID) {
if let Some(players) = self.connections.get(&conn) {
- for player in players.to_owned() {
+ for player in players.clone() {
let _ = self.packet_in_outer(conn, PacketS::Leave { player }).await;
}
}