1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-22 00:21:32 +00:00

Put an end to convertToDecimal

This commit is contained in:
Acamaeda 2020-10-08 19:42:26 -04:00
parent 1ae02a4328
commit 199485a87a
5 changed files with 54 additions and 28 deletions

View file

@ -131,11 +131,6 @@ Key:
Without it, the default is to reset everything on the row, but only
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
time-based things. diff is the time since the last tick.
Suggestion: use addPoints(layer, gain) when generating points to automatically

View file

@ -49,6 +49,15 @@
</div>
<div v-if="player.tab=='changelog'" class="col right">
<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>
<ul>
<li>Fix for the "order of operations" issue in temp.</li>

View file

@ -5,7 +5,7 @@ var NaNalert = false;
var gameEnded = false;
let VERSION = {
num: "1.3.4",
num: "1.3.5 maybe",
name: "Tabception... ception!"
}
@ -35,24 +35,6 @@ function inChallenge(layer, 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) {
let type = useType
if (!useType) type = layers[layer].type

View file

@ -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.
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
update(diff) {
if (player[this.layer].upgrades.includes(11)) player.points = player.points.add(tmp.pointGen.times(diff)).max(0)

View file

@ -107,6 +107,48 @@ function getStartPlayer() {
}
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()
for (datum in defaultData){
if (player[datum] == undefined){
@ -154,6 +196,8 @@ function fixSave() {
}
}
function load() {
let get = localStorage.getItem(modInfo.id);
if (get===null || get===undefined) player = getStartPlayer()
@ -166,7 +210,6 @@ function load() {
player.offTime.remain += (Date.now() - player.time) / 1000
}
player.time = Date.now();
convertToDecimal();
versionCheck();
changeTheme();
changeTreeQuality();