Browse Source

Major refactor; Add debug options;

master
Nero Ignis 4 years ago
parent
commit
af08c41508
  1. 5
      .idea/inspectionProfiles/Project_Default.xml
  2. 145
      index.html
  3. 231
      js/app.js

5
.idea/inspectionProfiles/Project_Default.xml

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="52" name="JavaScript" />
</Languages>
</inspection_tool>
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />

145
index.html

@ -24,42 +24,15 @@ @@ -24,42 +24,15 @@
</a>
<div class="card-body" id="collapseResources">
<div class="row">
<div class="col-md-12">
<div class="float-right">{{ getFormattedNumber(resources.gold) }} <img class="resource-icon" src="img/gold.png"></div>
Gold
</div>
<div class="col-md-12" v-if="resources.wood > 0">
<div class="float-right">{{ getFormattedNumber(resources.wood) }} <img class="resource-icon" src="img/wood.png"></div>
Wood
</div>
<div class="col-md-12" v-if="resources.planks > 0">
<div class="float-right">{{ getFormattedNumber(resources.planks) }} <img class="resource-icon" src="img/planks.png"></div>
Planks
</div>
<div class="col-md-12" v-if="resources.stone > 0">
<div class="float-right">{{ getFormattedNumber(resources.stone) }} <img class="resource-icon" src="img/stone.png"></div>
Stones
</div>
<div class="col-md-12" v-if="resources.coal > 0">
<div class="float-right">{{ getFormattedNumber(resources.coal) }} <img class="resource-icon" src="img/coal.png"></div>
Coal
</div>
<div class="col-md-12" v-if="resources.iron > 0">
<div class="float-right">{{ getFormattedNumber(resources.iron) }} <img class="resource-icon" src="img/iron.png"></div>
Iron
</div>
<div class="col-md-12" v-if="resources.corn > 0">
<div class="float-right">{{ getFormattedNumber(resources.corn) }} <img class="resource-icon" src="img/corn.png"></div>
Corn
</div>
<div class="col-md-12" v-if="resources.bricks > 0">
<div class="float-right">{{ getFormattedNumber(resources.bricks) }} <img class="resource-icon" src="img/bricks.png"></div>
Bricks
<div class="col-md-12" v-for="resource in resources" v-if="resource.amount > 0 || resource.name === 'Gold'">
<div class="float-right">{{ getFormattedNumber(resource.amount) }} <img class="resource-icon" :src="resource.icon"></div>
{{ resource.name }}
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card">
<a class="card-header" data-toggle="collapse" href="#collapseQuest" role="button" aria-expanded="true" aria-controls="collapseQuest">
@ -68,37 +41,24 @@ @@ -68,37 +41,24 @@
<div class="card-body" id="collapseQuest">
<div v-if="currentQuest">
Items needed: <br/>
<span v-if="currentQuest.wood > 0" :style="'color: ' + getColorForQuestResource(currentQuest.wood, resources.wood)">
<img title="wood" class="resource-icon" src="img/wood.png"> {{ currentQuest.wood }}
</span>
<span v-if="currentQuest.planks > 0" :style="'color: ' + getColorForQuestResource(currentQuest.planks, resources.planks)">
<img title="wood" class="resource-icon" src="img/planks.png"> {{ currentQuest.planks }}
</span>
<span v-if="currentQuest.stone > 0" :style="'color: ' + getColorForQuestResource(currentQuest.stone, resources.stone)">
<img title="stone" class="resource-icon" src="img/stone.png"> {{ currentQuest.stone }}
</span>
<span v-if="currentQuest.coal > 0" :style="'color: ' + getColorForQuestResource(currentQuest.coal, resources.coal)">
<img title="coal" class="resource-icon" src="img/coal.png"> {{ currentQuest.coal }}
</span>
<span v-if="currentQuest.iron > 0" :style="'color: ' + getColorForQuestResource(currentQuest.iron, resources.iron)">
<img title="iron" class="resource-icon" src="img/iron.png"> {{ currentQuest.iron }}
</span>
<span v-if="currentQuest.bricks > 0" :style="'color: ' + getColorForQuestResource(currentQuest.bricks, resources.bricks)">
<img title="bricks" class="resource-icon" src="img/bricks.png"> {{ currentQuest.bricks }}
</span>
<span v-if="currentQuest.corn > 0" :style="'color: ' + getColorForQuestResource(currentQuest.corn, resources.corn)">
<img title="corn" class="resource-icon" src="img/corn.png"> {{ currentQuest.corn }}
<span v-for="resource in resources" v-if="currentQuest[resource.name.toLowerCase()] > 0" :style="'color: ' + getColorForQuestResource(currentQuest[resource.name.toLowerCase()], resource.amount)">
<img :title="resource.name" class="resource-icon" :src="resource.icon"> {{ currentQuest[resource.name.toLowerCase()] }}
</span>
<br/>
<br/>
<a href="javascript:" class="btn btn-sm btn-success float-right" @click="redeemReward()">Redeem reward ({{ currentQuest.reward }} <img class="resource-icon" src="img/gold.png">)</a>
<a class="btn btn-sm btn-info float-right" style="margin-right: 1em;" @click="generateQuestWithRandomItems()"><i class="fas fa-question"></i> Get a new quest</a>
</div>
<div v-else>
<a class="btn btn-sm btn-info" @click="generateQuestWithRandomItems()"><i class="fas fa-question"></i> Get a new quest</a>
You don't have a quest at the moment. <br/>
<br/>
<br/>
<a class="btn btn-sm btn-info float-right" @click="generateQuestWithRandomItems()"><i class="fas fa-question"></i> Get a new quest</a>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<a class="card-header" data-toggle="collapse" href="#collapseOwned" role="button" aria-expanded="true" aria-controls="collapseOwned">
@ -163,47 +123,72 @@ @@ -163,47 +123,72 @@
<div class="col-md-12">
<div class="card">
<div class="card-header">Sandbox</div>
<a class="card-header" data-toggle="collapse" href="#collapseDebug" role="button" aria-expanded="true" aria-controls="collapseDebug">
<h3>Debug</h3>
</a>
<div class="card-body" id="collapseDebug">
<a href="https://git.luna-development.net/neroignis/idle-buildup/issues"><i class="fas fa-bug"></i> Found a bug?</a><br/>
<br/>
<input type="checkbox" v-model="debug.levelSandbox"> Buildings-Sandbox<br/>
<input type="checkbox" v-model="debug.buildingsSandbox"> Resource-Sandbox<br/>
<a class="btn btn-sm btn-danger" style="margin: 0.5em;" href="javascript:" @click="resources = {gold: 500,wood: 50,stone: 50,iron: 50,bricks: 50,corn: 50,coal: 50,planks: 50}">Reset resources</a>
<a class="btn btn-sm btn-danger" style="margin: 0.5em;" href="javascript:" @click="reset()">Soft reset (everything except resources)</a><br/>
<a class="btn btn-sm btn-danger" style="margin: 0.5em;" href="javascript:" @click="reset(true)">Hard reset (everything)</a><br/>
</div>
</div>
</div>
<div class="col-md-12" v-if="debug.levelSandbox">
<div class="card">
<div class="card-header">Buildings Sandbox</div>
<div class="card-body">
<template v-for="building in buildings" v-if="building.amountPerLevel || building.intervalPerLevel || building.pricePerLevel">
<h3><strong>{{ building.name }}</strong></h3>
Amout per Level:<br/>
<input class="form-control form-control-sandbox" type="text" v-for="amount in building.amountPerLevel" @change="saveBuildingsToStorage()" :value="amount"><br/>
<input class="form-control form-control-sandbox" type="text" v-for="amount in building.amountPerLevel" :value="amount"><br/>
Interval per Level:<br/>
<input class="form-control form-control-sandbox" type="text" v-for="interval in building.intervalPerLevel" @change="saveBuildingsToStorage()" :value="interval"><br/>
<input class="form-control form-control-sandbox" type="text" v-for="interval in building.intervalPerLevel" :value="interval"><br/>
Price per Level:<br/>
<input class="form-control form-control-sandbox" type="text" v-for="price in building.pricePerLevel" @change="saveBuildingsToStorage()" :value="price"><br/>
<input class="form-control form-control-sandbox" type="text" v-for="price in building.pricePerLevel" :value="price"><br/>
<hr/><br/>
</template>
</div>
</div>
</div>
<div class="col-md-12">
<div class="col-md-12" v-if="debug.buildingsSandbox">
<div class="card">
<a class="card-header" data-toggle="collapse" href="#collapseDebug" role="button" aria-expanded="true" aria-controls="collapseDebug">
<h3>Debug</h3>
</a>
<div class="card-body" id="collapseDebug">
<h3>Known bugs</h3><br/>
<ul class="list-group">
<li class="list-group-item">
Blacksmith is broken at the moment and corrupts the resource-storage. <br/>
<a class="btn btn-sm btn-danger" href="javascript:" @click="removeBlackSmith()">Click here to fix it for now</a>
</li>
</ul>
<br/>
<hr/>
<br/>
<a href="https://git.luna-development.net/neroignis/idle-buildup/issues"><i class="fas fa-bug"></i> Found a bug?</a>
<br/>
<hr/>
<br/>
<a class="btn btn-sm btn-danger" href="javascript:" @click="resources = {gold: 500,wood: 50,stone: 50,iron: 50,bricks: 50,corn: 50,coal: 50,planks: 50}">Reset resources</a>
<br/>
<br/>
<a class="btn btn-sm btn-danger" href="javascript:" @click="reset()">Soft reset (everything except resources)</a><br/>
<a class="btn btn-sm btn-danger" href="javascript:" @click="reset(true)">Hard reset (everything)</a><br/>
<div class="card-header">Resource Sandbox</div>
<div class="card-body">
<template v-for="resource in resources">
<h3><strong>{{ resource.name }}</strong></h3>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="">Name</label>
<input class="form-control" type="text" v-model="resource.name">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="">Worth</label>
<input class="form-control" type="text" v-model="resource.worth">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="">Amount</label>
<input class="form-control" type="text" v-model="resource.amount">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="">Unlocked</label><br/>
<input type="checkbox" v-model="resource.unlocked">
</div>
</div>
</div>
</template>
</div>
</div>
</div>

