Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
204 lines (168 sloc) 6.02 KB
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
// use chrono::{DateTime, TimeZone, NaiveDateTime, Utc};
#[wasm_bindgen]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SkillList {
name: String,
attribute: String,
is_knowledge: bool,
language: bool,
always_language: bool,
base_parry: bool,
}
#[wasm_bindgen]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Book {
id: u32,
active: bool,
name: String,
image_upload: String,
short_name: String,
publisher: String,
published: String,
core: bool,
primary: bool,
buylink : String,
swade_optimized: bool,
access_anonymous: bool,
access_registered: bool,
access_wildcard: bool,
access_developer: bool,
access_admin: bool,
access_premium: bool, // old database field.
setting_rules: Vec<String>,
knowledge_list: Vec<String>,
// skill_list: Vec<SkillList>,
add_skills: Vec<String>,
del_skills: Vec<String>,
core_skills: Vec<String>,
has_charisma: bool,
uses_xp: bool,
starting_skill_points: i32,
starting_attribute_points: i32,
language_list: Vec<String>,
created_by: i32,
created_on: String, // until I get a date time object
logo_upload: String,
deleted: i32,
deleted_by: i32,
deleted_on: String, // until I get a date time object
updated_by: i32,
updated_on: String, // until I get a date time object
created_by_name: String,
updated_by_name: String,
deleted_by_name: String,
}
#[wasm_bindgen]
impl Book {
#[wasm_bindgen(constructor)]
pub fn new() -> Book {
Book {
id: 0,
active: false,
name: "".to_string(),
image_upload: "".to_string(),
short_name: "".to_string(),
publisher: "".to_string(),
published: "".to_string(),
core: false,
primary: false,
buylink : "".to_string(),
swade_optimized: false,
access_anonymous: false,
access_registered: false,
access_wildcard: false,
access_developer: false,
access_admin: false,
access_premium: false, // old database field.
setting_rules: Vec::new(),
knowledge_list: Vec::new(),
// skill_list: Vec<SkillList>,
add_skills: Vec::new(),
del_skills: Vec::new(),
core_skills: Vec::new(),
has_charisma: false,
uses_xp: false,
starting_skill_points: 0,
starting_attribute_points: 0,
language_list: Vec::new(),
created_by: 0,
created_on: "".to_string(), // until I get a date time object
logo_upload: "".to_string(),
deleted: 0,
deleted_by: 0,
deleted_on: "".to_string(), // until I get a date time object
updated_by: 0,
updated_on: "".to_string(), // until I get a date time object
created_by_name: "".to_string(),
updated_by_name: "".to_string(),
deleted_by_name: "".to_string(),
}
}
#[wasm_bindgen(setter)]
pub fn set_name(&mut self, new_value: String) {
self.name = new_value.to_string();
}
#[wasm_bindgen(getter)]
pub fn name(&self) -> String {
return self.name.to_string();
}
pub fn get_name(&self) -> String {
return self.name.to_string();
}
#[wasm_bindgen(setter = shortName)]
pub fn set_short_name(&mut self, new_value: String) {
self.short_name = new_value.to_string();
}
#[wasm_bindgen(getter = shortName)]
pub fn short_name(&self) -> String {
return self.short_name.to_string();
}
// pub fn exportJSON(&self) -> String {
// serde
// }
// pub fn export(&self) -> BookExport {
// BookExport {
// id: self.id,
// active: self.active,
// name: self.name.as_ref(),
// image_upload: self.image_upload.to_string(),
// short_name: self.short_name.to_string(),
// publisher: self.publisher.to_string(),
// published: self.published.to_string(),
// core: self.core,
// primary: self.primary,
// buylink : self.name.to_string(),
// swade_optimized: self.swade_optimized,
// access_anonymous: self.access_anonymous,
// access_registered: self.access_registered,
// access_wildcard: self.access_wildcard,
// access_developer: self.access_developer,
// access_admin: self.access_admin,
// access_premium: self.access_premium, // old database field.
// setting_rules: self.setting_rules.clone(),
// knowledge_list: self.knowledge_list.clone(),
// // skill_list: Vec<SkillList>,
// add_skills: self.add_skills.clone(),
// del_skills: self.del_skills.clone(),
// core_skills: self.core_skills.clone(),
// has_charisma: self.has_charisma,
// uses_xp: self.uses_xp,
// starting_skill_points: self.starting_skill_points,
// starting_attribute_points: self.starting_attribute_points,
// language_list: self.language_list.clone(),
// created_by: self.created_by,
// created_on: self.created_on.to_string(), // until I get a date time object
// logo_upload: self.logo_upload.to_string(),
// deleted: self.deleted,
// deleted_by: self.deleted_by,
// deleted_on: self.deleted_on.to_string(), // until I get a date time object
// updated_by: self.updated_by,
// updated_on: self.updated_on.to_string(), // until I get a date time object
// created_by_name: self.created_by_name.to_string(),
// updated_by_name: self.updated_by_name.to_string(),
// deleted_by_name: self.deleted_by_name.to_string(),
// }
// }
}
You can’t perform that action at this time.