-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature-improved-initiative-export'
closes #95
- Loading branch information
Showing
7 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
rpg-docs/client/views/character/export/exportDialog/exportDialog.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.exportDialog .iiexport { | ||
overflow-y: auto; | ||
width: 100% !important; | ||
} |
31 changes: 31 additions & 0 deletions
31
rpg-docs/client/views/character/export/exportDialog/exportDialog.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<template name="exportDialog"> | ||
<div class="exportDialog fit layout vertical"> | ||
{{#with character}} | ||
<app-header fixed effects="waterfall"> | ||
<app-toolbar> | ||
<div main-title>Export Character to Improved Initiative</div> | ||
</app-toolbar> | ||
</app-header> | ||
<div class="form flex layout vertical"> | ||
<paper-toggle-button id="exportFeatures" checked={{settings.exportFeatures}}> | ||
Features | ||
</paper-toggle-button> | ||
<paper-toggle-button id="exportAttacks" checked={{settings.exportAttacks}}> | ||
Attacks | ||
</paper-toggle-button> | ||
<paper-toggle-button id="exportDescription" checked={{settings.exportDescription}}> | ||
Description | ||
</paper-toggle-button> | ||
<div class="paper-font-title padded">JSON</div> | ||
<textarea class="flex iiexport">{{improvedInitiativeJson}}</textarea> | ||
<paper-button id="copyExportButton" class="red-button" raised> | ||
<iron-icon icon="content-copy"></iron-icon> | ||
Copy to Clipboard | ||
</paper-button> | ||
</div> | ||
<div class="buttons layout horizontal end-justified"> | ||
<paper-button class="doneButton"> Done </paper-button> | ||
</div> | ||
{{/with}} | ||
</div> | ||
</template> |
60 changes: 60 additions & 0 deletions
60
rpg-docs/client/views/character/export/exportDialog/exportDialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
Template.exportDialog.helpers({ | ||
character: function(){ | ||
return Characters.findOne(this._id); | ||
}, | ||
improvedInitiativeJson: function(){ | ||
var options = { | ||
features: this.settings.exportFeatures, | ||
attacks: this.settings.exportAttacks, | ||
description: this.settings.exportDescription, | ||
} | ||
return improvedInitiativeJson(this._id, options); | ||
}, | ||
}); | ||
|
||
Template.exportDialog.events({ | ||
"change #exportFeatures": function(event, template){ | ||
Characters.update(this._id, {$set: { | ||
"settings.exportFeatures": event.target.checked, | ||
}}); | ||
}, | ||
"change #exportAttacks": function(event, template){ | ||
Characters.update(this._id, {$set: { | ||
"settings.exportAttacks": event.target.checked, | ||
}}); | ||
}, | ||
"change #exportDescription": function(event, template){ | ||
Characters.update(this._id, {$set: { | ||
"settings.exportDescription": event.target.checked, | ||
}}); | ||
}, | ||
"click #copyExportButton": function(event, template){ | ||
var copyTextarea = template.find(".iiexport"); | ||
copyTextarea.select(); | ||
var msg; | ||
try { | ||
var successful = document.execCommand("copy"); | ||
var msg = successful ? "JSON copied to clipboard" : "Unable to copy JSON"; | ||
} catch (err) { | ||
msg = "Unable to copy JSON"; | ||
} finally { | ||
clearSelection(); | ||
GlobalUI.toast(msg); | ||
} | ||
}, | ||
"click .doneButton": function(event, instance){ | ||
popDialogStack(); | ||
}, | ||
}); | ||
|
||
var clearSelection = function(){ | ||
if (window.getSelection) { | ||
if (window.getSelection().empty) { // Chrome | ||
window.getSelection().empty(); | ||
} else if (window.getSelection().removeAllRanges) { // Firefox | ||
window.getSelection().removeAllRanges(); | ||
} | ||
} else if (document.selection) { // IE? | ||
document.selection.empty(); | ||
} | ||
}; |
191 changes: 191 additions & 0 deletions
191
rpg-docs/client/views/character/export/improvedInitiativeJson.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
improvedInitiativeJson = function(charId, options){ | ||
options = options || { | ||
features: true, | ||
attacks: true, | ||
description: true, | ||
}; | ||
var char = Characters.findOne(charId); | ||
if (!char) return; | ||
var baseValue = function(attributeName){ | ||
return Characters.calculate.attributeBase(charId, attributeName); | ||
}; | ||
var skillMod = function(skillName){ | ||
return Characters.calculate.skillMod(charId, skillName); | ||
}; | ||
var damageMods = getDamageMods(charId); | ||
return JSON.stringify({ | ||
"Id": char._id, | ||
"Name": char.name, | ||
"Source": "DiceCloud", | ||
"Type": char.race, | ||
"HP": { | ||
"Value": baseValue("hitPoints"), | ||
"Notes": getHitDiceString(charId) || "", | ||
}, | ||
"AC": { | ||
"Value": baseValue("armor"), | ||
"Notes": getArmorString(charId) || "", | ||
}, | ||
"InitiativeModifier": skillMod("initiative"), | ||
"Speed": ["" + baseValue("speed")], | ||
"Abilities": { | ||
"Str": baseValue("strength"), | ||
"Dex": baseValue("dexterity"), | ||
"Con": baseValue("constitution"), | ||
"Cha": baseValue("charisma"), | ||
"Int": baseValue("intelligence"), | ||
"Wis": baseValue("wisdom"), | ||
}, | ||
"DamageVulnerabilities": damageMods.vulnerabilities, | ||
"DamageResistances": damageMods.resistances, | ||
"DamageImmunities": damageMods.immunities, | ||
"ConditionImmunities": [], | ||
"Saves": [ | ||
{"Name": "Str", "Modifier": skillMod("strengthSave")}, | ||
{"Name": "Dex", "Modifier": skillMod("dexteritySave")}, | ||
{"Name": "Con", "Modifier": skillMod("constitutionSave")}, | ||
{"Name": "Int", "Modifier": skillMod("intelligenceSave")}, | ||
{"Name": "Wis", "Modifier": skillMod("wisdomSave")}, | ||
{"Name": "Cha", "Modifier": skillMod("charismaSave")}, | ||
], | ||
"Skills": getSkills(charId), | ||
"Senses": [], | ||
"Languages": getLanguages(charId), | ||
"Challenge": "", | ||
"Traits": options.features ? getTraits(charId) : [], | ||
"Actions": options.attacks ? getActions(charId) : [], | ||
"Reactions": [], | ||
"LegendaryActions": [], | ||
"Description": options.description ? char.description : "", | ||
"Player": Meteor.user().username, | ||
}, null, 2); | ||
} | ||
|
||
var getHitDiceString = function(charId){ | ||
var d6 = Characters.calculate.attributeBase(charId, "d6HitDice"); | ||
var d8 = Characters.calculate.attributeBase(charId, "d8HitDice"); | ||
var d10 = Characters.calculate.attributeBase(charId, "d10HitDice"); | ||
var d12 = Characters.calculate.attributeBase(charId, "d12HitDice"); | ||
var con = Characters.calculate.abilityMod(charId,"constitution"); | ||
var string = "" + | ||
(d6 ? `${d6}d6 + ` : "") + | ||
(d8 ? `${d8}d8 + ` : "") + | ||
(d10 ? `${d10}d10 + ` : "") + | ||
(d12 ? `${d12}d12 + ` : "") + | ||
con; | ||
} | ||
|
||
var getArmorString = function(charId){ | ||
var bases = Effects.find({ | ||
charId: charId, | ||
stat: "armor", | ||
operation: "base", | ||
enabled: true, | ||
}).map(e => ({ | ||
ame: e.name, | ||
value: evaluateEffect(charId, e), | ||
})); | ||
var base = bases.length && _.max(bases, b => b.value).name || ""; | ||
var effects = Effects.find({ | ||
charId: charId, | ||
stat: "armor", | ||
operation: {$ne: "base"}, | ||
enabled: true, | ||
}).map(e => e.name); | ||
var strings = base ? [base] : []; | ||
strings = strings.concat(effects); | ||
return strings.join(", "); | ||
} | ||
|
||
var getDamageMods = function(charId){ | ||
// jscs:disable maximumLineLength | ||
var multipliers = [ | ||
{name: "Acid", value: Characters.calculate.attributeValue(charId, "acidMultiplier")}, | ||
{name: "Bludgeoning", value: Characters.calculate.attributeValue(charId, "bludgeoningMultiplier")}, | ||
{name: "Cold", value: Characters.calculate.attributeValue(charId, "coldMultiplier")}, | ||
{name: "Fire", value: Characters.calculate.attributeValue(charId, "fireMultiplier")}, | ||
{name: "Force", value: Characters.calculate.attributeValue(charId, "forceMultiplier")}, | ||
{name: "Lightning", value: Characters.calculate.attributeValue(charId, "lightningMultiplier")}, | ||
{name: "Necrotic", value: Characters.calculate.attributeValue(charId, "necroticMultiplier")}, | ||
{name: "Piercing", value: Characters.calculate.attributeValue(charId, "piercingMultiplier")}, | ||
{name: "Poison", value: Characters.calculate.attributeValue(charId, "poisonMultiplier")}, | ||
{name: "Psychic", value: Characters.calculate.attributeValue(charId, "psychicMultiplier")}, | ||
{name: "Radiant", value: Characters.calculate.attributeValue(charId, "radiantMultiplier")}, | ||
{name: "Slashing", value: Characters.calculate.attributeValue(charId, "slashingMultiplier")}, | ||
{name: "Thunder", value: Characters.calculate.attributeValue(charId, "thunderMultiplier")}, | ||
]; | ||
// jscs:enable maximumLineLength | ||
multipliers = _.groupBy(multipliers, "value"); | ||
return { | ||
"immunities": multipliers["0"] || [], | ||
"resistances": multipliers["0.5"] || [], | ||
"weaknesses": multipliers["2"] || [], | ||
}; | ||
} | ||
|
||
var getSkills = function(charId){ | ||
var allSkills = [ | ||
{name: "acrobatics", attribute: "dexterity"}, | ||
{name: "animalHandling", attribute: "wisdom"}, | ||
{name: "arcana", attribute: "intelligence"}, | ||
{name: "athletics", attribute: "strength"}, | ||
{name: "deception", attribute: "charisma"}, | ||
{name: "history", attribute: "intelligence"}, | ||
{name: "insight", attribute: "wisdom"}, | ||
{name: "intimidation", attribute: "charisma"}, | ||
{name: "investigation", attribute: "intelligence"}, | ||
{name: "medicine", attribute: "wisdom"}, | ||
{name: "nature", attribute: "intelligence"}, | ||
{name: "perception", attribute: "wisdom"}, | ||
{name: "performance", attribute: "charisma"}, | ||
{name: "persuasion", attribute: "charisma"}, | ||
{name: "religion", attribute: "intelligence"}, | ||
{name: "sleightOfHand", attribute: "dexterity"}, | ||
{name: "stealth", attribute: "dexterity"}, | ||
{name: "survival", attribute: "wisdom"}, | ||
]; | ||
var skills = []; | ||
_.each(allSkills, skill => { | ||
var value = Characters.calculate.skillMod(charId, skill.name); | ||
var mod = Characters.calculate.abilityMod(charId, skill.attribute); | ||
if (value !== mod){ | ||
skills.push({Name: skill.name, Modifier: value}); | ||
} | ||
}); | ||
return skills; | ||
}; | ||
|
||
var getLanguages = function(charId){ | ||
return Proficiencies.find({ | ||
charId, | ||
enabled: true, | ||
type: "language", | ||
}).map(l => l.name); | ||
}; | ||
|
||
var getTraits = function(charId){ | ||
return Features.find( | ||
{charId: charId}, | ||
{sort: {color: 1, name: 1}} | ||
).map(f => ({ | ||
Name: f.name, | ||
// evaluateShortString helper | ||
Content: evaluateString( | ||
charId, f.description && f.description.split(/^( *[-*_]){3,} *(?:\n+|$)/m)[0] | ||
) || "", | ||
Usage: "", | ||
})); | ||
} | ||
|
||
var getActions = function(charId){ | ||
return Attacks.find( | ||
{charId, enabled: true}, | ||
{sort: {color: 1, name: 1}} | ||
).map(a => ({ | ||
Name: a.name, | ||
Content: `+${evaluate(charId, a.attackBonus)} to hit, ` + | ||
`${evaluateString(charId, a.damage)} ${a.damageType} damage, ` + | ||
`${a.details}`, | ||
Usage: "", | ||
})); | ||
} |