Finished implementing basic item library

This commit is contained in:
Stefan Zermatten
2017-04-24 14:15:17 +02:00
parent cd7702cf4f
commit 7996fa4370
21 changed files with 1727 additions and 76 deletions

View File

@@ -138,6 +138,13 @@
</paper-fab>
<paper-tooltip position="left"> New container </paper-tooltip>
</div>
<div>
<paper-fab icon="av:library-books"
class="libraryItem"
mini>
</paper-fab>
<paper-tooltip position="left"> Library item </paper-tooltip>
</div>
<div>
<paper-fab icon="note-add"
class="addItem"

View File

@@ -139,6 +139,43 @@ Template.inventory.events({
returnElement: () => $(`[data-id='${itemId}']`).get(0),
});
},
"click .libraryItem": function(event, instance){
var charId = this._id;
var itemId = Items.insert({
charId: charId,
parent:{
id: charId,
collection: "Characters",
},
});
pushDialogStack({
template: "itemLibraryDialog",
element: event.currentTarget,
callback: (result) => {
if (!result) {
Items.remove(itemId);
return;
}
// Make the library item into a regular item
let item = _.omit(result, "library", "attacks", "effects");
delete item.settings.category;
// Update the item to match library item
Items.update(itemId, {$set: item});
// Copy over attacks and effects
_.each(result.attacks, (attack) => {
attack.charId = charId;
attack.parent = {id: itemId, collection: "Items"};
Attacks.insert(attack);
});
_.each(result.effects, (effect) => {
effect.charId = charId;
effect.parent = {id: itemId, collection: "Items"};
Effects.insert(effect);
});
},
returnElement: () => $(`[data-id='${itemId}']`).get(0),
})
},
"click .addContainer": function(event, instance){
var containerId = Containers.insert({
name: "New Container",

View File

@@ -1,6 +1,6 @@
<template name="itemDialog">
{{#with item}}
{{#baseDialog title=itemHeading class=colorClass startEditing=../startEditing showLibrary=true}}
{{#baseDialog title=itemHeading class=colorClass startEditing=../startEditing}}
{{> itemDetails}}
{{else}}
{{> itemEdit}}

View File

@@ -33,21 +33,6 @@ Template.itemDialog.events({
"click #doneEditingButton": function(event, instance){
instance.editing.set(false);
},
"click #libraryButton": function(event, instance){
pushDialogStack({
template: "itemLibraryDialog",
element: event.currentTarget,
callback: function(result){
if (!result) return;
delete result.parent;
delete result._id;
delete result.charId;
result.quantity = 1;
Items.update(instance.data.itemId, {$set: result});
//TODO Replace the effects with the effects of the library item
},
})
},
"color-change": function(event, instance){
Items.update(instance.data.itemId, {$set: {color: event.color}});
},

View File

@@ -10,26 +10,32 @@
</paper-input>
</app-toolbar>
<div class="flex scroll-y">
<div class="items" style="padding:8px">
{{#if searchTerm}}
{{#if searchItems.count}}
{{#each item in searchItems}}
{{>libraryItem item=item selected=(isSelected item)}}
{{/each}}
{{#if ready}}
<div class="items" style="padding:8px">
{{#if searchTerm}}
{{#if searchItems.count}}
{{#each item in searchItems}}
{{>libraryItem item=item selected=(isSelected item)}}
{{/each}}
{{else}}
No items match "{{searchTerm}}"
{{/if}}
{{else}}
No items match "{{searchTerm}}"
{{/if}}
{{else}}
{{#each category in categories}}
<div class="paper-font-subhead">
{{category.name}}
</div>
{{#each item in itemsInCategory category.value}}
{{>libraryItem item=item selected=(isSelected item)}}
{{#each category in categories}}
<div class="paper-font-subhead">
{{category.name}}
</div>
{{#each item in (itemsInCategory category.key)}}
{{>libraryItem item=item selected=(isSelected item)}}
{{/each}}
{{/each}}
{{/each}}
{{/if}}
</div>
{{/if}}
</div>
{{else}}
<div class="fit layout vertical center center-justified">
<paper-spinner active></paper-spinner>
</div>
{{/if}}
</div>
<div class="layout horizontal end-justified">
<paper-button class="cancelButton">Cancel</paper-button>
@@ -44,11 +50,5 @@
<div class="itemName flex">
{{item.name}}
</div>
<div style="margin: 0 8px">
{{item.weight}}
</div>
<div style="margin: 0 8px">
{{item.value}}
</div>
</div>
</template>

View File

@@ -1,24 +1,30 @@
const librarySubs = new SubsManager();
Template.itemLibraryDialog.onCreated(function(){
this.selectedItem = new ReactiveVar();
this.searchTerm = new ReactiveVar();
this.ready = new ReactiveVar();
this.autorun(() => {
var handle = librarySubs.subscribe("standardLibraries");
this.ready.set(handle.ready());
});
});
Template.itemLibraryDialog.helpers({
ready(){
return Template.instance().ready.get();
},
categories(){
return [
{name: "Weapons", key: "weapons"},
{name: "Armor", key: "armor"},
{name: "Adventuring Equipment", key: "adventuringEquipment"},
{name: "Tools", key: "tools"},
{name: "Adventuring Gear", key: "adventuringGear"},
];
},
itemsInCategory(category){
//TODO return a cursor of all library items in the category
// As a dummy function returns a random 2 items
let count = Items.find({}).count();
return Items.find({}, {
limit: 5,
skip: Math.floor(Math.random() * (count - 5)),
itemsInCategory(categoryKey){
return LibraryItems.find({
library: "SRDLibraryGA3XWsd",
"settings.category": categoryKey,
});
},
isSelected(item){
@@ -30,10 +36,12 @@ Template.itemLibraryDialog.helpers({
},
searchItems(){
const searchTerm = Template.instance().searchTerm.get();
//TODO return something relevant to the search terms
return Items.find({name: {
$regex: new RegExp(".*" + searchTerm + ".*", "gi")
}});
return LibraryItems.find({
library: "SRDLibraryGA3XWsd",
name: {
$regex: new RegExp(".*" + searchTerm + ".*", "gi")
},
});
},
});

View File

@@ -57,7 +57,7 @@
<iron-icon icon="bug-report" item-icon></iron-icon>
Send Feedback
</paper-icon-item>
<a href="changeLog" tabindex="-1">
<a href="/changeLog" tabindex="-1">
<paper-icon-item id="changeLog">
<iron-icon icon="list" item-icon></iron-icon>
Change Log

View File

@@ -19,7 +19,7 @@
<div class="flex" style="position: relative;">
<iron-pages id="tabPages" class="fit" selected={{selectedTab}}>
<div name="items" class="tab-page fit">{{> itemLibrary}}</div>
<div name="spells" class="tab-page fit">{{> spellLibrary}}</div>
<div name="spells" class="tab-page fit">{{! {{> spellLibrary}} }}</div>
</iron-pages>
</div>
</div>

View File

@@ -16,12 +16,6 @@
{{#unless hideColor}}
{{> colorDropdown}}
{{/unless}}
{{#if showLibrary}}
<paper-icon-button id="libraryButton"
tabindex="0"
icon="av:library-books">
</paper-icon-button>
{{/if}}
<paper-icon-button id="doneEditingButton"
icon="done">
</paper-icon-button>