pages/assets/public_lit_docs_buyables.md.079ec120.js

16 lines
10 KiB
JavaScript

import{_ as s,c as a,o as n,a as l}from"./app.4bcfb575.js";const h=JSON.parse('{"title":"Buyables","description":"","frontmatter":{},"headers":[],"relativePath":"public/lit/docs/buyables.md","lastUpdated":null}'),o={name:"public/lit/docs/buyables.md"},e=l(`<h1 id="buyables" tabindex="-1">Buyables <a class="header-anchor" href="#buyables" aria-hidden="true">#</a></h1><p>Buyables are usually things that can be bought multiple times with scaling costs. If you set a respec function, the player can reset the purchases to get their currency back.</p><p>The amount of a buyable owned is a <code>Decimal</code>.</p><p>Useful functions for dealing with buyables and implementing their effects:</p><ul><li>getBuyableAmount(layer, id): get the amount of the buyable the player has</li><li>setBuyableAmount(layer, id, amount): set the amount of the buyable the player has</li><li>buyableEffect(layer, id): Returns the current effects of the buyable, if any.</li></ul><p>Buyables should be formatted like this:</p><div class="language-js"><button class="copy"></button><span class="lang">js</span><pre><code><span class="line"><span style="color:#FFCB6B;">buyables</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;"> </span><span style="color:#FFCB6B;">rows</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> # </span><span style="color:#89DDFF;">of</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">rows</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;"> </span><span style="color:#FFCB6B;">cols</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> # </span><span style="color:#89DDFF;">of</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">columns</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;"> </span><span style="color:#F78C6C;">11</span><span style="color:#F07178;">: </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;"> cost</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">x</span><span style="color:#89DDFF;">)</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">return</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">new</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">Decimal</span><span style="color:#F07178;">(</span><span style="color:#F78C6C;">1</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">mul</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">x</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">||</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">getBuyableAmt</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">this.</span><span style="color:#A6ACCD;">layer</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">this.</span><span style="color:#A6ACCD;">id</span><span style="color:#F07178;">)) </span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#F07178;"> display</span><span style="color:#89DDFF;">()</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">return</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">Blah</span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#F07178;"> canAfford</span><span style="color:#89DDFF;">()</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">return</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">player</span><span style="color:#F07178;">[</span><span style="color:#89DDFF;">this.</span><span style="color:#A6ACCD;">layer</span><span style="color:#F07178;">]</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">points</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">gte</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">this.</span><span style="color:#82AAFF;">cost</span><span style="color:#F07178;">()) </span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#F07178;"> buy</span><span style="color:#89DDFF;">()</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">player</span><span style="color:#F07178;">[</span><span style="color:#89DDFF;">this.</span><span style="color:#A6ACCD;">layer</span><span style="color:#F07178;">]</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">points</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">player</span><span style="color:#F07178;">[</span><span style="color:#89DDFF;">this.</span><span style="color:#A6ACCD;">layer</span><span style="color:#F07178;">]</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">points</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">sub</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">this.</span><span style="color:#82AAFF;">cost</span><span style="color:#F07178;">())</span></span>
<span class="line"><span style="color:#F07178;"> </span><span style="color:#82AAFF;">setBuyableAmount</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">this.</span><span style="color:#A6ACCD;">layer</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">this.</span><span style="color:#A6ACCD;">id</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">getBuyableAmt</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">this.</span><span style="color:#A6ACCD;">layer</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">this.</span><span style="color:#A6ACCD;">id</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">add</span><span style="color:#F07178;">(</span><span style="color:#F78C6C;">1</span><span style="color:#F07178;">))</span></span>
<span class="line"><span style="color:#F07178;"> </span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">etc</span></span>
<span class="line"><span style="color:#F07178;"> </span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">etc</span></span>
<span class="line"><span style="color:#89DDFF;">}</span></span>
<span class="line"></span></code></pre></div><p>Features:</p><ul><li><p>title: <strong>optional</strong>. displayed at the top in a larger font. It can also be a function that returns updating text.</p></li><li><p>cost(): cost for buying the next buyable. Can have an optional argument &quot;x&quot; to calculate the cost of the x+1th object, but needs to use &quot;current amount&quot; as a default value for x. (x is a <code>Decimal</code>). Can return an object if there are multiple currencies.</p></li><li><p>effect(): <strong>optional</strong>. A function that calculates and returns the current values of bonuses of this buyable. Can return a value or an object containing multiple values.</p></li><li><p>display(): A function returning everything that should be displayed on the buyable after the title, likely including the description, amount bought, cost, and current effect. Can use basic HTML.</p></li><li><p>unlocked(): <strong>optional</strong>. A function returning a bool to determine if the buyable is visible or not. Default is unlocked.</p></li><li><p>canAfford(): A function returning a bool to determine if you can buy one of the buyables.</p></li><li><p>buy(): A function that implements buying one of the buyable, including spending the currency.</p></li><li><p>buyMax(): <strong>optional</strong>. A function that implements buying as many of the buyable as possible.</p></li><li><p>style: <strong>optional</strong>. Applies CSS to this buyable, in the form of an object where the keys are CSS attributes, and the values are the values for those attributes (both as strings).</p></li><li><p>layer: <strong>assigned automagically</strong>. It&#39;s the same value as the name of this layer, so you can do <code>player[this.layer].points</code> or similar.</p></li><li><p>id: <strong>assigned automagically</strong>. It&#39;s the &quot;key&quot; which the buyable was stored under, for convenient access. The buyable in the example&#39;s id is 11.</p></li></ul><p>Sell One/Sell All:</p><p>Including a <code>sellOne</code> or <code>sellAll</code> function will cause an additional button to appear beneath the buyable. They are functionally identical, but &quot;sell one&quot; appears above &quot;sell all&quot;. You can also use them for other things.</p><ul><li><p>sellOne/sellAll(): <strong>optional</strong>. Called when the button is pressed. The standard use would be to decrease/reset the amount of the buyable, and possibly return some currency to the player.</p></li><li><p>canSellOne/canSellAll(): <strong>optional</strong>. booleans determining whether or not to show the buttons. If &quot;canSellOne/All&quot; is absent but &quot;sellOne/All&quot; is present, the appropriate button will always show.</p></li></ul>`,12),t=[e];function p(r,c,y,i,F,u){return n(),a("div",null,t)}const b=s(o,[["render",p]]);export{h as __pageData,b as default};