From 44c8401a59de46264dd6299751d1ab122a5d0b15 Mon Sep 17 00:00:00 2001 From: Effortless Mountain Date: Tue, 26 Nov 2019 17:56:39 -0800 Subject: [PATCH] put code into an IIFE in preparation for adding libraries --- app.js | 245 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 124 insertions(+), 121 deletions(-) diff --git a/app.js b/app.js index c4df7d9..078d647 100644 --- a/app.js +++ b/app.js @@ -1,109 +1,110 @@ +(() => { + + 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, Face Desolation." + } + ] + } -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, Face Desolation." - } - ] -} - -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 Secure an Advantage or Compel by embodying your wild nature, add +1 and take +1 momentum on a hit." - }, - { - filled: false, - name: "", - text: "When you Strike and score a hit, you may inflict +1 harm. If you do, choose one.
  • Push yourself: Endure Harm (1 harm).
  • Lose yourself: Endure Stress (1 stress).
  • " - }, - { - filled: false, - name: "", - text: "When you Endure Harm 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 Resupply 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 Enter the Fray or Strike by sending your cat to attack, roll +edge. On a hit, take +2 momentum." - }, - { - filled: false, - name: "Protective", - text: "When you Make Camp, 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 Secure an Advantage or Compel by embodying your wild nature, add +1 and take +1 momentum on a hit." + }, + { + filled: false, + name: "", + text: "When you Strike and score a hit, you may inflict +1 harm. If you do, choose one.
  • Push yourself: Endure Harm (1 harm).
  • Lose yourself: Endure Stress (1 stress).
  • " + }, + { + filled: false, + name: "", + text: "When you Endure Harm 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 Resupply 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 Enter the Fray or Strike by sending your cat to attack, roll +edge. On a hit, take +2 momentum." + }, + { + filled: false, + name: "Protective", + text: "When you Make Camp, 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 ? `
    ${writeIn}
    ` : "" -} -const createDescription = (description) => { - return description ? `
    ${description}
    ` : "" -} + const createWriteIn = (writeIn) => { + return writeIn ? `
    ${writeIn}
    ` : "" + } -const createAbilitiesHtml = (abilities = []) => { - const createAbilityName = (name) => { - return name ? `${name}` : "" + const createDescription = (description) => { + return description ? `
    ${description}
    ` : "" } - return abilities.map((ability) => { - return `
    + + const createAbilitiesHtml = (abilities = []) => { + const createAbilityName = (name) => { + return name ? `${name}` : "" + } + return abilities.map((ability) => { + return `
    ${createAbilityName(ability.name)} ${ability.text}
    ` - }).join("") -} - -const createTrackValueHtml = (track, value) => { - if (value > track) { - return `
    ` - } else { - return `
    ${value}
    ` + }).join("") } -} -const createTrackHtml = (track) => { - if (!track) { - return "" - } else { - return `
    + const createTrackValueHtml = (track, value) => { + if (value > track) { + return `
    ` + } else { + return `
    ${value}
    ` + } + } + + const createTrackHtml = (track) => { + if (!track) { + return "" + } else { + return `
    0
    ${createTrackValueHtml(track, 1)} ${createTrackValueHtml(track, 2)} @@ -111,11 +112,11 @@ const createTrackHtml = (track) => { ${createTrackValueHtml(track, 4)} ${createTrackValueHtml(track, 5)}
    ` + } } -} -const createAssetHtml = (asset = {}) => { - return `
    + const createAssetHtml = (asset = {}) => { + return `
    ${asset.type}
    @@ -134,36 +135,38 @@ const createAssetHtml = (asset = {}) => {
    ${createTrackHtml(asset.track)}
    ` -} + } -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() +})() \ No newline at end of file