1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-28 02:51:55 +00:00

Added multiple challenge completions

This commit is contained in:
Acamaeda 2020-10-11 16:42:32 -04:00
parent dee1f93298
commit 9b035a2280
7 changed files with 59 additions and 29 deletions

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -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
}
}
}

View file

@ -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<br>"+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

View file

@ -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){

View file

@ -96,9 +96,9 @@ function loadVue() {
Vue.component('chall', {
props: ['layer', 'data'],
template: `
<div v-if="layers[layer].challs && layers[layer].challs[data]!== undefined && tmp[layer].challs[data].unl && !(player.hideChalls && hasChall(layer, [data]))" v-bind:class="{hChall: true, done: player[layer].challs.includes(data), canComplete: player[layer].active == data&&!player[layer].challs.includes(data)&&canCompleteChall(layer, data)}">
<div v-if="layers[layer].challs && layers[layer].challs[data]!== undefined && tmp[layer].challs[data].unl && !(player.hideChalls && hasChall(layer, [data]))" v-bind:class="{hChall: true, done: hasChall(layer, data), canComplete: player[layer].active == data&&!hasChall(layer, data)&&canCompleteChall(layer, data)}">
<br><h3 v-html="tmp[layer].challs[data].name"></h3><br><br>
<button v-bind:class="{ longUpg: true, can: true, [layer]: true }" v-bind:style="{'background-color': tmp[layer].color}" v-on:click="startChall(layer, data)">{{player[layer].active==(data)?(canCompleteChall(layer, data)?"Finish":"Exit Early"):(player[layer].challs.includes(data)?"Completed":"Start")}}</button><br><br>
<button v-bind:class="{ longUpg: true, can: true, [layer]: true }" v-bind:style="{'background-color': tmp[layer].color}" v-on:click="startChall(layer, data)">{{player[layer].active==(data)?(canCompleteChall(layer, data)?"Finish":"Exit Early"):(hasChall(layer, data)?"Completed":"Start")}}</button><br><br>
<span v-html="tmp[layer].challs[data].desc"></span><br>
Goal: {{format(tmp[layer].challs[data].goal)}} {{tmp[layer].challs[data].currencyDisplayName ? tmp[layer].challs[data].currencyDisplayName : "points"}}<br>
Reward: <span v-html="tmp[layer].challs[data].reward"></span><br>