231
js/app.js

@ -1,25 +1,68 @@ @@ -1,25 +1,68 @@
let game = new Vue({
el: '#root',
data: {
version: 0.5,
version: 0.6,
debug: {
levelSandbox: false,
buildingsSandbox: false
},
resources: {
gold: 0,
wood: 0,
stone: 0,
iron: 0,
bricks: 0,
corn: 0,
coal: 0,
planks: 0
},
hadResource: {
wood: false,
stone: false,
iron: false,
bricks: false,
corn: false,
coal: false,
planks: false
gold: {
amount: 500,
name: 'Gold',
worth: 100,
icon: 'img/gold.png',
unlocked: true
},
wood: {
amount: 0,
name: 'Wood',
worth: 10,
icon: 'img/wood.png',
unlocked: false
},
stone: {
amount: 0,
name: 'Stone',
worth: 25,
icon: 'img/stone.png',
unlocked: false
},
iron: {
amount: 0,
name: 'Iron',
worth: 100,
icon: 'img/iron.png',
unlocked: false
},
bricks: {
amount: 0,
name: 'Bricks',
worth: 200,
icon: 'img/bricks.png',
unlocked: false
},
corn: {
amount: 0,
name: 'Corn',
worth: 75,
icon: 'img/corn.png',
unlocked: false
},
coal: {
amount: 0,
name: 'Coal',
worth: 25,
icon: 'img/coal.png',
unlocked: false
},
planks: {
amount: 0,
name: 'Planks',
worth: 100,
icon: 'img/planks.png',
unlocked: false
}
},
storageNames: null,
buildings: [
@ -145,7 +188,6 @@ let game = new Vue({ @@ -145,7 +188,6 @@ let game = new Vue({
this.storageNames = {
lastVersion: 'lastVersion',
resources: 'resources' + this.version,
hadResource: 'hadResource' + this.version,
buildings: 'buildings' + this.version,
currentQuest: 'currentQuest' + this.version
}
@ -153,7 +195,6 @@ let game = new Vue({ @@ -153,7 +195,6 @@ let game = new Vue({
this.checkVersion();
this.checkBuildings();
this.loadHadResourceFromStorage();
this.loadResourcesFromStorage();
this.currentQuest = JSON.parse(localStorage.getItem(this.storageNames.currentQuest));
@ -221,70 +262,58 @@ let game = new Vue({ @@ -221,70 +262,58 @@ let game = new Vue({
}
},
// Save resources a user ever had to generate quests
saveHadResourceToStorage() {
localStorage.setItem(this.storageNames.hadResource, JSON.stringify(this.hadResource));
},
loadHadResourceFromStorage: function () {
let savedHadResource = JSON.parse(localStorage.getItem(this.storageNames.hadResource));
if (savedHadResource) {
this.hadResource = savedHadResource;
}
},
// Resource-Management
add(amount = 0, resource = 'gold') {
switch (resource) {
case 'wood':
this.sendResourceMessage(amount, 'wood');
this.resources.wood += amount;
this.hadResource.wood = true;
console.log(this.resources.wood.amount, amount);
this.resources.wood.amount += amount;
this.resources.wood.unlocked = true;
break;
case 'planks':
this.sendResourceMessage(amount, 'planks');
this.resources.planks += amount;
this.hadResource.planks = true;
this.resources.planks.amount += amount;
this.resources.planks.unlocked = true;
break;
case 'stone':
this.sendResourceMessage(amount, 'stone');
this.resources.stone += amount;
this.hadResource.stone = true;
this.resources.stone.amount += amount;
this.resources.stone.unlocked = true;
break;
case 'bricks':
this.sendResourceMessage(amount, 'bricks');
this.resources.bricks += amount;
this.hadResource.bricks = true;
this.resources.bricks.amount += amount;
this.resources.bricks.unlocked = true;
break;
case 'coal':
this.sendResourceMessage(amount, 'coal');
this.resources.coal += amount;
this.hadResource.coal = true;
this.resources.coal.amount += amount;
this.resources.coal.unlocked = true;
break;
case 'iron':
this.sendResourceMessage(amount, 'iron');
this.resources.iron += amount;
this.hadResource.iron = true;
this.resources.iron.amount += amount;
this.resources.iron.unlocked = true;
break;
case 'corn':
this.sendResourceMessage(amount, 'corn');
this.resources.corn += amount;
this.hadResource.corn = true;
this.resources.corn.amount += amount;
this.resources.corn.unlocked = true;
break;
case 'gold':
this.sendResourceMessage(amount, 'gold');
this.resources.gold += amount;
this.hadResource.gold = true;
this.resources.gold.amount += amount;
this.resources.gold.unlocked = true;
break;
}
this.saveHadResourceToStorage();
this.$forceUpdate();
this.saveResourcesToStorage();
},
sub(amount = 0, resource = false) {
this.resources.gold -= amount;
this.resources.gold.amount -= amount;
return this.saveResourcesToStorage();
},
@ -294,6 +323,9 @@ let game = new Vue({ @@ -294,6 +323,9 @@ let game = new Vue({
this.buildings.forEach((building) => {
if (building.isOwned && !building.hasMissingResources) {
building.price = building.pricePerLevel[building.level -1];
building.amount = building.amountPerLevel[building.level -1];
building.interval = building.intervalPerLevel[building.level -1];
vue.initiateIntervals(building);
}
});
@ -337,9 +369,12 @@ let game = new Vue({ @@ -337,9 +369,12 @@ let game = new Vue({
},
buyBuilding(building) {
if (this.resources.gold >= building.price) {
if (this.resources.gold.amount >= building.price) {
this.sub(building.price);
building.isOwned = true;
building.price = building.pricePerLevel[0];
building.amount = building.amountPerLevel[0];
building.interval = building.intervalPerLevel[0];
this.upgradeBuilding(building, true);
this.saveBuildingsToStorage();
@ -349,12 +384,12 @@ let game = new Vue({ @@ -349,12 +384,12 @@ let game = new Vue({
},
buyUpgrade(building) {
if (building.level === 'X') {
if (building.level === building.maxLevel) {
this.sendWarning('Already at MAX-Level');
return false;
}
if (this.resources.gold >= building.price) {
if (this.resources.gold.amount >= building.price) {
this.sub(building.price);
this.upgradeBuilding(building);
} else {
@ -376,9 +411,9 @@ let game = new Vue({ @@ -376,9 +411,9 @@ let game = new Vue({
}
building.price = building.pricePerLevel[building.level - 1];
building.amount = building.amountPerLevel[building.level - 1];
if (first === false) {
building.amount = building.amountPerLevel[building.level - 1];
building.intervalInSeconds = building.intervalPerLevel[building.level - 1];
}
@ -397,12 +432,12 @@ let game = new Vue({ @@ -397,12 +432,12 @@ let game = new Vue({
buildingHasEnoughResourcesToStart(building) {
if (building.requires) {
return (
building.requires.wood > this.resources.wood ||
building.requires.stone > this.resources.stone ||
building.requires.iron > this.resources.iron ||
building.requires.bricks > this.resources.bricks ||
building.requires.coal > this.resources.coal ||
building.requires.corn > this.resources.corn
building.requires.wood > this.resources.wood.amount ||
building.requires.stone > this.resources.stone.amount ||
building.requires.iron > this.resources.iron.amount ||
building.requires.bricks > this.resources.bricks.amount ||
building.requires.coal > this.resources.coal.amount ||
building.requires.corn > this.resources.corn.amount
);
} else {
return true;
@ -426,39 +461,39 @@ let game = new Vue({ @@ -426,39 +461,39 @@ let game = new Vue({
let rewardSum = 0;
if (this.hadResource.wood > 0) {
if (this.resources.wood.unlocked > 0) {
randomWood = this.getRandomElementForQuestResource(possibleAmountsForQuest);
rewardSum += (randomWood * 5);
rewardSum += (randomWood * this.resources.wood.worth);
}
if (this.hadResource.stone > 0) {
if (this.resources.stone.unlocked > 0) {
randomStone = this.getRandomElementForQuestResource(possibleAmountsForQuest);
rewardSum += (randomStone * 7);
rewardSum += (randomStone * this.resources.stone.worth);
}
if (this.hadResource.iron > 0) {
if (this.resources.iron.unlocked > 0) {
randomIron = this.getRandomElementForQuestResource(possibleAmountsForQuest);
rewardSum += (randomIron * 200);
rewardSum += (randomIron * this.resources.iron.worth);
}
if (this.hadResource.bricks > 0) {
if (this.resources.bricks.unlocked > 0) {
randomBricks = this.getRandomElementForQuestResource(possibleAmountsForQuest);
rewardSum += (randomBricks * 25);
rewardSum += (randomBricks * this.resources.bricks.worth);
}
if (this.hadResource.corn > 0) {
if (this.resources.corn.unlocked > 0) {
randomCorn = this.getRandomElementForQuestResource(possibleAmountsForQuest);
rewardSum += (randomCorn * 30);
rewardSum += (randomCorn * this.resources.corn.worth);
}
if (this.hadResource.coal > 0) {
if (this.resources.coal.unlocked > 0) {
randomCoal = this.getRandomElementForQuestResource(possibleAmountsForQuest);
rewardSum += (randomCoal * 10);
rewardSum += (randomCoal * this.resources.coal.worth);
}
if (this.hadResource.planks > 0) {
if (this.resources.planks.unlocked > 0) {
randomPlanks = this.getRandomElementForQuestResource(possibleAmountsForQuest);
rewardSum += (randomPlanks * 5);
rewardSum += (randomPlanks * this.resources.planks.worth);
}
if (rewardSum > 0) {
@ -486,12 +521,12 @@ let game = new Vue({ @@ -486,12 +521,12 @@ let game = new Vue({
},
isQuestRedeemable() {
let enoughWood = this.resources.wood >= this.currentQuest.wood;
let enoughStone = this.resources.stone >= this.currentQuest.stone;
let enoughIron = this.resources.iron >= this.currentQuest.iron;
let enoughBricks = this.resources.bricks >= this.currentQuest.bricks;
let enoughCorn = this.resources.corn >= this.currentQuest.corn;
let enoughCoal = this.resources.coal >= this.currentQuest.coal;
let enoughWood = this.resources.wood.amount >= this.currentQuest.wood;
let enoughStone = this.resources.stone.amount >= this.currentQuest.stone;
let enoughIron = this.resources.iron.amount >= this.currentQuest.iron;
let enoughBricks = this.resources.bricks.amount >= this.currentQuest.bricks;
let enoughCorn = this.resources.corn.amount >= this.currentQuest.corn;
let enoughCoal = this.resources.coal.amount >= this.currentQuest.coal;
if (enoughWood && enoughStone && enoughIron && enoughBricks && enoughCorn && enoughCoal) {
return true;
@ -502,13 +537,13 @@ let game = new Vue({ @@ -502,13 +537,13 @@ let game = new Vue({
redeemReward() {
if (this.isQuestRedeemable()) {
this.resources.gold += this.currentQuest.reward;
this.resources.wood -= this.currentQuest.wood;
this.resources.stone -= this.currentQuest.stone;
this.resources.iron -= this.currentQuest.iron;
this.resources.bricks -= this.currentQuest.bricks;
this.resources.corn -= this.currentQuest.corn;
this.resources.coal -= this.currentQuest.coal;
this.resources.gold.amount += this.currentQuest.reward;
this.resources.wood.amount -= this.currentQuest.wood;
this.resources.stone.amount -= this.currentQuest.stone;
this.resources.iron.amount -= this.currentQuest.iron;
this.resources.bricks.amount -= this.currentQuest.bricks;
this.resources.corn.amount -= this.currentQuest.corn;
this.resources.coal.amount -= this.currentQuest.coal;
this.sendRewardMessage(this.currentQuest.reward);
this.generateQuestWithRandomItems();
@ -519,12 +554,12 @@ let game = new Vue({ @@ -519,12 +554,12 @@ let game = new Vue({
},
useRequiredResources(building) {
this.resources.wood -= building.requires.wood;
this.resources.stone -= building.requires.stone;
this.resources.iron -= building.requires.iron;
this.resources.bricks -= building.requires.bricks;
this.resources.corn -= building.requires.corn;
this.resources.coal -= building.requires.coal;
this.resources.wood.amount -= (building.requires.wood ? building.requires.wood : 0);
this.resources.stone.amount -= (building.requires.stone ? building.requires.stone : 0);
this.resources.iron.amount -= (building.requires.iron ? building.requires.iron : 0);
this.resources.bricks.amount -= (building.requires.bricks ? building.requires.bricks : 0);
this.resources.corn.amount -= (building.requires.corn ? building.requires.corn : 0);
this.resources.coal.amount -= (building.requires.coal ? building.requires.coal : 0);
},
// Templating
@ -623,16 +658,8 @@ let game = new Vue({ @@ -623,16 +658,8 @@ let game = new Vue({
});
},
// Debug & Testing
removeBlackSmith() {
this.buildings[5].isOwned = false;
this.saveBuildingsToStorage();
location.reload();
},
reset(hard = false) {
localStorage.removeItem('buildings' + this.version);
localStorage.removeItem('hadResource' + this.version);
localStorage.removeItem('currentQuest' + this.version);
if (hard) {

Loading…
Cancel
Save