use std::fmt;
use std::fmt::Debug;
extern crate num;
use serde::{Deserialize, Serialize};
#[cfg(feature = "fltkform")]
use fltk::{prelude::*, *};
#[cfg(feature = "fltkform")]
use fltk_form_derive::*;
#[cfg(feature = "fltkform")]
use fltk_form::FltkForm;
use crate::random::Random;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "fltkform", derive(FltkForm))]
pub enum State {
Broken,
Ordered,
}
impl fmt::Display for State {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let v:String;
match *self {
State::Broken => v = String::from("Broken"),
State::Ordered => v = String::from("Ordered"),
}
write!(f, "{}", v.as_str())
}
}
impl Default for State {
fn default() -> Self {
Self::Ordered
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "fltkform", derive(FltkForm))]
pub enum Purpose {
Random,
Story,
Task,
}
impl fmt::Display for Purpose {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let v:String;
match *self {
Purpose::Random => v = String::from("Random"),
Purpose::Story => v = String::from("Story"),
Purpose::Task => v = String::from("Task"),
}
write!(f, "{}", v.as_str())
}
}
impl Default for Purpose {
fn default() -> Self {
Self::Random
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "fltkform", derive(FltkForm))]
pub enum Conversation {
Advice,
Details,
Dreams,
Event,
Fourth,
Greeting,
Hint,
Jokes,
Problems,
Quest,
Quotes,
SmallTalk,
Surroundings,
}
impl fmt::Display for Conversation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let v:String;
match *self {
Conversation::Quest => v = String::from("Quest"),
Conversation::Hint => v = String::from("Hint"),
Conversation::Advice => v = String::from("Advice"),
Conversation::Greeting => v = String::from("Greeting"),
Conversation::SmallTalk => v = String::from("SmallTalk"),
Conversation::Event => v = String::from("Event"),
Conversation::Surroundings => v = String::from("Surroundings"),
Conversation::Problems => v = String::from("Problems"),
Conversation::Dreams => v = String::from("Dreams"),
Conversation::Jokes => v = String::from("Jokes"),
Conversation::Quotes => v = String::from("Quotes"),
Conversation::Details => v = String::from("Details"),
Conversation::Fourth => v = String::from("Fourth"),
}
write!(f, "{}", v.as_str())
}
}
impl Default for Conversation {
fn default() -> Self {
Self::SmallTalk
}
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "fltkform", derive(FltkForm))]
pub struct Script {
pub lines:Vec<u32>,
pub conversation:Conversation,
pub file:String,
pub random:bool,
pub finished:bool
}
impl Random for Script{
type Type = Script;
fn random_type(&self) -> Self::Type {
Self::empty()
}
}
impl Script {
#[allow(dead_code)]
pub fn empty() -> Self where Self:Sized {
Script {
lines:vec![],
conversation:Conversation::SmallTalk,
file:String::from(""),
random:true,
finished:false,
}
}
#[allow(dead_code)]
pub fn default_words(&self)-> String {
if self.half() {
return String::from("Math is way more exciting than people really think it is...")
}
String::from("Aren't role playing games fascinating!")
}
#[allow(dead_code)]
pub fn speak(&self) -> Option<String> {
if self.finished {
return None
}
if self.file != *"" {
if !self.random {
}
return Some(self.default_words())
}
Some(self.default_words())
}
}
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "fltkform", derive(FltkForm))]
pub struct NPC {
pub state:State,
pub purpose:Purpose,
pub meet:Conversation, pub conversations:Vec<Conversation>, }
impl NPC {
#[allow(dead_code)]
pub fn empty() -> Self where Self:Sized {
NPC {
state:State::Broken,
purpose:Purpose::Random,
meet:Conversation::Greeting,
conversations:vec!{},
}
}
pub fn basic() -> Self where Self:Sized {
let conversations:Vec<Conversation> = vec![ Conversation::SmallTalk, Conversation::Surroundings, Conversation::Quotes, Conversation::Details, Conversation::Advice ];
NPC {
state:State::Ordered,
purpose:Purpose::Random,
meet:Conversation::Greeting,
conversations,
}
}
}
impl Default for NPC {
fn default() -> Self where Self:Sized {
Self::basic()
}
}