From 69ae8f7e05108fae094ace02e771886e96642194 Mon Sep 17 00:00:00 2001 From: Jason Wilson Date: Thu, 10 Aug 2023 21:14:38 -0400 Subject: [PATCH] rebundle --- dist/bundle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/bundle.js b/dist/bundle.js index cbafc66..8480f35 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -1 +1 @@ -(()=>{"use strict";class t{name;constructor(t){this.name=t}enter(){console.log(`Entering ${this.name} state.`)}exit(){console.log(`Exiting ${this.name} state.`)}update(){console.log(`Updating ${this.name} state.`)}}class e extends t{constructor(t,e){super("Battle"),this.mob=t,this.player=e,console.log(t)}enter(){super.enter(),this.battleInterval=window.setInterval((function(){this.mob.applyDMG(this.player.cachedStats.damage)}),1e3)}exit(){super.exit(),window.clearInterval(this.battleInterval)}update(){super.update()}}class s extends t{constructor(){super("Idle")}enter(){super.enter()}exit(){super.exit()}update(){super.update()}}class a extends t{constructor(){super("Death")}enter(){super.enter()}exit(){super.exit()}update(){super.update()}}const n=new Map,i=t=>{const e=n.get(t);if(e)return e;const s=document.getElementById(t);if(!s)throw new TypeError(`Nothing with "${t}" was found.`);return n.set(t,s),s};function r(t,e){var s,a,n;for(a=document.getElementsByClassName("tabcontent"),s=0;s{const s=document.createElement("div");s.classList.add("inventory-item-card");const a=document.createElement("h4");if(a.textContent=e.name,s.appendChild(a),e.image){const t=document.createElement("img");t.src=e.image,t.classList.add("inventory-item-image"),s.appendChild(t)}const n=document.createElement("p");n.textContent=e.description,s.appendChild(n);const i=document.createElement("p"),r=Object.entries(e.stats).map((([t,e])=>`${t}: ${e}`));i.textContent=r.join(", "),s.appendChild(i),s.addEventListener("click",(()=>{const t=document.querySelector(".inventory-item-card-selected");t&&t.classList.remove("inventory-item-card-selected"),s.classList.add("inventory-item-card-selected")})),t.appendChild(s)}))}calculateTotalStats(){let t={str:0,sta:0,agi:0,dex:0,wis:0,int:0,cha:0,health:0,damage:0};return this.items.forEach((e=>{Object.keys(e.stats).forEach((s=>{t[s]+=e.stats[s]}))})),t}}window.openTab=r;let l=new class{constructor(){this.maxHP=100,this.health=100,this.isDead=!1,this.malk=1e3,this.malkers=0,this.kills=0,this.inventory=new c(this),this.inventoryStats={},this.healthBar=i("player-health-bar"),this.baseStats={str:1,sta:1,agi:1,dex:1,wis:1,int:1,cha:1,health:10,damage:1},this.cachedStats={...this.baseStats},this.modifiers=[]}getStat(t){return this.cachedStats[t]}recalculateCachedStats(t){for(let e of t){this.cachedStats[e]=this.baseStats[e];for(let t of this.modifiers)!t.statsAffected[e]||t.condition&&!t.condition()||(this.cachedStats[e]+=t.statsAffected[e])}}removeMalk(t){return this.malk>=t&&(this.malk-=t,!0)}addMalk(t){this.malk+=t}addItemToInventory(t){this.inventory.addItem(t),this.inventory.populateGrid(),this.inventoryStats=this.inventory.calculateTotalStats(),this.updateStatsTable()}updateStatsTable(){const t=i("statsBody");for(;t.firstChild;)t.firstChild.remove();const e=this.inventoryStats;for(let[s,a]of Object.entries(e)){const e=document.createElement("tr"),n=document.createElement("td");n.textContent=s,e.appendChild(n);const i=document.createElement("td");i.textContent=a,e.appendChild(i),t.appendChild(e)}}},d=new class{constructor(t,e){this.maxHP=0,this.isDead=!1,this.type=t,this.player=e,this.monsterImage=i("monster"),this.healthBar=i("enemy-health-bar"),this.baseStats={str:1,sta:1,agi:1,dex:1,wis:1,int:1,cha:1,health:10,damage:1},this.health=this.calcHP(t,e),i("monster").addEventListener("click",(()=>this.applyDMG(1))),i("resetMob").addEventListener("click",(()=>this.resetMob()))}applyDMG(t){this.health<=0+t&&0==this.isDead?(this.health=0,this.isDead=!0,this.player.kills++,console.log(this.player.kills)):0==this.isDead&&(this.health-=t,this.player.malk+=t,this.monsterImage.classList.add("shrink"),setTimeout((()=>{this.monsterImage.classList.remove("shrink")}),150))}resetMob(){0!=this.isDead&&this.health<=0&&(this.isDead=!1),this.health=this.calcHP(this.type,this.player),this.monsterImage.classList.remove("mirrored"),this.monsterImage.classList.remove("flashing"),this.healthBar.style.backgroundColor="green"}calcHP(t,e){let s=Math.floor(10*Math.pow(1.02,this.baseStats.health*e.kills));return this.maxHP=s,s}}(50,l);new class{constructor(t){this.items=[],this.player=t;const e=i("buyButton");fetch("database/items.json").then((t=>t.json())).then((t=>{this.items=t,this.populateGrid()})).catch((t=>console.error("Error:",t))),e.addEventListener("click",(()=>{const t=document.querySelector(".shop-item-card-selected"),e=i("shopMessage");if(t){const s=t.getAttribute("data-id"),a=this.buyItem(this.player,s);e.textContent=a}else e.textContent="No item selected."}))}buyItem(t,e){let s=this.items.find((t=>t.id==e));return s?t.removeMalk(s.cost)?(t.addItemToInventory(s),`You bought ${s.name}!`):`You do not have enough malk. This item costs ${s.cost} and you only have ${t.malk} malk.`:"Item does not exist."}populateGrid(){const t=i("itemsGrid");this.items.forEach((e=>{const s=document.createElement("div");s.classList.add("shop-item-card"),s.setAttribute("data-id",e.id);const a=document.createElement("h4");if(a.textContent=e.name,s.appendChild(a),e.image){const t=document.createElement("img");t.src=e.image,t.classList.add("shop-item-image"),s.appendChild(t)}const n=document.createElement("p");n.textContent="Cost: "+e.cost,s.appendChild(n);const i=document.createElement("p");i.textContent=e.description,s.appendChild(i);const r=document.createElement("p"),o=Object.entries(e.stats).map((([t,e])=>`${t}: ${e}`));r.textContent=o.join(", "),s.appendChild(r),s.addEventListener("click",(()=>{const t=document.querySelector(".shop-item-card-selected");t&&t.classList.remove("shop-item-card-selected"),s.classList.add("shop-item-card-selected")})),t.appendChild(s)}))}addItemToShop(t){this.items.push(t)}}(l);const h=i("changeState"),m={battle:()=>new e(d,l),idle:()=>new s(d,l),death:()=>new a(d,l)},u=new class{constructor(t={},e){this.empty={update:function(){},enter:function(){},exit:function(){}},this.states=t,this.current=this.empty,this.buttonText=e}change(t,e){if(!this.states[t])throw new Error(`State ${t} does not exist`);this.current.exit(),this.current=this.states[t](),this.current.enter(e),this.buttonText.textContent=this.current.name}update(t){this.current.update(t)}}(m,h);h.addEventListener("click",(()=>{u.change("battle")}));const p=i("monster"),y=i("player-health-bar"),g=i("enemy-health-bar");i("tabButtonFight").addEventListener("click",(t=>r(t,"Fight"))),i("tabButtonStrategy").addEventListener("click",(t=>r(t,"Strategy"))),i("tabButtonInventory").addEventListener("click",(t=>r(t,"Inventory"))),i("tabButtonShop").addEventListener("click",(t=>r(t,"Shop"))),i("tabButtonStats").addEventListener("click",(t=>r(t,"Stats"))),i("buyMalker").addEventListener("click",(()=>function(t){let e=Math.floor(10*Math.pow(1.1,t.malkers));t.malk>=e&&(t.malkers++,t.malk=t.malk-e)}(l))),i("tabButtonFight").click(),function(){let t,e;fetch("database/actions.json").then((t=>t.json())).then((t=>{for(let e of t){let t=document.createElement("div");t.className="actionCard",t.draggable=!0;let s=document.createElement("h2");s.textContent=e.title,t.appendChild(s);let a=document.createElement("p");a.textContent=e.description,t.appendChild(a),i("playerActionList").appendChild(t)}})),document.addEventListener("dragstart",(function(s){t=s.target,s.target.style.opacity=.5,e=[...t.parentNode.children].indexOf(t)}),!1),document.addEventListener("dragend",(function(t){t.target.style.opacity=""}),!1),document.querySelector("#playerActionQueue").addEventListener("dragover",(function(t){t.preventDefault()}),!1),document.querySelector("#playerActionQueue").addEventListener("drop",(function(e){e.preventDefault();const s=t.cloneNode(!0);s.style.opacity="";let a=e.target;for(;"playerActionQueue"!==a.id&&!a.classList.contains("actionCard")&&!a.classList.contains("queuedCard");)a=a.parentNode;if("playerActionQueue"===a.id)s.dataset.sequence=a.children.length+1,s.classList.replace("actionCard","queuedCard"),a.appendChild(s);else if("playerActionQueue"===t.parentNode.id){const e=s.dataset.sequence,n=a.dataset.sequence;s.dataset.sequence=n,a.dataset.sequence=e,a.parentNode.insertBefore(s,a),a.parentNode.insertBefore(a,t)}else s.classList.replace("actionCard","queuedCard"),s.dataset.sequence=a.parentNode.children.length+1,a.parentNode.insertBefore(s,a.nextSibling);"playerActionQueue"===t.parentNode.id&&t.parentNode.removeChild(t)}),!1)}(),window.setInterval((function(){!function(){i("malk").innerHTML=l.malk,i("malkers").innerHTML=l.malkers,i("enemyHP").innerHTML=d.health,i("totalKills").innerHTML=l.kills;let t=Math.floor(10*Math.pow(1.1,l.malkers));i("malkerCost").innerHTML=t}(),o(d,g,p),o(l,y)}),50)})(); \ No newline at end of file +(()=>{"use strict";class t{name;constructor(t){this.name=t}enter(){console.log(`Entering ${this.name} state.`)}exit(){console.log(`Exiting ${this.name} state.`)}update(){console.log(`Updating ${this.name} state.`)}}class e extends t{constructor(t,e){super("Battle"),this.mob=t,this.player=e}enter(){super.enter(),this.battleInterval=window.setInterval((()=>{this.mob.applyDMG(this.player.cachedStats.damage)}),1e3)}exit(){super.exit(),window.clearInterval(this.battleInterval)}update(){super.update()}}class s extends t{constructor(){super("Idle")}enter(){super.enter()}exit(){super.exit()}update(){super.update()}}class a extends t{constructor(){super("Death")}enter(){super.enter()}exit(){super.exit()}update(){super.update()}}const n=new Map,i=t=>{const e=n.get(t);if(e)return e;const s=document.getElementById(t);if(!s)throw new TypeError(`Nothing with "${t}" was found.`);return n.set(t,s),s};function r(t,e){var s,a,n;for(a=document.getElementsByClassName("tabcontent"),s=0;s{const s=document.createElement("div");s.classList.add("inventory-item-card");const a=document.createElement("h4");if(a.textContent=e.name,s.appendChild(a),e.image){const t=document.createElement("img");t.src=e.image,t.classList.add("inventory-item-image"),s.appendChild(t)}const n=document.createElement("p");n.textContent=e.description,s.appendChild(n);const i=document.createElement("p"),r=Object.entries(e.stats).map((([t,e])=>`${t}: ${e}`));i.textContent=r.join(", "),s.appendChild(i),s.addEventListener("click",(()=>{const t=document.querySelector(".inventory-item-card-selected");t&&t.classList.remove("inventory-item-card-selected"),s.classList.add("inventory-item-card-selected")})),t.appendChild(s)}))}calculateTotalStats(){let t={str:0,sta:0,agi:0,dex:0,wis:0,int:0,cha:0,health:0,damage:0};return this.items.forEach((e=>{Object.keys(e.stats).forEach((s=>{t[s]+=e.stats[s]}))})),t}}window.openTab=r;let l=new class{constructor(){this.maxHP=100,this.health=100,this.isDead=!1,this.malk=1e3,this.malkers=0,this.kills=0,this.inventory=new c(this),this.inventoryStats={},this.healthBar=i("player-health-bar"),this.baseStats={str:1,sta:1,agi:1,dex:1,wis:1,int:1,cha:1,health:10,damage:1},this.cachedStats={...this.baseStats},this.modifiers=[]}getStat(t){return this.cachedStats[t]}recalculateCachedStats(t){for(let e of t){this.cachedStats[e]=this.baseStats[e];for(let t of this.modifiers)!t.statsAffected[e]||t.condition&&!t.condition()||(this.cachedStats[e]+=t.statsAffected[e])}}removeMalk(t){return this.malk>=t&&(this.malk-=t,!0)}addMalk(t){this.malk+=t}addItemToInventory(t){this.inventory.addItem(t),this.inventory.populateGrid(),this.inventoryStats=this.inventory.calculateTotalStats(),this.updateStatsTable()}updateStatsTable(){const t=i("statsBody");for(;t.firstChild;)t.firstChild.remove();const e=this.inventoryStats;for(let[s,a]of Object.entries(e)){const e=document.createElement("tr"),n=document.createElement("td");n.textContent=s,e.appendChild(n);const i=document.createElement("td");i.textContent=a,e.appendChild(i),t.appendChild(e)}}},d=new class{constructor(t,e){this.maxHP=0,this.isDead=!1,this.type=t,this.player=e,this.monsterImage=i("monster"),this.healthBar=i("enemy-health-bar"),this.baseStats={str:1,sta:1,agi:1,dex:1,wis:1,int:1,cha:1,health:10,damage:1},this.health=this.calcHP(t,e),i("monster").addEventListener("click",(()=>this.applyDMG(1))),i("resetMob").addEventListener("click",(()=>this.resetMob()))}applyDMG(t){this.health<=0+t&&0==this.isDead?(this.health=0,this.isDead=!0,this.player.kills++,console.log(this.player.kills)):0==this.isDead&&(this.health-=t,this.player.malk+=t,this.monsterImage.classList.add("shrink"),setTimeout((()=>{this.monsterImage.classList.remove("shrink")}),150))}resetMob(){0!=this.isDead&&this.health<=0&&(this.isDead=!1),this.health=this.calcHP(this.type,this.player),this.monsterImage.classList.remove("mirrored"),this.monsterImage.classList.remove("flashing"),this.healthBar.style.backgroundColor="green"}calcHP(t,e){let s=Math.floor(10*Math.pow(1.02,this.baseStats.health*e.kills));return this.maxHP=s,s}}(50,l);new class{constructor(t){this.items=[],this.player=t;const e=i("buyButton");fetch("database/items.json").then((t=>t.json())).then((t=>{this.items=t,this.populateGrid()})).catch((t=>console.error("Error:",t))),e.addEventListener("click",(()=>{const t=document.querySelector(".shop-item-card-selected"),e=i("shopMessage");if(t){const s=t.getAttribute("data-id"),a=this.buyItem(this.player,s);e.textContent=a}else e.textContent="No item selected."}))}buyItem(t,e){let s=this.items.find((t=>t.id==e));return s?t.removeMalk(s.cost)?(t.addItemToInventory(s),`You bought ${s.name}!`):`You do not have enough malk. This item costs ${s.cost} and you only have ${t.malk} malk.`:"Item does not exist."}populateGrid(){const t=i("itemsGrid");this.items.forEach((e=>{const s=document.createElement("div");s.classList.add("shop-item-card"),s.setAttribute("data-id",e.id);const a=document.createElement("h4");if(a.textContent=e.name,s.appendChild(a),e.image){const t=document.createElement("img");t.src=e.image,t.classList.add("shop-item-image"),s.appendChild(t)}const n=document.createElement("p");n.textContent="Cost: "+e.cost,s.appendChild(n);const i=document.createElement("p");i.textContent=e.description,s.appendChild(i);const r=document.createElement("p"),o=Object.entries(e.stats).map((([t,e])=>`${t}: ${e}`));r.textContent=o.join(", "),s.appendChild(r),s.addEventListener("click",(()=>{const t=document.querySelector(".shop-item-card-selected");t&&t.classList.remove("shop-item-card-selected"),s.classList.add("shop-item-card-selected")})),t.appendChild(s)}))}addItemToShop(t){this.items.push(t)}}(l);const h=i("changeState"),m={battle:()=>new e(d,l),idle:()=>new s(d,l),death:()=>new a(d,l)},u=new class{constructor(t={},e){this.empty={update:function(){},enter:function(){},exit:function(){}},this.states=t,this.current=this.empty,this.buttonText=e}change(t,e){if(!this.states[t])throw new Error(`State ${t} does not exist`);this.current.exit(),this.current=this.states[t](),this.current.enter(e),this.buttonText.textContent=this.current.name}update(t){this.current.update(t)}}(m,h);h.addEventListener("click",(()=>{u.change("battle")}));const p=i("monster"),y=i("player-health-bar"),g=i("enemy-health-bar");i("tabButtonFight").addEventListener("click",(t=>r(t,"Fight"))),i("tabButtonStrategy").addEventListener("click",(t=>r(t,"Strategy"))),i("tabButtonInventory").addEventListener("click",(t=>r(t,"Inventory"))),i("tabButtonShop").addEventListener("click",(t=>r(t,"Shop"))),i("tabButtonStats").addEventListener("click",(t=>r(t,"Stats"))),i("buyMalker").addEventListener("click",(()=>function(t){let e=Math.floor(10*Math.pow(1.1,t.malkers));t.malk>=e&&(t.malkers++,t.malk=t.malk-e)}(l))),i("tabButtonFight").click(),function(){let t,e;fetch("database/actions.json").then((t=>t.json())).then((t=>{for(let e of t){let t=document.createElement("div");t.className="actionCard",t.draggable=!0;let s=document.createElement("h2");s.textContent=e.title,t.appendChild(s);let a=document.createElement("p");a.textContent=e.description,t.appendChild(a),i("playerActionList").appendChild(t)}})),document.addEventListener("dragstart",(function(s){t=s.target,s.target.style.opacity=.5,e=[...t.parentNode.children].indexOf(t)}),!1),document.addEventListener("dragend",(function(t){t.target.style.opacity=""}),!1),document.querySelector("#playerActionQueue").addEventListener("dragover",(function(t){t.preventDefault()}),!1),document.querySelector("#playerActionQueue").addEventListener("drop",(function(e){e.preventDefault();const s=t.cloneNode(!0);s.style.opacity="";let a=e.target;for(;"playerActionQueue"!==a.id&&!a.classList.contains("actionCard")&&!a.classList.contains("queuedCard");)a=a.parentNode;if("playerActionQueue"===a.id)s.dataset.sequence=a.children.length+1,s.classList.replace("actionCard","queuedCard"),a.appendChild(s);else if("playerActionQueue"===t.parentNode.id){const e=s.dataset.sequence,n=a.dataset.sequence;s.dataset.sequence=n,a.dataset.sequence=e,a.parentNode.insertBefore(s,a),a.parentNode.insertBefore(a,t)}else s.classList.replace("actionCard","queuedCard"),s.dataset.sequence=a.parentNode.children.length+1,a.parentNode.insertBefore(s,a.nextSibling);"playerActionQueue"===t.parentNode.id&&t.parentNode.removeChild(t)}),!1)}(),window.setInterval((function(){!function(){i("malk").innerHTML=l.malk,i("malkers").innerHTML=l.malkers,i("enemyHP").innerHTML=d.health,i("totalKills").innerHTML=l.kills;let t=Math.floor(10*Math.pow(1.1,l.malkers));i("malkerCost").innerHTML=t}(),o(d,g,p),o(l,y)}),50)})(); \ No newline at end of file