Skip to content

Commit 8be1e04

Browse files
committed
Add more comments
1 parent dc4611c commit 8be1e04

6 files changed

Lines changed: 47 additions & 11 deletions

File tree

src/ts/buildings.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import ClickerCookie from "./clickercookie.js";
21
import { capitalize, commaify, clamp } from "./helper.js";
32
import { Game } from "./main.js";
43
import { SaveProvider } from "./saving.js";
54
import { hideTooltip } from "./tooltip.js";
65

76
export interface BuildingData {
8-
/** Display name for your building. Should be capitialized. */
7+
/** Display name for your building. Should be capitalized. */
98
name: string;
10-
/** *Plural* display name for your building. Should be capitialized. */
9+
/** *Plural* display name for your building. Should be capitalized. */
1110
namePlural: string;
1211
quote: string;
13-
/** Base upgrade cost for the building. */
12+
/** Base upgrade cost for the building. Multiplied by {@link upgradeCostMultiplier} when building is bought. */
1413
upgradeCost: number;
1514
CPSGain: number;
1615
img?: string;
17-
/** Default is 1.15 */
16+
/** How much {@link upgradeCost} is multiplied by when building is bought. Default is 1.15 */
1817
upgradeCostMultiplier?: number;
1918
/**
2019
* Returns a boolean based on whether the building may be unlocked.

src/ts/handler.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import { StringifiedIdentifier } from "./helper.js";
22

3+
/**
4+
* Handlers are the core feature for all content in the game. They store and manage different types of objects, such as buildings, upgrades, mods, and more.
5+
*
6+
* Each handler uses {@link Identifier}s to uniquely identify and retrieve objects (with the exception of {@link UniqueKeyHandler}s).
7+
*
8+
* Globally accessible handlers are stored in the {@link Handlers} class. These handlers are treated specially throughout the codebase to manage their respective content types. Generally, you will not create your own handlers if you are making a mod that does not drastically modify the game's core systems.
9+
*
10+
* Handlers can also be iterated over like so:
11+
* ```ts
12+
* for (const obj of handler) {
13+
* console.log(obj);
14+
* }
15+
* ```
16+
*/
317
export class Handler<T> implements Iterable<T> {
418
/** This stores the stringified Identifier as the key and then the values is obviously T. We store the identifier stringified because objects are never equal so we can't `get()` from the Map without using the same obj reference. */
519
protected registered: Map<StringifiedIdentifier, T>;
@@ -123,6 +137,13 @@ export class UniqueKeyHandler<T> implements Iterable<T> {
123137
}
124138
}
125139

140+
/**
141+
* A unique identifier, usually for objects registered to {@link Handler}s.
142+
*
143+
* Identifiers are core to avoiding name collisions. If two mods were to register a building with the name `farm` then they would conflict with each other. The solution is to add a "namespace" such that these identifiers become `mod1:farm` and `mod2:farm`.
144+
*
145+
* If you are familiar with Minecraft mods these are functionally identical to how they are implemented there.
146+
*/
126147
export class Identifier {
127148
/**
128149
* Constructs a new {@link Identifier} from a stringified Identifier (from {@link Identifier.toString()}). If the string is not valid then a warning will be logged and `undefined` will be returned.

src/ts/helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export function commaify(toComma: number): string {
4949
return commaifyed;
5050
}
5151

52-
/** Oftentimes, because JS is a pain in the butt hole, number such as 128.2 may instead be 128.2000000000013. This is not very friendly to look at. This makes that number better.
52+
/**
53+
* Oftentimes, because CPUs are annoying, number such as 128.2 may instead be 128.2000000000013. This is not very friendly to look at. This makes that number better.
5354
*
5455
* Historically, we would use a seperate object for numbers that would be impacted by this that would automatically apply the calculations in this function (variableView), but I prefer this method instead.
5556
*

src/ts/mods.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
import { SaveProvider } from "./saving.js";
2-
import { ModHandler } from "./handlers.js";
2+
import { ModHandler, BackgroundHandler, CurrentlyClickedHandler } from "./handlers.js";
3+
import { Game } from "./main.js"
34

4-
type Kooh = "click" | "cps" | "loop" | "cps" | "personalization";
5+
/**
6+
* Koohs ("hooks" spelled backwards) serve as events that mods can register functions to be called on. Register functions using {@link Mod.registerKooh}.
7+
*
8+
* These will all automatically be called by {@link Game} at the appropriate times. Usually, you should not need to call these manually.
9+
*
10+
* | Kooh | When is it called? |
11+
* | --------------- | ------------- |
12+
* | click | When the cookie is clicked ({@link Game.cookieClicked()}) |
13+
* | cps | When CPS is given ({@link Game.cookiesPerSecondUpdate()}) |
14+
* | loop | Called in game loop ({@link Game.gameLoop()}) |
15+
* | personalization | Whenever a personalization option is changed ({@link BackgroundHandler.setBackground()}, {@link CurrentlyClickedHandler.setCurrentlyClicked()}) |
16+
*/
17+
type Kooh = "click" | "cps" | "loop" | "personalization";
518

619
interface ModMetadata {
720
name: string;
@@ -12,7 +25,7 @@ interface ModMetadata {
1225
}
1326

1427
/**
15-
* Provides high-level abstractions for mod developers to work with
28+
* Provides high-level abstractions for mod developers to work with. [Read the docs.](https://github.com/clickercookie/clickercookie.github.io/wiki/Modding)
1629
*/
1730
export class Mod<T> implements SaveProvider<T> {
1831
// ------------------
@@ -44,7 +57,7 @@ export class Mod<T> implements SaveProvider<T> {
4457
/** Mod namespace used for saving */
4558
public readonly NAMESPACE: string;
4659

47-
constructor(namespace: string, metadata: ModMetadata={name: undefined, description: undefined, img: undefined}) { //? should namespace be a param?
60+
constructor(namespace: string, metadata: ModMetadata={name: undefined, description: undefined, img: undefined}) {
4861
this.NAMESPACE = namespace;
4962

5063
this.METADATA = {

src/ts/saving.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,11 @@ export interface SaveProvider<T> {
175175
}
176176

177177
interface SaveDataHeader {
178+
/** Current game version ({@link Game.VERSION}) */
178179
version: string;
180+
/** Current game version branch ({@link Game.VERSION_BRANCH}) */
179181
versionBranch: VersionBranch;
182+
/** Format for this save. Currently is always set to `4` but major updates to the spec will increment this. */
180183
format: number
181184
}
182185

src/ts/upgrades.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Building } from "./buildings.js";
22
import { clamp, commaify, countVisibleChildren, url } from "./helper.js";
33
import { hideTooltip } from "./tooltip.js";
44
import { Game } from "./main.js";
5-
import ClickerCookie from "./clickercookie.js";
65
import { Handlers } from "./handlers.js";
76
import { SaveProvider } from "./saving.js";
87

0 commit comments

Comments
 (0)