1use std::fmt;
11use std::fmt::Debug;
12extern crate num;
13use serde::{Deserialize, Serialize};
14
15#[cfg(feature = "fltkform")]
16use fltk::{prelude::*, *};
17#[cfg(feature = "fltkform")]
18use fltk_form_derive::*;
19#[cfg(feature = "fltkform")]
20use fltk_form::FltkForm;
21
22use crate::random::Random;
24
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
31#[cfg_attr(feature = "fltkform", derive(FltkForm))]
32pub enum State {
33 Broken,
35 Ordered,
37}
38impl fmt::Display for State {
39 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40 let v:String;
41 match *self {
42 State::Broken => v = String::from("Broken"),
43 State::Ordered => v = String::from("Ordered"),
44
45 }
46 write!(f, "{}", v.as_str())
47 }
48}
49impl Default for State {
50 fn default() -> Self {
51 Self::Ordered
52 }
53}
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
59#[cfg_attr(feature = "fltkform", derive(FltkForm))]
60pub enum Purpose {
61 Random,
62 Story,
63 Task,
64}
65impl fmt::Display for Purpose {
66 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
67 let v:String;
68 match *self {
69 Purpose::Random => v = String::from("Random"),
70 Purpose::Story => v = String::from("Story"),
71 Purpose::Task => v = String::from("Task"),
72
73 }
74 write!(f, "{}", v.as_str())
75 }
76}
77impl Default for Purpose {
78 fn default() -> Self {
79 Self::Random
80 }
81}
82
83#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
88#[cfg_attr(feature = "fltkform", derive(FltkForm))]
89pub enum Conversation {
90 Advice,
92 Details,
94 Dreams,
96 Event,
98 Fourth,
100 Greeting,
102 Hint,
104 Jokes,
106 Problems,
108 Quest,
110 Quotes,
112 SmallTalk,
114 Surroundings,
116}
117impl fmt::Display for Conversation {
118 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
119 let v:String;
120 match *self {
121 Conversation::Quest => v = String::from("Quest"),
122 Conversation::Hint => v = String::from("Hint"),
123 Conversation::Advice => v = String::from("Advice"),
124 Conversation::Greeting => v = String::from("Greeting"),
125 Conversation::SmallTalk => v = String::from("SmallTalk"),
126 Conversation::Event => v = String::from("Event"),
127 Conversation::Surroundings => v = String::from("Surroundings"),
128 Conversation::Problems => v = String::from("Problems"),
129 Conversation::Dreams => v = String::from("Dreams"),
130 Conversation::Jokes => v = String::from("Jokes"),
131 Conversation::Quotes => v = String::from("Quotes"),
132 Conversation::Details => v = String::from("Details"),
133 Conversation::Fourth => v = String::from("Fourth"),
134
135 }
136 write!(f, "{}", v.as_str())
137 }
138}
139impl Default for Conversation {
140 fn default() -> Self {
141 Self::SmallTalk
142 }
143}
144
145#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
148#[cfg_attr(feature = "fltkform", derive(FltkForm))]
149pub struct Script {
150 pub lines:Vec<u32>,
152 pub conversation:Conversation,
154 pub file:String,
156 pub random:bool,
158 pub finished:bool
160}
161impl Random for Script{
162 type Type = Script;
163 fn random_type(&self) -> Self::Type {
164 Self::empty()
165 }
166}
167impl Script {
168 #[allow(dead_code)]
170 pub fn empty() -> Self where Self:Sized {
171 Script {
172 lines:vec![],
173 conversation:Conversation::SmallTalk,
174 file:String::from(""),
175 random:true,
176 finished:false,
177 }
178 }
179 #[allow(dead_code)]
180 pub fn default_words(&self)-> String {
181 if self.half() {
182 return String::from("Math is way more exciting than people really think it is...")
183 }
184 String::from("Aren't role playing games fascinating!")
185 }
186 #[allow(dead_code)]
187 pub fn speak(&self) -> Option<String> {
188 if self.finished {
189 return None
190 }
191 if self.file != *"" {
192 if !self.random {
193 }
197 return Some(self.default_words())
199 }
200 Some(self.default_words())
201 }
202}
203
204#[allow(clippy::upper_case_acronyms)]
209#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
210#[cfg_attr(feature = "fltkform", derive(FltkForm))]
211pub struct NPC {
212 pub state:State,
214 pub purpose:Purpose,
216 pub meet:Conversation, pub conversations:Vec<Conversation>, }
221impl NPC {
222
223 #[allow(dead_code)]
225 pub fn empty() -> Self where Self:Sized {
226 NPC {
227 state:State::Broken,
228 purpose:Purpose::Random,
229 meet:Conversation::Greeting,
230 conversations:vec!{},
231 }
232 }
233
234 pub fn basic() -> Self where Self:Sized {
236 let conversations:Vec<Conversation> = vec![ Conversation::SmallTalk, Conversation::Surroundings, Conversation::Quotes, Conversation::Details, Conversation::Advice ];
237 NPC {
238 state:State::Ordered,
239 purpose:Purpose::Random,
240 meet:Conversation::Greeting,
241 conversations,
242 }
243 }
244}
245impl Default for NPC {
246 fn default() -> Self where Self:Sized {
247 Self::basic()
248 }
249}