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:
parent
dee1f93298
commit
9b035a2280
7 changed files with 59 additions and 29 deletions
|
@ -1,5 +1,8 @@
|
||||||
#The Modding Tree changelog:
|
#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
|
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.
|
Tree structure is based on layer data, no index.html needed.
|
||||||
Tmp does not need to be manually updated.
|
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).
|
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.
|
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.
|
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
|
##v1.3.5
|
||||||
- Completely automated convertToDecimal, now you never have to worry about it again.
|
- Completely automated convertToDecimal, now you never have to worry about it again.
|
||||||
|
|
|
@ -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)
|
- 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
|
- 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
|
- 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.
|
- currencyLayer: **optional**, the internal name of the layer that currency is stored in.
|
||||||
If it's part of a layer, omit.
|
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.
|
- 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
|
- layer: **Assigned automagically**. It's the same value as the name of this layer, so you can do player[this.layer].points or similar
|
||||||
|
|
28
js/game.js
28
js/game.js
|
@ -154,25 +154,6 @@ function resetBuyables(layer){
|
||||||
player[layer].spentOnBuyables = new Decimal(0)
|
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) {
|
function addPoints(layer, gain) {
|
||||||
player[layer].points = player[layer].points.add(gain).max(0)
|
player[layer].points = player[layer].points.add(gain).max(0)
|
||||||
|
@ -292,10 +273,13 @@ function canCompleteChall(layer, x)
|
||||||
function completeChall(layer, x) {
|
function completeChall(layer, x) {
|
||||||
var x = player[layer].active
|
var x = player[layer].active
|
||||||
if (!x) return
|
if (!x) return
|
||||||
if (! canCompleteChall(layer, x)) return
|
if (! canCompleteChall(layer, x)){
|
||||||
if (!player[layer].challs.includes(x)) {
|
delete player[layer].active
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (player[layer].challs[x] < tmp[layer].challs[x].completionLimit) {
|
||||||
needCanvasUpdate = true
|
needCanvasUpdate = true
|
||||||
player[layer].challs.push(x);
|
player[layer].challs[x] += 1
|
||||||
if (layers[layer].challs[x].onComplete) layers[layer].challs[x].onComplete()
|
if (layers[layer].challs[x].onComplete) layers[layer].challs[x].onComplete()
|
||||||
}
|
}
|
||||||
delete player[layer].active
|
delete player[layer].active
|
||||||
|
|
|
@ -58,6 +58,9 @@ function updateLayers(){
|
||||||
layers[layer].challs[thing].layer = layer
|
layers[layer].challs[thing].layer = layer
|
||||||
if (layers[layer].challs[thing].unl === undefined)
|
if (layers[layer].challs[thing].unl === undefined)
|
||||||
layers[layer].challs[thing].unl = true
|
layers[layer].challs[thing].unl = true
|
||||||
|
if (layers[layer].challs[thing].completionLimit === undefined)
|
||||||
|
layers[layer].challs[thing].completionLimit = 1
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,9 @@ addLayer("c", {
|
||||||
rows: 2,
|
rows: 2,
|
||||||
cols: 12,
|
cols: 12,
|
||||||
11: {
|
11: {
|
||||||
name:() => "Fun",
|
name:() => "Fun",
|
||||||
desc:() => "Makes the game 0% harder",
|
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) },
|
unl() { return player[this.layer].best.gt(0) },
|
||||||
goal:() => new Decimal("20"),
|
goal:() => new Decimal("20"),
|
||||||
currencyDisplayName: "lollipops", // Use if using a nonstandard currency
|
currencyDisplayName: "lollipops", // Use if using a nonstandard currency
|
||||||
|
|
41
js/utils.js
41
js/utils.js
|
@ -93,7 +93,7 @@ function getStartPlayer() {
|
||||||
playerdata[layer].spentOnBuyables = new Decimal(0)
|
playerdata[layer].spentOnBuyables = new Decimal(0)
|
||||||
playerdata[layer].upgrades = []
|
playerdata[layer].upgrades = []
|
||||||
playerdata[layer].milestones = []
|
playerdata[layer].milestones = []
|
||||||
playerdata[layer].challs = []
|
playerdata[layer].challs = getStartChalls(layer)
|
||||||
if (layers[layer].tabFormat && !Array.isArray(layers[layer].tabFormat)) {
|
if (layers[layer].tabFormat && !Array.isArray(layers[layer].tabFormat)) {
|
||||||
playerdata.subtabs[layer] = {}
|
playerdata.subtabs[layer] = {}
|
||||||
playerdata.subtabs[layer].mainTabs = Object.keys(layers[layer].tabFormat)[0]
|
playerdata.subtabs[layer].mainTabs = Object.keys(layers[layer].tabFormat)[0]
|
||||||
|
@ -107,6 +107,37 @@ function getStartPlayer() {
|
||||||
return playerdata
|
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() {
|
function fixSave() {
|
||||||
defaultData = getStartPlayer()
|
defaultData = getStartPlayer()
|
||||||
fixData(defaultData, player)
|
fixData(defaultData, player)
|
||||||
|
@ -137,7 +168,7 @@ function fixData(defaultData, newData) {
|
||||||
newData[item] = new Decimal(newData[item])
|
newData[item] = new Decimal(newData[item])
|
||||||
}
|
}
|
||||||
else if ((!!defaultData[item]) && (defaultData[item].constructor === Object)) {
|
else if ((!!defaultData[item]) && (defaultData[item].constructor === Object)) {
|
||||||
if (newData[item] === undefined)
|
if (newData[item] === undefined || (defaultData[item].constructor !== Object))
|
||||||
newData[item] = defaultData[item]
|
newData[item] = defaultData[item]
|
||||||
else
|
else
|
||||||
fixData(defaultData[item], newData[item])
|
fixData(defaultData[item], newData[item])
|
||||||
|
@ -338,7 +369,11 @@ function hasMilestone(layer, id){
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasChall(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){
|
function getBuyableAmt(layer, id){
|
||||||
|
|
4
js/v.js
4
js/v.js
|
@ -96,9 +96,9 @@ function loadVue() {
|
||||||
Vue.component('chall', {
|
Vue.component('chall', {
|
||||||
props: ['layer', 'data'],
|
props: ['layer', 'data'],
|
||||||
template: `
|
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>
|
<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>
|
<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>
|
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>
|
Reward: <span v-html="tmp[layer].challs[data].reward"></span><br>
|
||||||
|
|
Loading…
Reference in a new issue