mirror of
https://github.com/Acamaeda/The-Modding-Tree.git
synced 2024-11-24 17:31:50 +00:00
Put an end to convertToDecimal
This commit is contained in:
parent
1ae02a4328
commit
199485a87a
5 changed files with 54 additions and 28 deletions
|
@ -131,11 +131,6 @@ Key:
|
||||||
Without it, the default is to reset everything on the row, but only
|
Without it, the default is to reset everything on the row, but only
|
||||||
if it was triggered by a layer in a higher row.
|
if it was triggered by a layer in a higher row.
|
||||||
|
|
||||||
- convertToDecimal(): **sometimes required**, required if you add non-standard Decimals to startData.
|
|
||||||
This function converts those values from a string to a Decimal (used when loading).
|
|
||||||
Convert a value to Decimal with `value = new Decimal(value)`
|
|
||||||
|
|
||||||
|
|
||||||
- update(diff): **optional**, this function is called every game tick. Use it for any passive resource production or
|
- update(diff): **optional**, this function is called every game tick. Use it for any passive resource production or
|
||||||
time-based things. diff is the time since the last tick.
|
time-based things. diff is the time since the last tick.
|
||||||
Suggestion: use addPoints(layer, gain) when generating points to automatically
|
Suggestion: use addPoints(layer, gain) when generating points to automatically
|
||||||
|
|
|
@ -49,6 +49,15 @@
|
||||||
</div>
|
</div>
|
||||||
<div v-if="player.tab=='changelog'" class="col right">
|
<div v-if="player.tab=='changelog'" class="col right">
|
||||||
<button class="back" onclick="showTab('tree')">←</button><br><br><br>
|
<button class="back" onclick="showTab('tree')">←</button><br><br><br>
|
||||||
|
<h3>v1.3.5</h3>
|
||||||
|
<ul>
|
||||||
|
<li>The system now handles convertToDecimal for everything automatically!</li>
|
||||||
|
</ul>
|
||||||
|
<h3>v1.3.4</h3>
|
||||||
|
<ul>
|
||||||
|
<li>Added "midsection" feature to add things to a tab's layout while still keeping the standard layout.</li>
|
||||||
|
<li>Fix for being able to buy more buyables than you should.</li>
|
||||||
|
</ul><br>
|
||||||
<h3>v1.3.3</h3>
|
<h3>v1.3.3</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Fix for the "order of operations" issue in temp.</li>
|
<li>Fix for the "order of operations" issue in temp.</li>
|
||||||
|
|
20
js/game.js
20
js/game.js
|
@ -5,7 +5,7 @@ var NaNalert = false;
|
||||||
var gameEnded = false;
|
var gameEnded = false;
|
||||||
|
|
||||||
let VERSION = {
|
let VERSION = {
|
||||||
num: "1.3.4",
|
num: "1.3.5 maybe",
|
||||||
name: "Tabception... ception!"
|
name: "Tabception... ception!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,24 +35,6 @@ function inChallenge(layer, id){
|
||||||
return layers[layer].challs[id].countsAs.includes(id)
|
return layers[layer].challs[id].countsAs.includes(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToDecimal() {
|
|
||||||
player.points = new Decimal(player.points)
|
|
||||||
for (layer in layers) {
|
|
||||||
player[layer].points = new Decimal(player[layer].points)
|
|
||||||
if (player[layer].best != undefined) player[layer].best = new Decimal(player[layer].best)
|
|
||||||
if (player[layer].total !== undefined) player[layer].total = new Decimal(player[layer].total)
|
|
||||||
player[layer].spentOnBuyables = new Decimal(player[layer].spentOnBuyables)
|
|
||||||
|
|
||||||
if (player[layer].buyables != undefined) {
|
|
||||||
for (id in player[layer].buyables)
|
|
||||||
player[layer].buyables[id] = new Decimal(player[layer].buyables[id])
|
|
||||||
}
|
|
||||||
player[layer].best = new Decimal(player[layer].best)
|
|
||||||
|
|
||||||
if (layers[layer].convertToDecimal) layers[layer].convertToDecimal();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getResetGain(layer, useType = null) {
|
function getResetGain(layer, useType = null) {
|
||||||
let type = useType
|
let type = useType
|
||||||
if (!useType) type = layers[layer].type
|
if (!useType) type = layers[layer].type
|
||||||
|
|
|
@ -167,9 +167,6 @@ addLayer("c", {
|
||||||
doReset(resettingLayer){ // Triggers when this layer is being reset, along with the layer doing the resetting. Not triggered by lower layers resetting, but is by layers on the same row.
|
doReset(resettingLayer){ // Triggers when this layer is being reset, along with the layer doing the resetting. Not triggered by lower layers resetting, but is by layers on the same row.
|
||||||
if(layers[resettingLayer].row > this.row) fullLayerReset(this.layer) // This is actually the default behavior
|
if(layers[resettingLayer].row > this.row) fullLayerReset(this.layer) // This is actually the default behavior
|
||||||
},
|
},
|
||||||
convertToDecimal() {
|
|
||||||
// Convert any layer-specific Decimal values (besides points, total, and best) from String to Decimal (used when loading save)
|
|
||||||
},
|
|
||||||
layerShown() {return true}, // Condition for when layer appears on the tree
|
layerShown() {return true}, // Condition for when layer appears on the tree
|
||||||
update(diff) {
|
update(diff) {
|
||||||
if (player[this.layer].upgrades.includes(11)) player.points = player.points.add(tmp.pointGen.times(diff)).max(0)
|
if (player[this.layer].upgrades.includes(11)) player.points = player.points.add(tmp.pointGen.times(diff)).max(0)
|
||||||
|
|
45
js/utils.js
45
js/utils.js
|
@ -107,6 +107,48 @@ function getStartPlayer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fixSave() {
|
function fixSave() {
|
||||||
|
defaultData = getStartPlayer()
|
||||||
|
fixData(defaultData, player)
|
||||||
|
|
||||||
|
for(layer in layers)
|
||||||
|
{
|
||||||
|
if (player[layer].best !== undefined) player[layer].best = new Decimal (player[layer].best)
|
||||||
|
if (player[layer].total !== undefined) player[layer].total = new Decimal (player[layer].total)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fixData(defaultData, newData) {
|
||||||
|
for (item in defaultData){
|
||||||
|
if (defaultData[item] == null) {
|
||||||
|
if (newData[item] === undefined)
|
||||||
|
newData[item] = null
|
||||||
|
}
|
||||||
|
else if (Array.isArray(defaultData[item])) {
|
||||||
|
if (newData[item] === undefined)
|
||||||
|
newData[item] = defaultData[item]
|
||||||
|
else
|
||||||
|
fixData(defaultData[item], newData[item])
|
||||||
|
}
|
||||||
|
else if (defaultData[item] instanceof Decimal) { // Convert to Decimal
|
||||||
|
if (newData[item] === undefined)
|
||||||
|
newData[item] = defaultData[item]
|
||||||
|
else
|
||||||
|
newData[item] = new Decimal(newData[item])
|
||||||
|
}
|
||||||
|
else if ((!!defaultData[item]) && (defaultData[item].constructor === Object)) {
|
||||||
|
if (newData[item] === undefined)
|
||||||
|
newData[item] = defaultData[item]
|
||||||
|
else
|
||||||
|
fixData(defaultData[item], newData[item])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (newData[item] === undefined)
|
||||||
|
newData[item] = defaultData[item]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hecj() {
|
||||||
defaultData = startPlayerBase()
|
defaultData = startPlayerBase()
|
||||||
for (datum in defaultData){
|
for (datum in defaultData){
|
||||||
if (player[datum] == undefined){
|
if (player[datum] == undefined){
|
||||||
|
@ -154,6 +196,8 @@ function fixSave() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
let get = localStorage.getItem(modInfo.id);
|
let get = localStorage.getItem(modInfo.id);
|
||||||
if (get===null || get===undefined) player = getStartPlayer()
|
if (get===null || get===undefined) player = getStartPlayer()
|
||||||
|
@ -166,7 +210,6 @@ function load() {
|
||||||
player.offTime.remain += (Date.now() - player.time) / 1000
|
player.offTime.remain += (Date.now() - player.time) / 1000
|
||||||
}
|
}
|
||||||
player.time = Date.now();
|
player.time = Date.now();
|
||||||
convertToDecimal();
|
|
||||||
versionCheck();
|
versionCheck();
|
||||||
changeTheme();
|
changeTheme();
|
||||||
changeTreeQuality();
|
changeTreeQuality();
|
||||||
|
|
Loading…
Reference in a new issue