implemented UI for new parenting
This commit is contained in:
@@ -60,7 +60,11 @@ Characters.after.insert(function (userId, char) {
|
|||||||
name: "Constitution modifier for each level",
|
name: "Constitution modifier for each level",
|
||||||
stat: "hitPoints",
|
stat: "hitPoints",
|
||||||
operation: "add",
|
operation: "add",
|
||||||
calculation: "level * constitutionMod"
|
calculation: "level * constitutionMod",
|
||||||
|
parent: {
|
||||||
|
id: char._id,
|
||||||
|
collection: "Characters"
|
||||||
|
}
|
||||||
});
|
});
|
||||||
Effects.insert({
|
Effects.insert({
|
||||||
charId: char._id,
|
charId: char._id,
|
||||||
@@ -68,7 +72,11 @@ Characters.after.insert(function (userId, char) {
|
|||||||
name: "Proficiency bonus by level",
|
name: "Proficiency bonus by level",
|
||||||
stat: "proficiencyBonus",
|
stat: "proficiencyBonus",
|
||||||
operation: "add",
|
operation: "add",
|
||||||
calculation: "floor(level / 4 + 1.75)"
|
calculation: "floor(level / 4 + 1.75)",
|
||||||
|
parent: {
|
||||||
|
id: char._id,
|
||||||
|
collection: "Characters"
|
||||||
|
}
|
||||||
});
|
});
|
||||||
Effects.insert({
|
Effects.insert({
|
||||||
charId: char._id,
|
charId: char._id,
|
||||||
@@ -76,7 +84,11 @@ Characters.after.insert(function (userId, char) {
|
|||||||
name: "Dexterity Armor Bonus",
|
name: "Dexterity Armor Bonus",
|
||||||
stat: "armor",
|
stat: "armor",
|
||||||
operation: "add",
|
operation: "add",
|
||||||
calculation: "dexterityArmor"
|
calculation: "dexterityArmor",
|
||||||
|
parent: {
|
||||||
|
id: char._id,
|
||||||
|
collection: "Characters"
|
||||||
|
}
|
||||||
});
|
});
|
||||||
Effects.insert({
|
Effects.insert({
|
||||||
charId: char._id,
|
charId: char._id,
|
||||||
@@ -84,7 +96,11 @@ Characters.after.insert(function (userId, char) {
|
|||||||
name: "Natural Armor",
|
name: "Natural Armor",
|
||||||
stat: "armor",
|
stat: "armor",
|
||||||
operation: "base",
|
operation: "base",
|
||||||
value: 10
|
value: 10,
|
||||||
|
parent: {
|
||||||
|
id: char._id,
|
||||||
|
collection: "Characters"
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ Containers.attachSchema(Schemas.Container);
|
|||||||
Containers.helpers({
|
Containers.helpers({
|
||||||
totalValue: function(){
|
totalValue: function(){
|
||||||
var value = this.value;
|
var value = this.value;
|
||||||
Items.find({container: this._id, equipped: false}, {fields: {quantity: 1, value: 1}}).forEach(function(item){
|
Items.find({"parent.id": this._id}, {fields: {quantity: 1, value: 1}}).forEach(function(item){
|
||||||
value += item.totalValue();
|
value += item.totalValue();
|
||||||
});
|
});
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
totalWeight: function(){
|
totalWeight: function(){
|
||||||
var weight = this.weight;
|
var weight = this.weight;
|
||||||
Items.find({container: this._id, equipped: false}, {fields: {quantity: 1, weight: 1}}).forEach(function(item){
|
Items.find({"parent.id": this._id}, {fields: {quantity: 1, weight: 1}}).forEach(function(item){
|
||||||
weight += item.totalWeight();
|
weight += item.totalWeight();
|
||||||
});
|
});
|
||||||
return weight;
|
return weight;
|
||||||
|
|||||||
@@ -33,17 +33,24 @@ Items.helpers({
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
equip: function(){
|
equip: function(characterId){
|
||||||
Items.update(this._id, {$set: {enabled: true}});
|
var charId = characterId || this.charId;
|
||||||
|
if(!charId || ! Characters.findOne(charId)) throw "Invalid character";
|
||||||
|
if(this.parent.collection === "Characters" && this.parent.id === charId && this.enabled) return;
|
||||||
|
Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": charId, enabled: true}});
|
||||||
},
|
},
|
||||||
unequip: function(){
|
unequip: function(){
|
||||||
|
if(!this.enabled) return;
|
||||||
Items.update(this._id, {$set: {enabled: false}});
|
Items.update(this._id, {$set: {enabled: false}});
|
||||||
},
|
},
|
||||||
moveToContainer: function(containerId){
|
moveToContainer: function(containerId){
|
||||||
|
if( !containerId || !Containers.findOne(containerId) ) throw "Invalid container";
|
||||||
|
if(this.parent.collection === "Containers" && this.parent.id === containerId && !this.enabled) return;
|
||||||
Items.update(this._id, {$set: {"parent.collection": "Containers", "parent.id": containerId, enabled: false}});
|
Items.update(this._id, {$set: {"parent.collection": "Containers", "parent.id": containerId, enabled: false}});
|
||||||
},
|
},
|
||||||
moveToCharacter: function(characterId){
|
moveToCharacter: function(characterId){
|
||||||
if(this.charId === characterId) return;
|
if(!characterId || ! Characters.findOne(characterId)) throw "Invalid character";
|
||||||
|
if(this.parent.collection === "Characters" && this.parent.id === characterId && !this.enabled) return;
|
||||||
Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": characterId, charId: characterId, enabled: false}});
|
Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": characterId, charId: characterId, enabled: false}});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<!--needs to be given charId, sourceId and type-->
|
<!--needs to be given charId, parentId and type-->
|
||||||
<template name="attackEditList">
|
<template name="attackEditList">
|
||||||
{{#if attacks.count}}
|
{{#if attacks.count}}
|
||||||
<hr style="margin: 16px 0 16px 0;">
|
<hr style="margin: 16px 0 16px 0;">
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
Template.attackEditList.helpers({
|
Template.attackEditList.helpers({
|
||||||
attacks: function(){
|
attacks: function(){
|
||||||
var cursor = Attacks.find({sourceId: this.sourceId, type: this.type});
|
var cursor = Attacks.find({"parent.id": this.parentId, type: this.type, charId: this.charId});
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Template.attackEditList.events({
|
Template.attackEditList.events({
|
||||||
"tap #addAttackButton": function(){
|
"tap #addAttackButton": function(){
|
||||||
if ( !_.isBoolean(this.enabled) ) {
|
|
||||||
this.enabled = true;
|
|
||||||
}
|
|
||||||
Attacks.insert({
|
Attacks.insert({
|
||||||
name: this.name,
|
|
||||||
charId: this.charId,
|
charId: this.charId,
|
||||||
sourceId: this.sourceId,
|
parent: {
|
||||||
|
id: this.parentId,
|
||||||
|
collection: this.parentCollection
|
||||||
|
},
|
||||||
type: this.type,
|
type: this.type,
|
||||||
enabled: this.enabled
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<template name="effectView">
|
<template name="effectView">
|
||||||
<div class="effectView" layout horizontal center>
|
<div class="effectView" layout horizontal center>
|
||||||
{{#if sourceId}}
|
{{#with statName}}
|
||||||
<div>{{sourceName}}</div>
|
|
||||||
{{else}}
|
|
||||||
<div flex>{{statName}}</div>
|
<div flex>{{statName}}</div>
|
||||||
{{/if}}
|
{{else}}
|
||||||
|
<div flex>{{sourceName}}</div>
|
||||||
|
{{/with}}
|
||||||
<div>{{operationName}}</div>
|
<div>{{operationName}}</div>
|
||||||
<div>{{statValue}}</div>
|
<div>{{statValue}}</div>
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
@@ -86,20 +86,20 @@ var operations = {
|
|||||||
|
|
||||||
Template.effectView.helpers({
|
Template.effectView.helpers({
|
||||||
sourceName: function(){
|
sourceName: function(){
|
||||||
var id = this.sourceId;
|
var id = this.parent.id;
|
||||||
if(!id) return;
|
if(!id) return;
|
||||||
switch(this.type){
|
switch(this.parent.collection){
|
||||||
case "feature":
|
case "Features":
|
||||||
return "Feature - " + Features.findOne(id, {fields: {name: 1}}).name;
|
return "Feature - " + Features.findOne(id, {fields: {name: 1}}).name;
|
||||||
case "class":
|
case "Classes":
|
||||||
return Classes.findOne(id, {fields: {name: 1}}).name;
|
return Classes.findOne(id, {fields: {name: 1}}).name;
|
||||||
case "buff":
|
case "Buffs":
|
||||||
return "Buff - " + Buffs.findOne(id, {fields: {name: 1}}).name;
|
return "Buff - " + Buffs.findOne(id, {fields: {name: 1}}).name;
|
||||||
case "equipment":
|
case "Items":
|
||||||
return "Equipment - " + Items.findOne(id, {fields: {name: 1}}).name;
|
return "Equipment - " + Items.findOne(id, {fields: {name: 1}}).name;
|
||||||
case "racial":
|
case "Characters":
|
||||||
return Characters.findOne(this.charId, {fields: {race: 1}}).race;
|
return Characters.findOne(this.charId, {fields: {race: 1}}).race;
|
||||||
case "inate":
|
default:
|
||||||
return "Inate"
|
return "Inate"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<!--needs to be given charId, sourceId and type-->
|
<!--needs to be given charId, parentId, parentCollection and type-->
|
||||||
<template name="effectsEditList">
|
<template name="effectsEditList">
|
||||||
{{#if effects.count}}
|
{{#if effects.count}}
|
||||||
<hr style="margin: 16px 0 16px 0;">
|
<hr style="margin: 16px 0 16px 0;">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Template.effectsEditList.helpers({
|
Template.effectsEditList.helpers({
|
||||||
effects: function(){
|
effects: function(){
|
||||||
var cursor = Effects.find({sourceId: this.sourceId, type: this.type});
|
var cursor = Effects.find({"parent.id": this.parentId, "parent.collection": this.parentCollection, type: this.type});
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -13,7 +13,10 @@ Template.effectsEditList.events({
|
|||||||
Effects.insert({
|
Effects.insert({
|
||||||
name: this.name,
|
name: this.name,
|
||||||
charId: this.charId,
|
charId: this.charId,
|
||||||
sourceId: this.sourceId,
|
parent: {
|
||||||
|
id: this.parentId,
|
||||||
|
collection: this.parentCollection
|
||||||
|
},
|
||||||
operation: "add",
|
operation: "add",
|
||||||
type: this.type,
|
type: this.type,
|
||||||
enabled: this.enabled
|
enabled: this.enabled
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<!--needs to be given charId, sourceId and type-->
|
<!--needs to be given charId, (parentId or stat) and type-->
|
||||||
<template name="effectsViewList">
|
<template name="effectsViewList">
|
||||||
{{#if effects}}
|
{{#if effects}}
|
||||||
<hr style="margin: 16px 0 16px 0;">
|
<hr style="margin: 16px 0 16px 0;">
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
Template.effectsViewList.helpers({
|
Template.effectsViewList.helpers({
|
||||||
effects: function(){
|
effects: function(){
|
||||||
if(this.sourceId){
|
if(this.parentId){
|
||||||
return Effects.find({sourceId: this.sourceId, type: this.type, charId: this.charId}, {fields: {sourceId: 0}});
|
return Effects.find({"parent.id": this.parentId, type: this.type, charId: this.charId}, {fields: {parent: 0}});
|
||||||
} else if(this.stat){
|
} else if(this.stat){
|
||||||
return Effects.find({charId: this.charId, stat: this.stat});
|
return Effects.find({charId: this.charId, stat: this.stat});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
</paper-dropdown>
|
</paper-dropdown>
|
||||||
</paper-dropdown-menu>
|
</paper-dropdown-menu>
|
||||||
</div>
|
</div>
|
||||||
{{> effectsEditList sourceId=_id charId=charId type="feature" name=name enabled=isEnabled}}
|
{{> effectsEditList parentId=_id parentCollection="Features" charId=charId type="feature" name=name enabled=isEnabled}}
|
||||||
{{/baseDialog}}
|
{{/baseDialog}}
|
||||||
{{/with}}
|
{{/with}}
|
||||||
</template>
|
</template>
|
||||||
@@ -116,7 +116,7 @@ div#stats {
|
|||||||
.inventoryItem {
|
.inventoryItem {
|
||||||
background: white;
|
background: white;
|
||||||
transition: box-shadow 0.3s ease,
|
transition: box-shadow 0.3s ease,
|
||||||
opacity 0.3s ease;
|
opacity 0.5s ease-in-out;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
margin: 1px 0 1px 0;
|
margin: 1px 0 1px 0;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ Template.inventory.helpers({
|
|||||||
return Containers.find({charId: this._id}, {sort: {color: 1, name: 1}})
|
return Containers.find({charId: this._id}, {sort: {color: 1, name: 1}})
|
||||||
},
|
},
|
||||||
items: function(charId, containerId){
|
items: function(charId, containerId){
|
||||||
return Items.find({charId: charId, equipped: false, container: containerId }, {sort: {color: 1, name: 1}});
|
return Items.find({charId: charId, "parent.id": containerId }, {sort: {color: 1, name: 1}});
|
||||||
},
|
},
|
||||||
equipment: function(){
|
equipment: function(){
|
||||||
return Items.find({ charId: this._id, equipped: true }, {sort: {color: 1, name: 1}});
|
return Items.find({ charId: this._id, enabled: true }, {sort: {color: 1, name: 1}});
|
||||||
},
|
},
|
||||||
showAddButtons: function(){
|
showAddButtons: function(){
|
||||||
return Template.instance().showAddButtons.get();
|
return Template.instance().showAddButtons.get();
|
||||||
@@ -30,21 +30,21 @@ Template.inventory.helpers({
|
|||||||
Containers.find({charId: this._id, isCarried: true}).forEach(function(container){
|
Containers.find({charId: this._id, isCarried: true}).forEach(function(container){
|
||||||
weight += container.totalWeight();
|
weight += container.totalWeight();
|
||||||
});
|
});
|
||||||
Items.find({charId: this._id, equipped: true}, {fields: {weight : 1, quantity: 1}}).forEach(function(item){
|
Items.find({charId: this._id, "parent.id": this._id}, {fields: {weight : 1, quantity: 1}}).forEach(function(item){
|
||||||
weight += item.totalWeight();
|
weight += item.totalWeight();
|
||||||
});
|
});
|
||||||
return weight;
|
return weight;
|
||||||
},
|
},
|
||||||
equipmentValue: function(){
|
equipmentValue: function(){
|
||||||
var value = 0;
|
var value = 0;
|
||||||
Items.find({charId: this._id, equipped: true}, {fields: {value : 1, quantity: 1}}).forEach(function(item){
|
Items.find({charId: this._id, enabled: true}, {fields: {value : 1, quantity: 1}}).forEach(function(item){
|
||||||
value += item.totalValue();
|
value += item.totalValue();
|
||||||
});
|
});
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
equipmentWeight: function(){
|
equipmentWeight: function(){
|
||||||
var weight = 0;
|
var weight = 0;
|
||||||
Items.find({charId: this._id, equipped: true}, {fields: {weight : 1, quantity: 1}}).forEach(function(item){
|
Items.find({charId: this._id, enabled: true}, {fields: {weight : 1, quantity: 1}}).forEach(function(item){
|
||||||
weight += item.totalWeight();
|
weight += item.totalWeight();
|
||||||
});
|
});
|
||||||
return weight;
|
return weight;
|
||||||
@@ -63,7 +63,13 @@ Template.inventory.events({
|
|||||||
containerId = Containers.insert({name: "New Container", isCarried: true, charId: this._id});
|
containerId = Containers.insert({name: "New Container", isCarried: true, charId: this._id});
|
||||||
}
|
}
|
||||||
_.defer(function(){
|
_.defer(function(){
|
||||||
var itemId = Items.insert({charId: charId, container: containerId});
|
var itemId = Items.insert({
|
||||||
|
charId: charId,
|
||||||
|
parent:{
|
||||||
|
id: containerId,
|
||||||
|
collection: "Containers"
|
||||||
|
}
|
||||||
|
});
|
||||||
GlobalUI.setDetail({
|
GlobalUI.setDetail({
|
||||||
template: "itemDialog",
|
template: "itemDialog",
|
||||||
data: {itemId: itemId, charId: charId},
|
data: {itemId: itemId, charId: charId},
|
||||||
@@ -128,35 +134,18 @@ Template.layout.events({
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
},
|
},
|
||||||
"dragover .equipmentContainer": function(event, instance){
|
"dragover .equipmentContainer": function(event, instance){
|
||||||
var containerId = Session.get("inventory.dragItemOriginalContainer");
|
|
||||||
var charId = Session.get("inventory.dragItemOriginalCharacter");
|
|
||||||
|
|
||||||
if (this._id !== charId) return; //we can't equip something we don't own
|
|
||||||
|
|
||||||
var item = Items.findOne(Session.get("inventory.dragItemId"));
|
|
||||||
if (item.equipmentSlot === "none") return; //we can't equip this
|
|
||||||
|
|
||||||
event.preventDefault(); //this is a valid drop zone
|
event.preventDefault(); //this is a valid drop zone
|
||||||
},
|
},
|
||||||
"drop .container": function(event, instacne){
|
"drop .itemContainer": function(event, instacne){
|
||||||
var item = Items.findOne(Session.get("inventory.dragItemId"));
|
var item = Items.findOne(Session.get("inventory.dragItemId"));
|
||||||
if (!item) return; //the item doesn't exist
|
//move item to the container
|
||||||
if (item.container === this._id && !item.equipped) return; //the item is already here
|
item.moveToContainer(this._id)
|
||||||
if(Containers.findOne(this._id)){//the container exists
|
|
||||||
Items.update(item._id, {$set: {container: this._id, charId: this.charId, equipped: false}});
|
|
||||||
}
|
|
||||||
resetInvetorySession();
|
resetInvetorySession();
|
||||||
},
|
},
|
||||||
"drop .equipmentContainer": function(event, instance){
|
"drop .equipmentContainer": function(event, instance){
|
||||||
var containerId = Session.get("inventory.dragItemOriginalContainer");
|
|
||||||
var charId = Session.get("inventory.dragItemOriginalCharacter");
|
var charId = Session.get("inventory.dragItemOriginalCharacter");
|
||||||
|
|
||||||
if (this._id !== charId) return; //we can't equip something we don't own
|
|
||||||
|
|
||||||
var item = Items.findOne(Session.get("inventory.dragItemId"));
|
var item = Items.findOne(Session.get("inventory.dragItemId"));
|
||||||
if (item.equipmentSlot === "none") return; //we can't equip this
|
item.equip(charId);
|
||||||
//equip the item if it's not equipped
|
|
||||||
if(!item.equipped) Items.update(item._id, {$set: {equipped: true, container: containerId, charId: charId}});
|
|
||||||
resetInvetorySession();
|
resetInvetorySession();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
<!--Container dropdown-->
|
<!--Container dropdown-->
|
||||||
<paper-dropdown-menu id="containerDropDown" label="Container">
|
<paper-dropdown-menu id="containerDropDown" label="Container">
|
||||||
<paper-dropdown layered class="dropdown">
|
<paper-dropdown layered class="dropdown">
|
||||||
<core-menu class="menu" selected={{containerIndex}}>
|
<core-menu class="menu" selected={{parent.id}}>
|
||||||
{{#each containers}}
|
{{#each containers}}
|
||||||
<paper-item containerId={{_id}} class="containerMenuItem">{{name}}</paper-item>
|
<paper-item name={{_id}} class="containerMenuItem">{{name}}</paper-item>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</core-menu>
|
</core-menu>
|
||||||
</paper-dropdown>
|
</paper-dropdown>
|
||||||
@@ -57,9 +57,9 @@
|
|||||||
</paper-input-decorator>
|
</paper-input-decorator>
|
||||||
{{#if canEquip}}
|
{{#if canEquip}}
|
||||||
<!--Effects-->
|
<!--Effects-->
|
||||||
{{> effectsEditList sourceId=_id charId=charId type="equipment" enabled=equipped name=name}}
|
{{> effectsEditList parentId=_id parentCollection="Items" charId=charId type="equipment" enabled=equipped name=name}}
|
||||||
<!--Attacks-->
|
<!--Attacks-->
|
||||||
{{> attackEditList sourceId=_id charId=charId type="equipment" enabled=equipped name=name}}
|
{{> attackEditList parentId=_id parentCollection="Items" charId=charId type="equipment" enabled=equipped name=name}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/baseDialog}}
|
{{/baseDialog}}
|
||||||
{{/with}}
|
{{/with}}
|
||||||
|
|||||||
@@ -19,11 +19,6 @@ Template.itemDialog.helpers({
|
|||||||
containers: function(){
|
containers: function(){
|
||||||
return getContainers(this.charId);
|
return getContainers(this.charId);
|
||||||
},
|
},
|
||||||
containerIndex: function(){
|
|
||||||
var containers = getContainers(this.charId);
|
|
||||||
var containerIds = _.pluck(containers, "_id");
|
|
||||||
return _.indexOf(containerIds, this.container);
|
|
||||||
},
|
|
||||||
equipmentSlots: function(){
|
equipmentSlots: function(){
|
||||||
return equipmentSlots;
|
return equipmentSlots;
|
||||||
},
|
},
|
||||||
@@ -79,8 +74,9 @@ Template.itemDialog.events({
|
|||||||
"core-select #containerDropDown": function(event){
|
"core-select #containerDropDown": function(event){
|
||||||
var detail = event.originalEvent.detail;
|
var detail = event.originalEvent.detail;
|
||||||
if(!detail.isSelected) return;
|
if(!detail.isSelected) return;
|
||||||
var containerId = detail.item.getAttribute("containerId");
|
var containerId = detail.item.getAttribute("name");
|
||||||
Items.update(Template.currentData().itemId, {$set: {container: containerId}});
|
var item = Items.findOne(Template.currentData().itemId);
|
||||||
|
item.moveToContainer(containerId);
|
||||||
},
|
},
|
||||||
"core-select #slotDropDown": function(event){
|
"core-select #slotDropDown": function(event){
|
||||||
var detail = event.originalEvent.detail;
|
var detail = event.originalEvent.detail;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<!--Level-->
|
<!--Level-->
|
||||||
<paper-input id="levelValueInput" label="Level" floatinglabel value={{level}}></paper-input>
|
<paper-input id="levelValueInput" label="Level" floatinglabel value={{level}}></paper-input>
|
||||||
<!--Effects-->
|
<!--Effects-->
|
||||||
{{> effectsEditList sourceId=_id charId=charId type="class"}}
|
{{> effectsEditList parentId=_id parentCollection="Classes" charId=charId type="class"}}
|
||||||
{{/baseDialog}}
|
{{/baseDialog}}
|
||||||
{{/with}}
|
{{/with}}
|
||||||
</template>
|
</template>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<template name="raceDialog">
|
<template name="raceDialog">
|
||||||
{{#baseDialog title="Race" class=colorClass hideColor="true" hideDelete="true"}}
|
{{#baseDialog title="Race" class=colorClass hideColor="true" hideDelete="true"}}
|
||||||
<paper-input id="raceInput" label="Race" floatinglabel value={{race}}></paper-input>
|
<paper-input id="raceInput" label="Race" floatinglabel value={{race}}></paper-input>
|
||||||
{{> effectsEditList sourceId=_id charId=charId type="racial"}}
|
{{> effectsEditList parentId=_id parentCollection="Characters" charId=charId type="racial"}}
|
||||||
{{/baseDialog}}
|
{{/baseDialog}}
|
||||||
</template>
|
</template>
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
<!--List dropdown-->
|
<!--List dropdown-->
|
||||||
<paper-dropdown-menu id="listDropdown" label="Spell List">
|
<paper-dropdown-menu id="listDropdown" label="Spell List">
|
||||||
<paper-dropdown layered class="dropdown">
|
<paper-dropdown layered class="dropdown">
|
||||||
<core-menu class="menu" selected={{listId}}>
|
<core-menu class="menu" selected={{parent.id}}>
|
||||||
{{#each spellLists}}
|
{{#each spellLists}}
|
||||||
<paper-item name={{_id}} class="containerMenuItem">{{name}}</paper-item>
|
<paper-item name={{_id}} class="containerMenuItem">{{name}}</paper-item>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ Template.spellDialog.events({
|
|||||||
var detail = event.originalEvent.detail;
|
var detail = event.originalEvent.detail;
|
||||||
if(!detail.isSelected) return;
|
if(!detail.isSelected) return;
|
||||||
var value = detail.item.getAttribute("name");
|
var value = detail.item.getAttribute("name");
|
||||||
if (value == this.listId) return;
|
if (value == this.parent.id) return;
|
||||||
Spells.update(this._id, {$set: {listId: value}});
|
Spells.update(this._id, {$set: {"parent.id": value}});
|
||||||
},
|
},
|
||||||
"core-select #levelDropdown": function(event){
|
"core-select #levelDropdown": function(event){
|
||||||
var detail = event.originalEvent.detail;
|
var detail = event.originalEvent.detail;
|
||||||
|
|||||||
@@ -16,22 +16,23 @@ Template.spells.helpers({
|
|||||||
return SpellLists.find({charId: this._id}, {sort: {color: 1, name: 1}});
|
return SpellLists.find({charId: this._id}, {sort: {color: 1, name: 1}});
|
||||||
},
|
},
|
||||||
spellCount: function(list, charId){
|
spellCount: function(list, charId){
|
||||||
|
if(!list || !list.settings) return;
|
||||||
if(list.settings.showUnprepared){
|
if(list.settings.showUnprepared){
|
||||||
return Spells.find( {charId: charId, listId: list._id, level: this.level},
|
return Spells.find( {charId: charId, "parent.id": list._id, level: this.level},
|
||||||
{fields: {_id: 1, level: 1}} ).count() > 0;
|
{fields: {_id: 1, level: 1}} ).count() > 0;
|
||||||
} else{
|
} else{
|
||||||
return Spells.find( {charId: charId, listId: list._id, level: this.level, prepared: {$in: ["prepared", "always"]} },
|
return Spells.find( {charId: charId, "parent.id": list._id, level: this.level, prepared: {$in: ["prepared", "always"]} },
|
||||||
{fields: {_id: 1, level: 1}} ).count() > 0;
|
{fields: {_id: 1, level: 1}} ).count() > 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
spells: function(listId, charId){
|
spells: function(listId, charId){
|
||||||
return Spells.find( {charId: charId, listId: listId, level: this.level}, {sort: {color: 1, name: 1}} );
|
return Spells.find( {charId: charId, "parent.id": listId, level: this.level}, {sort: {color: 1, name: 1}} );
|
||||||
},
|
},
|
||||||
levels: function(){
|
levels: function(){
|
||||||
return spellLevels;
|
return spellLevels;
|
||||||
},
|
},
|
||||||
numPrepared: function(){
|
numPrepared: function(){
|
||||||
return Spells.find({charId: Template.parentData()._id, listId: this._id, prepared: "prepared"}).count();
|
return Spells.find({charId: Template.parentData()._id, "parent.id": this._id, prepared: "prepared"}).count();
|
||||||
},
|
},
|
||||||
order: function(){
|
order: function(){
|
||||||
return _.indexOf(_.keys(colorOptions), this.color);
|
return _.indexOf(_.keys(colorOptions), this.color);
|
||||||
@@ -168,17 +169,20 @@ Template.spells.events({
|
|||||||
},
|
},
|
||||||
"tap #addSpell": function(event){
|
"tap #addSpell": function(event){
|
||||||
var charId = this.charId;
|
var charId = this.charId;
|
||||||
var listId = this.listId;
|
var listId = SpellLists.findOne({charId: this._id})._id;
|
||||||
Spells.insert({
|
Spells.insert({
|
||||||
name: "New Spell",
|
name: "New Spell",
|
||||||
charId: this._id,
|
charId: this._id,
|
||||||
listId: SpellLists.findOne({charId: this._id})._id,
|
parent: {
|
||||||
|
id: listId,
|
||||||
|
collection: "SpellLists"
|
||||||
|
},
|
||||||
prepared: "prepared"
|
prepared: "prepared"
|
||||||
}, function(error, id){
|
}, function(error, id){
|
||||||
if(!error){
|
if(!error){
|
||||||
GlobalUI.setDetail({
|
GlobalUI.setDetail({
|
||||||
template: "spellDialog",
|
template: "spellDialog",
|
||||||
data: {spellId: id, charId: charId, listId: listId},
|
data: {spellId: id, charId: charId},
|
||||||
heroId: id
|
heroId: id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ Template.skillDialog.helpers({
|
|||||||
return Characters.findOne(this.charId, {fields:{_id: 1}});
|
return Characters.findOne(this.charId, {fields:{_id: 1}});
|
||||||
},
|
},
|
||||||
sourceName: function(){
|
sourceName: function(){
|
||||||
var id = this.sourceId;
|
var id = this.parent.id;
|
||||||
if(!id) return;
|
if(!id) return;
|
||||||
switch(this.type){
|
switch(this.type){
|
||||||
case "feature":
|
case "feature":
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ var joinWithDefaultKeys = function(keys){
|
|||||||
'restoredBy'
|
'restoredBy'
|
||||||
];
|
];
|
||||||
return _.union(keys, defaultKeys);
|
return _.union(keys, defaultKeys);
|
||||||
}
|
};
|
||||||
|
|
||||||
var limitModifierToKeys = function(modifier, keys){
|
var limitModifierToKeys = function(modifier, keys){
|
||||||
if(!modifier) return;
|
if(!modifier) return;
|
||||||
@@ -24,7 +24,23 @@ var limitModifierToKeys = function(modifier, keys){
|
|||||||
if(_.isEmpty(modifier.$set)) delete modifier.$set;
|
if(_.isEmpty(modifier.$set)) delete modifier.$set;
|
||||||
if(_.isEmpty(modifier.$unset)) delete modifier.$unset;
|
if(_.isEmpty(modifier.$unset)) delete modifier.$unset;
|
||||||
return modifier;
|
return modifier;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
var getParent = function(doc){
|
||||||
|
if(!doc || !doc.parent) return;
|
||||||
|
var parentCol = Meteor.isClient?
|
||||||
|
window[doc.parent.collection] : global[doc.parent.collection];
|
||||||
|
if (parentCol)
|
||||||
|
return parentCol.findOne(doc.parent.id, {removed: true});
|
||||||
|
};
|
||||||
|
|
||||||
|
var inheritParentProperties = function(doc, collection){
|
||||||
|
var parent = getParent(doc);
|
||||||
|
if(!parent) throw new Meteor.Error('Parenting Error',
|
||||||
|
'Document\'s parent does not exist');
|
||||||
|
var handMeDowns = _.pick(parent, collection.inheritedKeys);
|
||||||
|
collection.update(doc._id, {$set: handMeDowns});
|
||||||
|
};
|
||||||
|
|
||||||
var childCollections = [];
|
var childCollections = [];
|
||||||
|
|
||||||
@@ -34,25 +50,23 @@ makeChild = function(collection, inheritedKeys){
|
|||||||
collection.helpers({
|
collection.helpers({
|
||||||
//returns the parent even if it's removed
|
//returns the parent even if it's removed
|
||||||
getParent: function(){
|
getParent: function(){
|
||||||
var parentCol = Meteor.isClient?
|
return getParent(this);
|
||||||
window[this.parent.collection] : global[this.parent.collection];
|
|
||||||
if (parentCol)
|
|
||||||
return parentCol.findOne(this.parent.id, {removed: true});
|
|
||||||
},
|
},
|
||||||
getParentCollection: function(){
|
getParentCollection: function(){
|
||||||
return Meteor.isClient?
|
return Meteor.isClient?
|
||||||
window[this.parent.collection] : global[this.parent.collection];
|
window[this.parent.collection] : global[this.parent.collection];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//when created, inherit parent properties
|
||||||
|
collection.after.insert(function(userId, doc){
|
||||||
|
inheritParentProperties(doc, collection);
|
||||||
|
});
|
||||||
|
|
||||||
//when we change parents, inherit its properties
|
//when we change parents, inherit its properties
|
||||||
collection.after.update(function (userId, doc, fieldNames, modifier, options) {
|
collection.after.update(function (userId, doc, fieldNames, modifier, options) {
|
||||||
if(modifier && modifier.$set && modifier.$set.parent){
|
if(modifier && modifier.$set && modifier.$set.parent){
|
||||||
var parent = doc.getParent();
|
inheritParentProperties(doc, collection);
|
||||||
if(!parent) throw new Meteor.Error('Parenting Error',
|
|
||||||
'Document\'s parent does not exist');
|
|
||||||
var handMeDowns = _.pick(parent, collection.inheritedKeys);
|
|
||||||
collection.update(doc._id, {$set: handMeDowns});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user