94 lines
4.1 KiB
JavaScript
94 lines
4.1 KiB
JavaScript
module.exports = {
|
|
GifData: class {
|
|
constructor() {
|
|
this.id = 0;
|
|
this.name = "";
|
|
this.url = "";
|
|
}
|
|
|
|
// Initial GifData configuration
|
|
// Can also be used to update the data piecemeal
|
|
setInfo(name, url, id) {
|
|
// Check for existing or incoming name
|
|
if ((this.name === "") && (typeof name !== 'string')) throw `Error: This Gif doesn't have existing name, and no name is going to be set.`;
|
|
// Check for existing content or incoming content
|
|
if ((this.url === "") && (typeof url !== 'string')) throw `Error: This Gif doesn't have existing url, and no url is going to be set.`;
|
|
|
|
// Property is set if the variable is the right type,
|
|
// otherwise it keeps the existing property
|
|
this.id = typeof id === 'number' ? id : this.id;
|
|
this.name = typeof name === 'string' ? name : this.name;
|
|
this.url = typeof url === 'string' ? url : this.url;
|
|
|
|
return this; // For chaining
|
|
}
|
|
},
|
|
PastaData: class {
|
|
constructor() {
|
|
this.id = 0;
|
|
this.name = "";
|
|
this.content = "";
|
|
this.iconUrl = "";
|
|
}
|
|
|
|
// Initial PastaData configuration
|
|
// Can also be used to update the data piecemeal
|
|
setInfo(name, content, iconUrl, id) {
|
|
// Check for existing or incoming name
|
|
if ((this.name === "") && (typeof name !== 'string')) throw `Error: This Pasta doesn't have existing name, and no name is going to be set.`;
|
|
// Check for existing content or incoming content
|
|
if ((this.content === "") && (typeof content !== 'string')) throw `Error: This Pasta doesn't have existing content, and no content is going to be set.`;
|
|
|
|
// Property is set if the variable is the right type,
|
|
// otherwise it keeps the existing property
|
|
this.id = typeof id === 'number' ? id : this.id;
|
|
this.name = typeof name === 'string' ? name : this.name;
|
|
this.content = typeof content === 'string' ? content : this.content;
|
|
this.iconUrl = typeof iconUrl === 'string' ? iconUrl : this.iconUrl;
|
|
|
|
return this; // For chaining
|
|
}
|
|
},
|
|
// StrainData
|
|
StrainData: class {
|
|
constructor() {
|
|
this.id = 0;
|
|
this.name = "Unknown";
|
|
this.type = "Unknown";
|
|
this.effects = "Unknown";
|
|
this.flavor = "Unknown";
|
|
this.rating = "0.0";
|
|
this.description = "Unknown";
|
|
}
|
|
|
|
// Initial Strain configuration
|
|
// Can also be used to update the data piecemeal
|
|
setInfo(name, details, id) {
|
|
/* details contains all the optional pieces of data
|
|
This is to prevent having to call setInfo(name, undefined, undefined, undefined, 0) or something
|
|
details: {
|
|
type: String,
|
|
effects: String,
|
|
rating: String,
|
|
description: String
|
|
}
|
|
*/
|
|
|
|
// Check for existing or incoming name
|
|
if ((this.name === "") && (typeof name !== 'string')) throw `Error: This Strain doesn't have existing name, and no name is going to be set.`;
|
|
|
|
// Property is set if the variable is the right type,
|
|
// otherwise it keeps the existing property
|
|
this.id = typeof id === 'number' ? id : this.id;
|
|
this.name = typeof name === 'string' ? name : this.name;
|
|
this.type = typeof details.type === 'string' ? details.type : this.type;
|
|
this.effects = typeof details.effects === 'string' ? details.effects : this.effects;
|
|
this.flavor = typeof details.flavor === 'string' ? details.flavor : this.flavor;
|
|
this.rating = typeof details.rating === 'string' ? details.rating : this.rating;
|
|
this.description = typeof details.description === 'string' ? details.description : this.description;
|
|
|
|
|
|
return this; // For chaining
|
|
}
|
|
}
|
|
} |