clippy
This commit is contained in:
@@ -170,11 +170,10 @@ pub fn apply_teleport(board: &mut Board, target: i64, x: i64, y: i64) -> Result<
|
|||||||
let (x, y) = (x as usize, y as usize);
|
let (x, y) = (x as usize, y as usize);
|
||||||
let from = if target == -1 {
|
let from = if target == -1 {
|
||||||
Some(board.player_pos())
|
Some(board.player_pos())
|
||||||
} else if let Some(obj) = board.get_hookable(target as ObjectId) {
|
|
||||||
Some(obj.location().into())
|
|
||||||
} else {
|
} else {
|
||||||
None
|
board.get_hookable(target as ObjectId).map(|o| o.location())
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(from) = from {
|
if let Some(from) = from {
|
||||||
// Check if we're blocked:
|
// Check if we're blocked:
|
||||||
if (from.ux() != x || from.uy() != y) && board.get((x, y)).is_none() {
|
if (from.ux() != x || from.uy() != y) && board.get((x, y)).is_none() {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use rhai::{Dynamic, Engine, ImmutableString};
|
use rhai::{Dynamic, Engine, ImmutableString};
|
||||||
use crate::{Board, Direction};
|
use crate::Board;
|
||||||
use crate::api::object_info::ObjectInfo;
|
use crate::api::object_info::ObjectInfo;
|
||||||
use crate::api::registry::Registry;
|
use crate::api::registry::Registry;
|
||||||
use crate::script::Registerable;
|
use crate::script::Registerable;
|
||||||
|
|||||||
@@ -25,11 +25,10 @@
|
|||||||
use rhai::{Dynamic, Engine};
|
use rhai::{Dynamic, Engine};
|
||||||
use crate::api::board::BoardRef;
|
use crate::api::board::BoardRef;
|
||||||
use crate::api::queue::ObjQueue;
|
use crate::api::queue::ObjQueue;
|
||||||
use crate::{Board, Direction};
|
use crate::Direction;
|
||||||
use crate::action::BoardAction;
|
use crate::action::BoardAction;
|
||||||
use crate::object_def::ObjectDef;
|
|
||||||
use crate::script::Registerable;
|
use crate::script::Registerable;
|
||||||
use crate::tile::{Hookable, Optics, ScriptAttributes, ScriptKey, Tile};
|
use crate::tile::{Hookable, ScriptKey};
|
||||||
use crate::utils::{LogSink, ObjectId, Point};
|
use crate::utils::{LogSink, ObjectId, Point};
|
||||||
|
|
||||||
/// A snapshot of one board object, returned by `Board.tagged`, `Board.named`,
|
/// A snapshot of one board object, returned by `Board.tagged`, `Board.named`,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use crate::floor::Floor;
|
use crate::floor::Floor;
|
||||||
use crate::fov::{color_to_rgb, FovCaster, Lighting};
|
use crate::fov::{color_to_rgb, FovCaster, Lighting};
|
||||||
use crate::glyph::Glyph;
|
use crate::glyph::Glyph;
|
||||||
use crate::log::LogLine;
|
|
||||||
use crate::utils::{Direction, Point};
|
use crate::utils::{Direction, Point};
|
||||||
use crate::utils::{ObjectId, RegistryValue};
|
use crate::utils::{ObjectId, RegistryValue};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
@@ -147,9 +146,7 @@ impl Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise the floor, or the canonical black empty cell.
|
// Otherwise the floor, or the canonical black empty cell.
|
||||||
self.floor
|
self.floor.glyph_at(p, self.width).unwrap_or_else(Glyph::transparent)
|
||||||
.glyph_at(p, self.width)
|
|
||||||
.unwrap_or_else(|| Glyph::transparent())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if `(x, y)` is a valid cell coordinate on this board.
|
/// Returns `true` if `(x, y)` is a valid cell coordinate on this board.
|
||||||
@@ -306,7 +303,7 @@ impl Board {
|
|||||||
// Find which ones are blockers
|
// Find which ones are blockers
|
||||||
let mut immobile = HashSet::new();
|
let mut immobile = HashSet::new();
|
||||||
for (curr_idx, curr) in solids.iter().enumerate() {
|
for (curr_idx, curr) in solids.iter().enumerate() {
|
||||||
let pushable = curr.as_ref().map_or(true, |c| c.shiftable());
|
let pushable = curr.as_ref().is_none_or(Tile::shiftable);
|
||||||
if !pushable {
|
if !pushable {
|
||||||
immobile.insert(curr_idx);
|
immobile.insert(curr_idx);
|
||||||
}
|
}
|
||||||
@@ -438,7 +435,7 @@ impl Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sort by id
|
// Sort by id
|
||||||
hookables.sort_by(|a, b| a.id().cmp(&b.id()));
|
hookables.sort_by_key(|a| a.id());
|
||||||
hookables
|
hookables
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,7 +452,7 @@ impl Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_sensor(&mut self, id: ObjectId, dir: Direction) {
|
pub fn move_sensor(&mut self, id: ObjectId, dir: Direction) {
|
||||||
if let Some((sensor_idx, _)) = self.sensors.iter().enumerate().find(|(idx, s)| s.scripting.id == id) {
|
if let Some(sensor_idx) = self.sensors.iter().position(|s| s.scripting.id == id) {
|
||||||
let new_loc = self.sensors[sensor_idx].location.in_dir(dir);
|
let new_loc = self.sensors[sensor_idx].location.in_dir(dir);
|
||||||
if self.in_bounds(new_loc) {
|
if self.in_bounds(new_loc) {
|
||||||
self.sensors[sensor_idx].location = new_loc
|
self.sensors[sensor_idx].location = new_loc
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
//! player) for the map loader to resolve. Cross-cell validation (one solid per
|
//! player) for the map loader to resolve. Cross-cell validation (one solid per
|
||||||
//! cell, unique names, the player winning its cell) lives in [`crate::map_file`].
|
//! cell, unique names, the player winning its cell) lives in [`crate::map_file`].
|
||||||
|
|
||||||
use crate::log::LogLine;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
@@ -116,7 +115,7 @@ impl BoardSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Try to check for validity of the board, return a list of errors we find (if any)
|
/// Try to check for validity of the board, return a list of errors we find (if any)
|
||||||
pub fn validate(&self, grid: &Vec<Option<TileSpec>>, valid_script_names: &HashSet<&String>) -> Result<(), Vec<String>> {
|
pub fn validate(&self, grid: &[Option<TileSpec>], valid_script_names: &HashSet<&String>) -> Result<(), Vec<String>> {
|
||||||
let mut errors = vec![];
|
let mut errors = vec![];
|
||||||
|
|
||||||
// Check for player being positioned exactly once
|
// Check for player being positioned exactly once
|
||||||
@@ -188,7 +187,7 @@ impl BoardSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for objects using scripts that don't exist
|
// Check for objects using scripts that don't exist
|
||||||
let missing = obj_script_names.difference(&valid_script_names).collect::<Vec<_>>();
|
let missing = obj_script_names.difference(valid_script_names).collect::<Vec<_>>();
|
||||||
if !missing.is_empty() {
|
if !missing.is_empty() {
|
||||||
errors.push(format!("Missing scripts: {missing:?}"));
|
errors.push(format!("Missing scripts: {missing:?}"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use crate::script::ScriptHost;
|
|||||||
use crate::utils::{Direction, ObjectId, Point};
|
use crate::utils::{Direction, ObjectId, Point};
|
||||||
use crate::world::World;
|
use crate::world::World;
|
||||||
use std::cell::{Ref, RefMut};
|
use std::cell::{Ref, RefMut};
|
||||||
use std::hash::Hash;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
/// How long a `say()` speech bubble stays on screen, in seconds.
|
/// How long a `say()` speech bubble stays on screen, in seconds.
|
||||||
@@ -389,7 +388,7 @@ impl GameState {
|
|||||||
fn resolve_move<P: Into<Point>>(&mut self, from: P, dir: Direction) -> bool {
|
fn resolve_move<P: Into<Point>>(&mut self, from: P, dir: Direction) -> bool {
|
||||||
let from = from.into();
|
let from = from.into();
|
||||||
// Get the target coords, if they're out of bounds then the move fails.
|
// Get the target coords, if they're out of bounds then the move fails.
|
||||||
let target: Point = dir.from_point(from).into();
|
let target: Point = dir.from_point(from);
|
||||||
if !self.board().in_bounds(target) { return false; }
|
if !self.board().in_bounds(target) { return false; }
|
||||||
|
|
||||||
if self.board().is_empty(target) {
|
if self.board().is_empty(target) {
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
use crate::action::{Action, BoardAction, ScrollLine, SendArg, MOVE_COST};
|
use crate::action::{Action, BoardAction, ScrollLine, SendArg, MOVE_COST};
|
||||||
use crate::game::SAY_DURATION;
|
use crate::game::SAY_DURATION;
|
||||||
use crate::log::LogLine;
|
use crate::log::LogLine;
|
||||||
use crate::object_def::ObjectDef;
|
|
||||||
use crate::utils::{Direction, LogSink, Hook, ObjectId, Point};
|
use crate::utils::{Direction, LogSink, Hook, ObjectId, Point};
|
||||||
use rhai::{
|
use rhai::{
|
||||||
Array, CallFnOptions, Dynamic, Engine, ImmutableString, Module, NativeCallContext,
|
Array, CallFnOptions, Dynamic, Engine, ImmutableString, Module, NativeCallContext,
|
||||||
@@ -133,7 +132,7 @@ impl ScriptHost {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
match script_key.source(&script_sources) {
|
match script_key.source(script_sources) {
|
||||||
Ok(None) => { continue } // This has no source...
|
Ok(None) => { continue } // This has no source...
|
||||||
Err(e) => { // Couldn't find it
|
Err(e) => { // Couldn't find it
|
||||||
failed.insert(script_key.clone());
|
failed.insert(script_key.clone());
|
||||||
@@ -279,7 +278,7 @@ impl ScriptHost {
|
|||||||
/// the same send, we could fail to terminate. The only way to cut that loop would be to drop
|
/// the same send, we could fail to terminate. The only way to cut that loop would be to drop
|
||||||
/// a send action we've already seen this tick.
|
/// a send action we've already seen this tick.
|
||||||
pub(crate) fn run_send(&mut self, id: ObjectId, fn_name: &str, arg: SendArg) {
|
pub(crate) fn run_send(&mut self, id: ObjectId, fn_name: &str, arg: SendArg) {
|
||||||
if let Some(mut info) = ObjectInfo::from_id(id, self.board.clone()) {
|
if let Some(info) = ObjectInfo::from_id(id, self.board.clone()) {
|
||||||
if let Some(script) = self.scripts.get(&info.script_key)
|
if let Some(script) = self.scripts.get(&info.script_key)
|
||||||
&& let Some(scope) = self.scopes.get_mut(&id) {
|
&& let Some(scope) = self.scopes.get_mut(&id) {
|
||||||
|
|
||||||
|
|||||||
+5
-14
@@ -18,7 +18,7 @@ use crate::utils::{ObjectId, Point};
|
|||||||
pub enum DrawLayer { Above, Below }
|
pub enum DrawLayer { Above, Below }
|
||||||
|
|
||||||
/// How a thing interacts with the lighting and visibility models
|
/// How a thing interacts with the lighting and visibility models
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Copy, Clone, Debug)]
|
#[derive(Serialize, Deserialize, PartialEq, Copy, Clone, Debug, Default)]
|
||||||
#[serde(rename = "lowercase")]
|
#[serde(rename = "lowercase")]
|
||||||
pub struct Optics {
|
pub struct Optics {
|
||||||
/// Opaque things block field of view
|
/// Opaque things block field of view
|
||||||
@@ -36,15 +36,6 @@ pub struct Optics {
|
|||||||
pub glow: u32,
|
pub glow: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Optics {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
opaque: false,
|
|
||||||
glow: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn default_as_true() -> bool {
|
const fn default_as_true() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@@ -66,7 +57,7 @@ impl ScriptKey {
|
|||||||
match self {
|
match self {
|
||||||
ScriptKey::None => "<none>",
|
ScriptKey::None => "<none>",
|
||||||
ScriptKey::World(name) => name.as_str(),
|
ScriptKey::World(name) => name.as_str(),
|
||||||
ScriptKey::Builtin(name) => *name
|
ScriptKey::Builtin(name) => name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +78,7 @@ impl ScriptKey {
|
|||||||
|
|
||||||
impl From<Option<String>> for ScriptKey {
|
impl From<Option<String>> for ScriptKey {
|
||||||
fn from(s: Option<String>) -> Self {
|
fn from(s: Option<String>) -> Self {
|
||||||
s.map_or(Self::None, |s| Self::World(s))
|
s.map_or(Self::None, Self::World)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,7 +309,7 @@ impl IntoTile for TileSpec {
|
|||||||
queue: ObjQueue::new(),
|
queue: ObjQueue::new(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
*next_object_id = *next_object_id + 1;
|
*next_object_id += 1;
|
||||||
|
|
||||||
Ok(Tile::Object(Box::new(def)))
|
Ok(Tile::Object(Box::new(def)))
|
||||||
},
|
},
|
||||||
@@ -336,7 +327,7 @@ impl IntoTile for TileSpec {
|
|||||||
queue: ObjQueue::new(),
|
queue: ObjQueue::new(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
*next_object_id = *next_object_id + 1;
|
*next_object_id += 1;
|
||||||
Ok(Tile::Object(Box::new(def)))
|
Ok(Tile::Object(Box::new(def)))
|
||||||
} else {
|
} else {
|
||||||
Err(format!("Unknown builtin kind {}", kind))
|
Err(format!("Unknown builtin kind {}", kind))
|
||||||
|
|||||||
+10
-6
@@ -101,7 +101,7 @@ impl Registerable for Direction {
|
|||||||
fn register(engine: &mut Engine, _log_sink: LogSink) {
|
fn register(engine: &mut Engine, _log_sink: LogSink) {
|
||||||
engine.register_type_with_name::<Direction>("Direction")
|
engine.register_type_with_name::<Direction>("Direction")
|
||||||
.register_get("opposite", |dir: &mut Direction| dir.opposite())
|
.register_get("opposite", |dir: &mut Direction| dir.opposite())
|
||||||
.register_fn("from_point", |dir: &mut Direction, x: i64, y: i64| Point::from(dir.from_point((x, y))))
|
.register_fn("from_point", |dir: &mut Direction, x: i64, y: i64| dir.from_point((x, y)))
|
||||||
// The Point overload, so a script can walk a coordinate along an axis
|
// The Point overload, so a script can walk a coordinate along an axis
|
||||||
// (`p = d.from_point(p)`) without unpacking it into two ints.
|
// (`p = d.from_point(p)`) without unpacking it into two ints.
|
||||||
.register_fn("from_point", |dir: &mut Direction, p: Point| dir.from_point(p));
|
.register_fn("from_point", |dir: &mut Direction, p: Point| dir.from_point(p));
|
||||||
@@ -126,12 +126,16 @@ impl From<(i32, i32)> for Point {
|
|||||||
fn from((x, y): (i32, i32)) -> Self { Self { x: x as i64, y: y as i64 } }
|
fn from((x, y): (i32, i32)) -> Self { Self { x: x as i64, y: y as i64 } }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<(i64, i64)> for Point {
|
impl From<Point> for (i64, i64) {
|
||||||
fn into(self) -> (i64, i64) { (self.x, self.y) }
|
fn from(p: Point) -> Self { (p.x, p.y) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<(usize, usize)> for Point {
|
impl From<Point> for (usize, usize) {
|
||||||
fn into(self) -> (usize, usize) { (self.x as usize, self.y as usize) }
|
fn from(p: Point) -> Self { (p.x as usize, p.y as usize) }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Point> for (i32, i32) {
|
||||||
|
fn from(p: Point) -> Self { (p.x as i32, p.y as i32) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Point {
|
impl Display for Point {
|
||||||
@@ -144,7 +148,7 @@ impl Point {
|
|||||||
pub fn ux(&self) -> usize { self.x as usize }
|
pub fn ux(&self) -> usize { self.x as usize }
|
||||||
pub fn uy(&self) -> usize { self.y as usize }
|
pub fn uy(&self) -> usize { self.y as usize }
|
||||||
pub fn in_dir(self, dir: Direction) -> Self {
|
pub fn in_dir(self, dir: Direction) -> Self {
|
||||||
dir.from_point(self).into()
|
dir.from_point(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ mod tests {
|
|||||||
/// original board untouched (the property the editor's playtest relies on).
|
/// original board untouched (the property the editor's playtest relies on).
|
||||||
#[test]
|
#[test]
|
||||||
fn deep_clone_isolates_boards() {
|
fn deep_clone_isolates_boards() {
|
||||||
let mut board = open_board(3, 1, (0, 0));
|
let board = open_board(3, 1, (0, 0));
|
||||||
let mut boards = HashMap::new();
|
let mut boards = HashMap::new();
|
||||||
boards.insert("start".to_string(), Rc::new(RefCell::new(board)));
|
boards.insert("start".to_string(), Rc::new(RefCell::new(board)));
|
||||||
let world = World {
|
let world = World {
|
||||||
|
|||||||
Reference in New Issue
Block a user