From 9b035a22801c84c39aee221546604406e0484440 Mon Sep 17 00:00:00 2001 From: Acamaeda Date: Sun, 11 Oct 2020 16:42:32 -0400 Subject: [PATCH] Added multiple challenge completions --- changelog.md | 4 ++++ docs/challenges.md | 3 +++ js/game.js | 28 ++++++---------------------- js/layerSupport.js | 3 +++ js/layers.js | 5 +++-- js/utils.js | 41 ++++++++++++++++++++++++++++++++++++++--- js/v.js | 4 ++-- 7 files changed, 59 insertions(+), 29 deletions(-) diff --git a/changelog.md b/changelog.md index a0434f5..f14dd85 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ #The Modding Tree changelog: +Added clickables, a more generalized variant of buyables! +Support for multiple completions of challenges. +Added getter/setter functions for buyable amount and such Moved modInfo to game.js, added a spot for a Discord link, and a separate mod version from the TMT version Tree structure is based on layer data, no index.html needed. Tmp does not need to be manually updated. @@ -8,6 +11,7 @@ You don't have to have the same amount of upgrades in every row (and challs and Unl is optional for all Big Components (defaults to true). effectDisplay in Challenges and Upgrades no longer takes an argument, as well as buyable effect. Buyable cost can take an argument for amount of buyables, but if one is not supplied it should do the cost of the next buyable. +All displays will update correctly. ##v1.3.5 - Completely automated convertToDecimal, now you never have to worry about it again. diff --git a/docs/challenges.md b/docs/challenges.md index b684d98..ad715a6 100644 --- a/docs/challenges.md +++ b/docs/challenges.md @@ -4,6 +4,7 @@ Useful functions for dealing with Challenges and implementing their effects: - inChall(layer, id): determine if the player is in a given challenge (or another challenge on the same layer that counts as this one) - hasChall(layer, id): determine if the player has completed the challenge +- challCompletions(layer, id): determine if the player has completed the challenge - challEffect(layer, id): Returns the current effects of the challenge, if any @@ -54,6 +55,8 @@ By default, challenges use basic Points for the goal. You can change that using - currencyLayer: **optional**, the internal name of the layer that currency is stored in. If it's part of a layer, omit. +- completionLimit: **optional**, the amount of times you can complete this challenge. Default is 1 completion. + - style: **Optional**, A CSS object, which affects this challenge. - layer: **Assigned automagically**. It's the same value as the name of this layer, so you can do player[this.layer].points or similar diff --git a/js/game.js b/js/game.js index a1e2439..8c6ae9e 100644 --- a/js/game.js +++ b/js/game.js @@ -154,25 +154,6 @@ function resetBuyables(layer){ player[layer].spentOnBuyables = new Decimal(0) } -function getStartBuyables(layer){ - let data = {} - if (layers[layer].buyables) { - for (id in layers[layer].buyables) - if (!isNaN(id)) - data[id] = new Decimal(0) - } - return data -} - -function getStartClickables(layer){ - let data = {} - if (layers[layer].buyables) { - for (id in layers[layer].buyables) - if (!isNaN(id)) - data[id] = "" - } - return data -} function addPoints(layer, gain) { player[layer].points = player[layer].points.add(gain).max(0) @@ -292,10 +273,13 @@ function canCompleteChall(layer, x) function completeChall(layer, x) { var x = player[layer].active if (!x) return - if (! canCompleteChall(layer, x)) return - if (!player[layer].challs.includes(x)) { + if (! canCompleteChall(layer, x)){ + delete player[layer].active + return + } + if (player[layer].challs[x] < tmp[layer].challs[x].completionLimit) { needCanvasUpdate = true - player[layer].challs.push(x); + player[layer].challs[x] += 1 if (layers[layer].challs[x].onComplete) layers[layer].challs[x].onComplete() } delete player[layer].active diff --git a/js/layerSupport.js b/js/layerSupport.js index ff463bc..4f250d0 100644 --- a/js/layerSupport.js +++ b/js/layerSupport.js @@ -58,6 +58,9 @@ function updateLayers(){ layers[layer].challs[thing].layer = layer if (layers[layer].challs[thing].unl === undefined) layers[layer].challs[thing].unl = true + if (layers[layer].challs[thing].completionLimit === undefined) + layers[layer].challs[thing].completionLimit = 1 + } } } diff --git a/js/layers.js b/js/layers.js index 448b44f..cb714c2 100644 --- a/js/layers.js +++ b/js/layers.js @@ -64,8 +64,9 @@ addLayer("c", { rows: 2, cols: 12, 11: { - name:() => "Fun", - desc:() => "Makes the game 0% harder", + name:() => "Fun", + completionLimit: 3, + desc() {return "Makes the game 0% harder
"+challCompletions(this.layer, this.id) + "/" + this.completionLimit + " completions"}, unl() { return player[this.layer].best.gt(0) }, goal:() => new Decimal("20"), currencyDisplayName: "lollipops", // Use if using a nonstandard currency diff --git a/js/utils.js b/js/utils.js index 3ddc27a..7e5fc6f 100644 --- a/js/utils.js +++ b/js/utils.js @@ -93,7 +93,7 @@ function getStartPlayer() { playerdata[layer].spentOnBuyables = new Decimal(0) playerdata[layer].upgrades = [] playerdata[layer].milestones = [] - playerdata[layer].challs = [] + playerdata[layer].challs = getStartChalls(layer) if (layers[layer].tabFormat && !Array.isArray(layers[layer].tabFormat)) { playerdata.subtabs[layer] = {} playerdata.subtabs[layer].mainTabs = Object.keys(layers[layer].tabFormat)[0] @@ -107,6 +107,37 @@ function getStartPlayer() { return playerdata } + +function getStartBuyables(layer){ + let data = {} + if (layers[layer].buyables) { + for (id in layers[layer].buyables) + if (!isNaN(id)) + data[id] = new Decimal(0) + } + return data +} + +function getStartClickables(layer){ + let data = {} + if (layers[layer].clickables) { + for (id in layers[layer].clickables) + if (!isNaN(id)) + data[id] = "" + } + return data +} + +function getStartChalls(layer){ + let data = {} + if (layers[layer].challs) { + for (id in layers[layer].challs) + if (!isNaN(id)) + data[id] = 0 + } + return data +} + function fixSave() { defaultData = getStartPlayer() fixData(defaultData, player) @@ -137,7 +168,7 @@ function fixData(defaultData, newData) { newData[item] = new Decimal(newData[item]) } else if ((!!defaultData[item]) && (defaultData[item].constructor === Object)) { - if (newData[item] === undefined) + if (newData[item] === undefined || (defaultData[item].constructor !== Object)) newData[item] = defaultData[item] else fixData(defaultData[item], newData[item]) @@ -338,7 +369,11 @@ function hasMilestone(layer, id){ } function hasChall(layer, id){ - return (player[layer].challs.includes(toNumber(id)) || player[layer].challs.includes(id.toString())) + return (player[layer].challs[id]) +} + +function challCompletions(layer, id){ + return (player[layer].challs[id]) } function getBuyableAmt(layer, id){ diff --git a/js/v.js b/js/v.js index 9b88198..22390d6 100644 --- a/js/v.js +++ b/js/v.js @@ -96,9 +96,9 @@ function loadVue() { Vue.component('chall', { props: ['layer', 'data'], template: ` -
+



-

+


Goal: {{format(tmp[layer].challs[data].goal)}} {{tmp[layer].challs[data].currencyDisplayName ? tmp[layer].challs[data].currencyDisplayName : "points"}}
Reward: