Overhauled data models to make actions and libraries more universal
This commit is contained in:
@@ -1,57 +1,44 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import schema from '/imports/api/schema.js';
|
||||
import {makeParent} from "/imports/api/parenting.js";
|
||||
import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js";
|
||||
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
|
||||
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
|
||||
|
||||
//set up the collection for containers
|
||||
let Containers = new Mongo.Collection("containers");
|
||||
|
||||
let containerSchema = schema({
|
||||
name: {type: String, optional: true, trim: false},
|
||||
charId: {type: String, regEx: SimpleSchema.RegEx.Id, index: 1},
|
||||
isCarried: {type: Boolean},
|
||||
weight: {type: Number, min: 0, defaultValue: 0},
|
||||
value: {type: Number, min: 0, defaultValue: 0},
|
||||
description:{type: String, optional: true, trim: false},
|
||||
});
|
||||
|
||||
Containers.attachSchema(containerSchema);
|
||||
Containers.attachSchema(ColorSchema);
|
||||
|
||||
Containers.helpers({
|
||||
contentsValue: function(){
|
||||
var value = 0;
|
||||
Items.find(
|
||||
{"parent.id": this._id},
|
||||
{fields: {quantity: 1, value: 1}}
|
||||
).forEach(function(item){
|
||||
value += item.totalValue();
|
||||
});
|
||||
return value;
|
||||
let ContainerSchema = schema({
|
||||
name: {
|
||||
type: String,
|
||||
optional: true,
|
||||
trim: false
|
||||
},
|
||||
totalValue: function(){
|
||||
return this.contentsValue() + this.value;
|
||||
isCarried: {
|
||||
type: Boolean,
|
||||
defaultValue: true,
|
||||
},
|
||||
contentsWeight: function(){
|
||||
var weight = 0;
|
||||
Items.find(
|
||||
{"parent.id": this._id},
|
||||
{fields: {quantity: 1, weight: 1}}
|
||||
).forEach(function(item){
|
||||
weight += item.totalWeight();
|
||||
});
|
||||
return weight;
|
||||
weight: {
|
||||
type: Number,
|
||||
min: 0,
|
||||
defaultValue: 0
|
||||
},
|
||||
totalWeight: function(){
|
||||
return this.contentsWeight() + this.weight;
|
||||
value: {
|
||||
type: Number,
|
||||
min: 0,
|
||||
defaultValue: 0
|
||||
},
|
||||
moveToCharacter: function(characterId){
|
||||
if (this.charId === characterId) return;
|
||||
Items.update(this._id, {$set: {charId: characterId}});
|
||||
description: {
|
||||
type: String,
|
||||
optional: true,
|
||||
trim: false
|
||||
},
|
||||
});
|
||||
|
||||
// Containers.attachBehaviour("softRemovable");
|
||||
makeParent(Containers); //parents of items
|
||||
ContainerSchema.extend(ColorSchema);
|
||||
|
||||
Containers.attachSchema(ContainerSchema);
|
||||
Containers.attachSchema(PropertySchema);
|
||||
Containers.attachSchema(ChildSchema);
|
||||
|
||||
export default Containers;
|
||||
export { ContainerSchema };
|
||||
|
||||
Reference in New Issue
Block a user