diff options
| author | Arne Dußin | 2021-01-27 14:01:50 +0100 |
|---|---|---|
| committer | Arne Dußin | 2021-02-02 22:16:15 +0100 |
| commit | f92e9f6f07b1e3834c2ca58ce3510734819d08e4 (patch) | |
| tree | 20e3d3afce342a56ae98f6c20491482ccd2b5c6b /src/map/wall.rs | |
| parent | c60a6d07efb120724b308e29e8e70f27c87c952d (diff) | |
| download | graf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.tar.gz graf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.zip | |
Rework graf karto to fit the client/server structure
Diffstat (limited to 'src/map/wall.rs')
| -rw-r--r-- | src/map/wall.rs | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/src/map/wall.rs b/src/map/wall.rs deleted file mode 100644 index f1748bb..0000000 --- a/src/map/wall.rs +++ /dev/null @@ -1,125 +0,0 @@ -//! Walls, solid barriers that are generally unscaleable. -//! -//! This interpretation is generally up to the GM to decide, but generally speaking, a wall cannot be -//! crossed by a player. If special conditions apply (for instance, when the player wants to scale the -//! wall), a check is necessary. If a check is not necessary, then maybe you were not thinking about -//! a wall. - -use super::Mappable; -use crate::colours::DEFAULT_COLOURS; -use crate::math::{LineSegment, Rect, Vec2}; -use crate::transform::Transform; -use crate::transformable::NonRigidTransformable; -use nalgebra::Matrix3; -use raylib::drawing::{RaylibDraw, RaylibDrawHandle}; -use std::ops::{Deref, DerefMut}; - -/// The data which defines a wall segment completely for serialisation. -pub type WallData = LineSegment<f64>; - -/// A solid wall a player cannot go through, except if special conditions apply. -pub struct Wall { - data: WallData, - selected: bool, - round_start: bool, - round_end: bool, -} - -impl Wall { - /// Create a new wall from the deserialised data and information known from internal sources. - pub fn from_data(data: WallData, round_start: bool, round_end: bool) -> Self { - Self { - data, - selected: false, - round_start, - round_end, - } - } - - /// Get the internal data for serialisation - pub fn data(&self) -> &WallData { - &self.data - } -} - -fn draw_round_corner( - rld: &mut RaylibDrawHandle, - pos_px: Vec2<f64>, - transform: &Transform, - selected: bool, -) { - rld.draw_circle_v( - pos_px, - transform.length_m_to_px(0.05) as f32, - if selected { - DEFAULT_COLOURS.wall_selected - } else { - DEFAULT_COLOURS.wall_normal - }, - ); -} - -impl Mappable for Wall { - fn draw(&self, rld: &mut RaylibDrawHandle, transform: &Transform) { - let start_px = transform.point_m_to_px(&self.data.start); - let end_px = transform.point_m_to_px(&self.data.end); - rld.draw_line_ex( - start_px, - end_px, - transform.length_m_to_px(0.1) as f32, - if self.selected() { - DEFAULT_COLOURS.wall_selected - } else { - DEFAULT_COLOURS.wall_normal - }, - ); - - if self.round_start { - draw_round_corner(rld, start_px, transform, self.selected()); - } - if self.round_end { - draw_round_corner(rld, end_px, transform, self.selected()); - } - } - - fn set_selected(&mut self, selected: bool) { - self.selected = selected; - } - - fn selected(&self) -> bool { - self.selected - } - - fn bounding_rect(&self) -> Rect<f64> { - Rect::bounding_rect(self.data.start, self.data.end) - } - - fn as_non_rigid(&self) -> Option<&dyn NonRigidTransformable> { - Some(self as &dyn NonRigidTransformable) - } - - fn as_non_rigid_mut(&mut self) -> Option<&mut dyn NonRigidTransformable> { - Some(self as &mut dyn NonRigidTransformable) - } -} - -impl NonRigidTransformable for Wall { - fn apply_matrix(&mut self, matrix: &Matrix3<f64>) { - self.data.start = matrix.transform_point(&self.data.start.into()).into(); - self.data.end = matrix.transform_point(&self.data.end.into()).into(); - } -} - -impl Deref for Wall { - type Target = WallData; - - fn deref(&self) -> &Self::Target { - &self.data - } -} - -impl DerefMut for Wall { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.data - } -} |
