Ammonite is a small library made for incremental games.
- Small (under ~3Kb)
- Immutable leverages Immutable.js constructs
- Functional focuses on pure functions, helps ensure fewer side-effects
npm install ammonite --save
import { Amount, AmountStore, Metric, NewEntryOptions } from 'ammonite';
Amount is a class that Ammonite uses to control metrics. Its constructor takes a List
of an item that has the same subset of properties as Metric
(see Metric for more information). It uses a list as an easy way to maintain a record of all valuesβin a lot of incremental games, this ability is often lost, as it simply mutates a single value over time.
Property | Type | Optional? | Default |
---|---|---|---|
load |
List<T extends Metric> |
No | |
treatAsInteger |
boolean | Yes | false |
load
is theList
treatAsInteger
will round the value after each evaluation
This is the constructor function for the Amount class. Remember that it requires an interface which extends from Metric.
Example
interface Dogs {
total: number;
averageWoof: number;
averageBark: number;
}
let dogs = new Amount(List<Dogs>(), true);
Returns all items in the load.
Returns an exact copy of Amount
.
Note: not of load
, but of the class itself.
Returns the first item in the load.
Returns the last item in the load.
Return the last item item in the load (alias for last()
).
Returns the size of the load.
Pushes a new value to the load and returns the new load.
Note that the type of n
must satisfy T
, which is F-bounded to Metric
.
Returns the sum of the given property. Note that the property itself should be of type number
.
Example
amount.sum('total');
Returns a true if v
is included in the load.
Returns false otherwise.
Returns a new sorted List
C
generic corresponds to the type of the propertyprop
is the property accessor for theMetric
property
Example
amount.sort<number>(prop: 'total');
amount.sort<number>(prop: 'time');
amount.sort<string>(prop: 'alphabet');
Increments the last value of the load and then returns a new load with the added value pushed onto it.
See NewEntryOptions<T>
for more information.
Example
amount.load = amount.increment(43);
amount.load = amount.increment(1.057, { exponential: true });
Same as increment, except it substracts the given value, i.e. decrement(43)
would subtract 43 from the most recent value.
AmountStore<K, V>
is a class for managing all instances of Amount
.
Property | Type | Optional? | Default |
---|---|---|---|
store |
Map<K, Amount<V>> |
No |
Under most cases K
will be a string, but it can also be a number.
Returns the Amount
which belongs to the key.
Returns the store.
Returns a new Map after settings a new value for the given key.
Returns an Iterator from the keys of store
.
Returns a new Map
with the updated value at the given key.
Performs a given side-effect.
Returns the number of times the side-effect was produced.
Metric is an interface that is F-bounded to Amount
.
Property | Type | Optional? | Default |
---|---|---|---|
total |
number | No | |
time |
number | Yes | |
[prop: string] | any | Yes |
All generic types of Amount
must extend from Metric
. This is easy to do with extends
.
interface Click extends Metric {
total: number;
doubleClick?: boolean;
}
NewEntryOptions is the interface for new additions via increment
and decrement
.
Property | Type | Optional? | Default |
---|---|---|---|
exponential |
number | No | |
extra |
any | Yes |
exponential
determines whether the increment number is treated as an exponentialextra
is for additional metadata that may be required
It's this.
Ammonite made by Freepik from www.flaticon.com is licensed by CC 3.0 BY. Code licensed under MIT