1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
mod relative;
pub mod tooltip;
pub mod persona;

use std::fmt;
use std::str;

use ::graphic;
use ::libc;

use self::tooltip::Tooltip;
use self::persona::{Persona, Position};
pub use self::relative::Relative;

#[repr(C)]
#[derive(Copy)]
pub struct LibraryState {
  persona: Persona,
  tooltip: Tooltip,
  unmount: libc::c_uchar,
  lock: libc::c_uchar,
}

impl LibraryState {
    pub fn is_unmounted(&self) -> bool {
        self.unmount.ne(&b'\0')
    }

    pub fn is_locked(&self) -> bool {
        self.lock.ne(&b'\0')
    }

    pub fn get_sheet(&self) -> &graphic::Sheet {
        self.persona.get_sheet()
    }

    pub fn get_tooltip(&self) -> &Tooltip {
        &self.tooltip
    }

    pub fn get_persona(&self) -> &Persona
    { &self.persona }

    pub fn get_position(&self) -> &Position {
        self.persona.get_position()
    }

    /// The function `get_emotion` returns a reference on a ffi argument
    /// of detailed emotion by draw.
    pub fn get_emotion(&self)
        -> &[[graphic::Tuple; graphic::SPEC_MAX_XY];
    graphic::SPEC_MAX_DRAW] {
        self.persona.get_emotion()
    }

    pub fn set_tooltip_message(&mut self,
        message: String,
    ) {
        self.tooltip.set_message(message);
    }

    pub fn set_tooltip_cardinal(&mut self, cardinal: Relative) {
        self.tooltip.set_cardinal(cardinal);
    }

    pub fn set_persona_sheet(&mut self, sheet: graphic::Sheet) {
        self.persona.set_sheet(sheet);
    }

    pub fn set_persona_position(&mut self, position: Position) {
        self.persona.set_position(position);
    }
}

impl Clone for LibraryState {
    fn clone(&self) -> Self {
        LibraryState {
            persona: self.persona,
            tooltip: self.tooltip,
            unmount: self.unmount,
            lock: self.lock,
        }
    }
}

impl fmt::Debug for LibraryState {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "LibraryState {{ persona: {:?}, tooltip: {:?}, unmount: {}, lock: {:?} }}",
               self.persona,
               self.tooltip,
               self.unmount,
               self.lock.ne(&0),
        )
    }
}

impl Default for LibraryState {
    fn default() -> Self {
        LibraryState {
            persona: Persona::default(),
            tooltip: Tooltip::default(),
            unmount: b'\0',
            lock: b'\0',
        }
    }
}