1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-22 08:31:33 +00:00
The-Modding-Tree/js/technical/temp.js

249 lines
7.1 KiB
JavaScript
Raw Normal View History

var tmp = {}
2020-12-04 04:19:14 +00:00
var temp = tmp // Proxy for tmp
var funcs = {}
2020-10-27 21:41:35 +00:00
var NaNalert = false;
2020-10-07 22:41:03 +00:00
// Tmp will not call these
var activeFunctions = [
"startData", "onPrestige", "doReset", "update", "automate",
2020-10-17 19:50:30 +00:00
"buy", "buyMax", "respec", "onComplete", "onPurchase", "onPress", "onClick", "masterButtonPress",
"sellOne", "sellAll", "pay", "actualCostFunction", "actualEffectFunction",
]
2020-10-07 20:41:45 +00:00
2020-10-17 04:21:59 +00:00
var noCall = doNotCallTheseFunctionsEveryTick
for (item in noCall) {
activeFunctions.push(noCall[item])
}
2020-12-01 02:58:42 +00:00
// Add the names of classes to traverse
var traversableClasses = []
function setupTemp() {
tmp = {}
tmp.pointGen = {}
tmp.displayThings = []
2021-01-25 00:05:01 +00:00
tmp.scrolled = 0
funcs = {}
2021-01-25 00:05:01 +00:00
setupTempData(layers, tmp, funcs)
for (layer in layers){
tmp[layer].resetGain = {}
tmp[layer].nextAt = {}
tmp[layer].nextAtDisp = {}
tmp[layer].canReset = {}
2020-11-08 04:34:53 +00:00
tmp[layer].notify = {}
tmp[layer].prestigeNotify = {}
tmp[layer].computedNodeStyle = []
2020-10-12 22:28:12 +00:00
setupBarStyles(layer)
setupBuyables(layer)
2020-10-09 03:13:15 +00:00
}
2020-12-04 04:19:14 +00:00
temp = tmp
}
function setupTempData(layerData, tmpData, funcsData) {
for (item in layerData){
if (layerData[item] == null) {
tmpData[item] = null
2020-09-14 02:41:42 +00:00
}
else if (layerData[item] instanceof Decimal)
tmpData[item] = layerData[item]
else if (Array.isArray(layerData[item])) {
tmpData[item] = []
funcsData[item] = []
setupTempData(layerData[item], tmpData[item], funcsData[item])
2020-10-03 19:45:47 +00:00
}
else if ((!!layerData[item]) && (layerData[item].constructor === Object)) {
tmpData[item] = {}
funcsData[item] = []
setupTempData(layerData[item], tmpData[item], funcsData[item])
2020-10-07 20:41:45 +00:00
}
2020-12-01 02:58:42 +00:00
else if ((!!layerData[item]) && (typeof layerData[item] === "object") && traversableClasses.includes(layerData[item].constructor.name)) {
tmpData[item] = new layerData[item].constructor()
funcsData[item] = new layerData[item].constructor()
2020-12-01 02:58:42 +00:00
}
else if (isFunction(layerData[item]) && !activeFunctions.includes(item)){
funcsData[item] = layerData[item]
tmpData[item] = new Decimal(1) // The safest thing to put probably?
} else {
tmpData[item] = layerData[item]
}
}
}
function updateTemp() {
if (tmp === undefined)
setupTemp()
updateTempData(layers, tmp, funcs)
for (layer in layers){
tmp[layer].resetGain = getResetGain(layer)
tmp[layer].nextAt = getNextAt(layer)
tmp[layer].nextAtDisp = getNextAt(layer, true)
tmp[layer].canReset = canReset(layer)
2020-11-08 04:34:53 +00:00
tmp[layer].notify = shouldNotify(layer)
tmp[layer].prestigeNotify = prestigeNotify(layer)
2020-10-12 22:28:12 +00:00
constructBarStyles(layer)
2020-12-09 06:13:20 +00:00
constructAchievementStyles(layer)
constructNodeStyle(layer)
2020-12-04 04:19:14 +00:00
updateChallengeDisplay(layer)
}
tmp.pointGen = getPointGen()
tmp.displayThings = []
for (thing in displayThings){
let text = displayThings[thing]
if (isFunction(text)) text = text()
tmp.displayThings.push(text)
}
}
function updateTempData(layerData, tmpData, funcsData) {
for (item in funcsData){
if (Array.isArray(layerData[item])) {
updateTempData(layerData[item], tmpData[item], funcsData[item])
2020-10-03 19:45:47 +00:00
}
2020-12-01 02:58:42 +00:00
else if ((!!layerData[item]) && (layerData[item].constructor === Object) || (typeof layerData[item] === "object") && traversableClasses.includes(layerData[item].constructor.name)){
updateTempData(layerData[item], tmpData[item], funcsData[item])
2020-10-09 03:13:15 +00:00
}
else if (isFunction(layerData[item]) && !isFunction(tmpData[item])){
2020-10-27 21:41:35 +00:00
let value = layerData[item]()
if (value !== value || value === decimalNaN){
2020-10-27 23:25:03 +00:00
if (NaNalert === true || confirm ("Invalid value found in tmp, named '" + item + "'. Please let the creator of this mod know! Would you like to try to auto-fix the save and keep going?")){
2020-10-27 21:41:35 +00:00
NaNalert = true
value = (value !== value ? 0 : decimalZero)
}
else {
clearInterval(interval);
player.autosave = false;
NaNalert = true;
}
}
Vue.set(tmpData, item, value)
}
}
}
function updateChallengeTemp(layer)
{
updateTempData(layers[layer].challenges, tmp[layer].challenges, funcs[layer].challenges)
2020-12-04 04:19:14 +00:00
updateChallengeDisplay(layer)
}
function updateChallengeDisplay(layer) {
for (id in player[layer].challenges) {
let style = "locked"
if (player[layer].activeChallenge == id && canCompleteChallenge(layer, id)) style = "canComplete"
else if (hasChallenge(layer, id)) style = "done"
tmp[layer].challenges[id].defaultStyle = style
tmp[layer].challenges[id].buttonText = (player[layer].activeChallenge==(id)?(canCompleteChallenge(layer, id)?"Finish":"Exit Early"):(hasChallenge(layer, id)?"Completed":"Start"))
}
}
function updateBuyableTemp(layer)
{
updateTempData(layers[layer].buyables, tmp[layer].buyables, funcs[layer].buyables)
2020-10-11 20:16:36 +00:00
}
function updateClickableTemp(layer)
{
updateTempData(layers[layer].clickables, tmp[layer].clickables, funcs[layer].clickables)
2020-10-12 22:28:12 +00:00
}
function constructNodeStyle(layer){
let style = []
if ((tmp[layer].isLayer && layerunlocked(layer)) || (!tmp[layer].isLayer && tmp[layer].canClick))
style.push({'background-color': tmp[layer].color})
if (tmp[layer].image !== undefined)
style.push({'background-image': 'url("' + tmp[layer].image + '")'})
style.push(tmp[layer].nodeStyle)
Vue.set(tmp[layer], 'computedNodeStyle', style)
}
2020-12-09 06:13:20 +00:00
function constructAchievementStyles(layer){
for (id in tmp[layer].achievements) {
ach = tmp[layer].achievements[id]
if (isPlainObject(ach)) {
let style = []
if (ach.image){
2020-12-09 06:36:27 +00:00
style.push({'background-image': 'url("' + ach.image + '")'})
2020-12-09 06:13:20 +00:00
}
if (!ach.unlocked) style.push({'visibility': 'hidden'})
style.push(ach.style)
Vue.set(ach, 'computedStyle', style)
}
}
}
2020-10-12 22:28:12 +00:00
function constructBarStyles(layer){
if (layers[layer].bars === undefined)
return
for (id in layers[layer].bars){
if (id !== "layer") {
let bar = tmp[layer].bars[id]
if (bar.progress instanceof Decimal)
bar.progress = bar.progress.toNumber()
2020-10-16 22:45:44 +00:00
bar.progress = (1 -Math.min(Math.max(bar.progress, 0), 1)) * 100
2020-10-12 22:28:12 +00:00
bar.dims = {'width': bar.width + "px", 'height': bar.height + "px"}
let dir = bar.direction
2020-10-16 22:45:44 +00:00
bar.fillDims = {'width': (bar.width + 0.5) + "px", 'height': (bar.height + 0.5) + "px"}
2020-10-12 22:28:12 +00:00
if (dir !== undefined)
{
2020-10-16 22:45:44 +00:00
bar.fillDims['clip-path'] = 'inset(0% 50% 0% 0%)'
if(dir == UP){
bar.fillDims['clip-path'] = 'inset(' + bar.progress + '% 0% 0% 0%)'
}
else if(dir == DOWN){
bar.fillDims['clip-path'] = 'inset(0% 0% ' + bar.progress + '% 0%)'
}
else if(dir == RIGHT){
bar.fillDims['clip-path'] = 'inset(0% ' + bar.progress + '% 0% 0%)'
}
else if(dir == LEFT){
bar.fillDims['clip-path'] = 'inset(0% 0% 0% ' + bar.progress + '%)'
}
2020-10-12 22:28:12 +00:00
}
}
}
}
function setupBarStyles(layer){
if (layers[layer].bars === undefined)
return
for (id in layers[layer].bars){
let bar = tmp[layer].bars[id]
bar.dims = {}
bar.fillDims = {}
}
}
function setupBuyables(layer) {
for (id in layers[layer].buyables) {
if (!isNaN(id)) {
let b = layers[layer].buyables[id]
b.actualCostFunction = b.cost
b.cost = function(x) {
x = x ?? player[this.layer].buyables[this.id]
return layers[this.layer].buyables[this.id].actualCostFunction(x)
}
b.actualEffectFunction = b.effect
b.effect = function(x) {
x = x ?? player[this.layer].buyables[this.id]
return layers[this.layer].buyables[this.id].actualEffectFunction(x)
}
}
}
2020-08-21 19:02:34 +00:00
}