rpg_stat/
compass.rs

1/*!
2# Compass
3The direction module
4
5All of these default to None
6
7## Basic
8
9intended for the most basic clicker-style RPG
10
11```
12// basic compass has Forward/Backward
13use rpg_stat::compass::Basic as Compass;
14// this is what I want
15let direction = Compass::Forward;
16```
17
18## Normal
19
20Intended for standard top-down world view RPG
21
22```
23// normal compass has Up, Down, Left, Right
24use rpg_stat::compass::Normal as Compass;
25// this is what I want
26let direction = Compass::Up;
27```
28
29## Advanced
30
31```
32// advanced compass has the four cardinal and four intercardinal directions
33use rpg_stat::compass::Advanced as Compass;
34// this is where to go in winter
35let direction = Compass::South;
36```
37
38*/
39use std::fmt;
40use crate::random::Random;
41use serde::{Deserialize, Serialize};
42#[cfg(feature = "fltkform")]
43use fltk::{prelude::*, *};
44#[cfg(feature = "fltkform")]
45use fltk_form_derive::*;
46#[cfg(feature = "fltkform")]
47use fltk_form::FltkForm;
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
50#[cfg_attr(feature = "fltkform", derive(FltkForm))]
51/*
52# Basic
531-D movement, like time
54*/
55pub enum Basic {
56    /// 
57    Forward,
58    /// 
59    Backward,
60    /// Nothing
61    None,
62}
63impl Default for Basic {
64    fn default() -> Self {
65        Self::None
66    }
67}
68impl fmt::Display for Basic {
69    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
70        let v:String;
71        match *self {
72            Basic::Forward => v = String::from("Forward"),
73            Basic::Backward => v = String::from("Backward"),
74            _=> v = String::from("None"),
75        }
76        write!(f, "{}", v.as_str())
77    }
78}
79impl Random for Basic {
80    type Type = Basic;
81    fn random_type(&self) -> Self::Type {
82        let max = 2;
83        let val = self.random_rate(max);
84        match val {
85            0 => Basic::Forward,
86            1 => Basic::Backward,
87            _=> Basic::None,
88        }
89    }
90    
91}
92
93#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
94#[cfg_attr(feature = "fltkform", derive(FltkForm))]
95/*
96# Normal
972-D movement
98*/
99pub enum Normal {
100    /// Going up the y axis
101    Up,
102    /// Going down the y axis
103    Down,
104    /// Going up the x axis
105    Left,
106    /// Going down the x axis
107    Right,
108    /// Nothing
109    None,
110}
111impl Default for Normal {
112    fn default() -> Self {
113        Self::None
114    }
115}
116impl fmt::Display for Normal {
117    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
118        let v:String;
119        match *self {
120            Normal::Up => v = String::from("Up"),
121            Normal::Down => v = String::from("Down"),
122            Normal::Left => v = String::from("Left"),
123            Normal::Right => v = String::from("Right"),
124            _=> v = String::from("None"),
125        }
126        write!(f, "{}", v.as_str())
127    }
128}
129impl Random for Normal {
130    type Type = Normal;
131    fn random_type(&self) -> Self::Type {
132        let max = 4;
133        let val = self.random_rate(max);
134        match val {
135            0 => Normal::Up,
136            1 => Normal::Down,
137            2 => Normal::Left,
138            3 => Normal::Right,
139            _=> Normal::None,
140        }
141    }
142    
143}
144
145#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
146#[cfg_attr(feature = "fltkform", derive(FltkForm))]
147/*
148# Advanced
149The four cardinal directions and the four intercardinal directions
150*/
151pub enum Advanced {
152    /// Opposite of South, up
153    North,
154    /// Opposite of SouthWest, up-right
155    NorthEast,
156    /// Opposite of West, right
157    East,
158    /// Opposite of NorthWest, down-right
159    SouthEast,
160    /// Opposite of North, down
161    South,
162    /// Opposite of NorthEast, down-left
163    SouthWest,
164    /// Opposite of East, left
165    West,
166    /// Opposite of SouthEast, up-left
167    NorthWest,
168    /// Nothing
169    None,
170}
171impl Default for Advanced {
172    fn default() -> Self {
173        Self::None
174    }
175}
176impl fmt::Display for Advanced {
177    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
178        let v:String;
179        match *self {
180            Advanced::North => v = String::from("North"),
181            Advanced::NorthEast => v = String::from("NorthEast"),
182            Advanced::East => v = String::from("East"),
183            Advanced::SouthEast => v = String::from("SouthEast"),
184            Advanced::South => v = String::from("South"),
185            Advanced::SouthWest => v = String::from("SouthWest"),
186            Advanced::West => v = String::from("West"),
187            Advanced::NorthWest => v = String::from("NorthWest"),
188            _=> v = String::from("None"),
189        }
190        write!(f, "{}", v.as_str())
191    }
192}
193impl Random for Advanced {
194    type Type = Advanced;
195    fn random_type(&self) -> Self::Type {
196        let max = 8;
197        let val = self.random_rate(max);
198        match val {
199            0 => Advanced::North,
200            1 => Advanced::NorthEast,
201            2 => Advanced::East,
202            3 => Advanced::SouthEast,
203            4 => Advanced::South,
204            5 => Advanced::SouthWest,
205            6 => Advanced::West,
206            7 => Advanced::NorthWest,
207            _=> Advanced::None,
208        }
209    }
210    
211}