Skip to content

Commit

Permalink
put code into an IIFE in preparation for adding libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
effortlessmountain committed Nov 27, 2019
1 parent fa28138 commit 44c8401
Showing 1 changed file with 124 additions and 121 deletions.
245 changes: 124 additions & 121 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,121 +1,122 @@
(() => {

const bonded = {
type: "path",
icon: "◊",
name: "Bonded",
abilities: [
{
filled: true,
text: "When you make a move which gives you an add for sharing a bond, add +1 more."
},
{
text: "When you completely fill a box on your bonds progress track, envision what your relationships have taught you. Then, take +1 experience and +2 momentum."
},
{
text: "When you make a move in a crucial moment and score a miss, you may cling to thoughts of your bond-kin for courage or encouragement. If you do, reroll any dice. On another miss, in addition to the outcome of the move, you must mark shaken or corrupted. If both debilities are already marked, <em>Face Desolation</em>."
}
]
}

const bonded = {
type: "path",
icon: "◊",
name: "Bonded",
abilities: [
{
filled: true,
text: "When you make a move which gives you an add for sharing a bond, add +1 more."
},
{
text: "When you completely fill a box on your bonds progress track, envision what your relationships have taught you. Then, take +1 experience and +2 momentum."
},
{
text: "When you make a move in a crucial moment and score a miss, you may cling to thoughts of your bond-kin for courage or encouragement. If you do, reroll any dice. On another miss, in addition to the outcome of the move, you must mark shaken or corrupted. If both debilities are already marked, <em>Face Desolation</em>."
}
]
}

const berserker = {
type: "combat talent",
icon: "▿",
name: "Berserker",
writeIn: "",
track: 0,
description: "If you are clad only in animal pelts...",
abilities: [
{
filled: true,
name: "",
text: "When you <em>Secure an Advantage</em> or <em>Compel</em> by embodying your wild nature, add +1 and take +1 momentum on a hit."
},
{
filled: false,
name: "",
text: "When you <em>Strike</em> and score a hit, you may inflict +1 harm. If you do, choose one. <li>Push yourself: <em>Endure Harm</em> (1 harm).</li> <li>Lose yourself: <em>Endure Stress</em> (1 stress).</li>"
},
{
filled: false,
name: "",
text: "When you <em>Endure Harm</em> in a fight, you may let the pain inflame your wildness (decide before rolling). The value of your action die is then halved, rounding up (1/2=1, 3/4=2, 5/6=3). If you score a strong hit, and choose to embrace the pain, take your modified action die value as +momentum."
}
]
}

const caveLion = {
type: "companion",
icon: "C",
name: "Cave Lion",
writeIn: "Name",
track: 4,
description: "Your cat takes down its prey.",
abilities: [
{
filled: false,
name: "Eager",
text: "When your cat chases down big game, you may <em>Resupply</em> with +edge (instead of +wits). If you do, take +1 supply or +1 momentum on a strong hit."
},
{
filled: false,
name: "Inescapable",
text: "When you <em>Enter the Fray</em> or <em>Strike</em> by sending your cat to attack, roll +edge. On a hit, take +2 momentum."
},
{
filled: false,
name: "Protective",
text: "When you <em>Make Camp</em>, your cat is alert to trouble. If you or an ally choose to relax, take +1 spirit. If you focus, take +1 momentum."
}
]
}
const berserker = {
type: "combat talent",
icon: "▿",
name: "Berserker",
writeIn: "",
track: 0,
description: "If you are clad only in animal pelts...",
abilities: [
{
filled: true,
name: "",
text: "When you <em>Secure an Advantage</em> or <em>Compel</em> by embodying your wild nature, add +1 and take +1 momentum on a hit."
},
{
filled: false,
name: "",
text: "When you <em>Strike</em> and score a hit, you may inflict +1 harm. If you do, choose one. <li>Push yourself: <em>Endure Harm</em> (1 harm).</li> <li>Lose yourself: <em>Endure Stress</em> (1 stress).</li>"
},
{
filled: false,
name: "",
text: "When you <em>Endure Harm</em> in a fight, you may let the pain inflame your wildness (decide before rolling). The value of your action die is then halved, rounding up (1/2=1, 3/4=2, 5/6=3). If you score a strong hit, and choose to embrace the pain, take your modified action die value as +momentum."
}
]
}

const caveLion = {
type: "companion",
icon: "C",
name: "Cave Lion",
writeIn: "Name",
track: 4,
description: "Your cat takes down its prey.",
abilities: [
{
filled: false,
name: "Eager",
text: "When your cat chases down big game, you may <em>Resupply</em> with +edge (instead of +wits). If you do, take +1 supply or +1 momentum on a strong hit."
},
{
filled: false,
name: "Inescapable",
text: "When you <em>Enter the Fray</em> or <em>Strike</em> by sending your cat to attack, roll +edge. On a hit, take +2 momentum."
},
{
filled: false,
name: "Protective",
text: "When you <em>Make Camp</em>, your cat is alert to trouble. If you or an ally choose to relax, take +1 spirit. If you focus, take +1 momentum."
}
]
}

const createWriteIn = (writeIn) => {
return writeIn ? `<div class="write-in">${writeIn}</div>` : ""
}

const createDescription = (description) => {
return description ? `<div class="description">${description}</div>` : ""
}
const createWriteIn = (writeIn) => {
return writeIn ? `<div class="write-in">${writeIn}</div>` : ""
}

const createAbilitiesHtml = (abilities = []) => {
const createAbilityName = (name) => {
return name ? `<span class="ability-name">${name}</span>` : ""
const createDescription = (description) => {
return description ? `<div class="description">${description}</div>` : ""
}
return abilities.map((ability) => {
return `<div class="ability">

const createAbilitiesHtml = (abilities = []) => {
const createAbilityName = (name) => {
return name ? `<span class="ability-name">${name}</span>` : ""
}
return abilities.map((ability) => {
return `<div class="ability">
<i class="dot ${ability.filled ? "filled" : "unfilled"}"></i>
${createAbilityName(ability.name)}
${ability.text}
</div>`
}).join("")
}

const createTrackValueHtml = (track, value) => {
if (value > track) {
return `<div class="value empty"></div>`
} else {
return `<div class="value">${value}</div>`
}).join("")
}
}

const createTrackHtml = (track) => {
if (!track) {
return ""
} else {
return `<div class="track">
const createTrackValueHtml = (track, value) => {
if (value > track) {
return `<div class="value empty"></div>`
} else {
return `<div class="value">${value}</div>`
}
}

const createTrackHtml = (track) => {
if (!track) {
return ""
} else {
return `<div class="track">
<div class="value zero">0</div>
${createTrackValueHtml(track, 1)}
${createTrackValueHtml(track, 2)}
${createTrackValueHtml(track, 3)}
${createTrackValueHtml(track, 4)}
${createTrackValueHtml(track, 5)}
</div>`
}
}
}

const createAssetHtml = (asset = {}) => {
return `<div class="asset">
const createAssetHtml = (asset = {}) => {
return `<div class="asset">
<div class="main-matter">
<div class="top">
<div class="type">${asset.type}</div>
Expand All @@ -134,36 +135,38 @@ const createAssetHtml = (asset = {}) => {
</div>
${createTrackHtml(asset.track)}
</div>`
}
}

const assetInput = document.querySelector('.interface-input')
const assetContainer = document.querySelector(".assets")
const updateButton = document.querySelector(".update")
const showSingleAssetButton = document.querySelector(".show-single")
const showMultipleAssetButton = document.querySelector(".show-multiple")
const assetInput = document.querySelector('.interface-input')
const assetContainer = document.querySelector(".assets")
const updateButton = document.querySelector(".update")
const showSingleAssetButton = document.querySelector(".show-single")
const showMultipleAssetButton = document.querySelector(".show-multiple")

const showSingleAssetExample = () => {
assetInput.value = JSON.stringify(caveLion, null, 2)
assetContainer.innerHTML = createAssetHtml(caveLion)
}
const showSingleAssetExample = () => {
assetInput.value = JSON.stringify(caveLion, null, 2)
assetContainer.innerHTML = createAssetHtml(caveLion)
}

const showMultipleAssetExample = () => {
assetInput.value = JSON.stringify([bonded, berserker, caveLion], null, 2)
assetContainer.innerHTML = [bonded, berserker, caveLion].map(createAssetHtml).join("")
}
const showMultipleAssetExample = () => {
assetInput.value = JSON.stringify([bonded, berserker, caveLion], null, 2)
assetContainer.innerHTML = [bonded, berserker, caveLion].map(createAssetHtml).join("")
}



updateButton.onclick = () => {
let data = JSON.parse(assetInput.value)
if (Array.isArray(data)) {
assetContainer.innerHTML = data.map(createAssetHtml).join('')
} else {
assetContainer.innerHTML = createAssetHtml(data)
updateButton.onclick = () => {
let data = JSON.parse(assetInput.value)
if (Array.isArray(data)) {
assetContainer.innerHTML = data.map(createAssetHtml).join('')
} else {
assetContainer.innerHTML = createAssetHtml(data)
}
}
}

showSingleAssetButton.onclick = showSingleAssetExample
showMultipleAssetButton.onclick = showMultipleAssetExample
showSingleAssetButton.onclick = showSingleAssetExample
showMultipleAssetButton.onclick = showMultipleAssetExample

showSingleAssetExample()

showSingleAssetExample()
})()

0 comments on commit 44c8401

Please sign in to comment.