-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathselection.ts
More file actions
65 lines (54 loc) · 1.65 KB
/
selection.ts
File metadata and controls
65 lines (54 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*!
* Debug Stick -- A Bedrock port of the debug stick tool from Java Edition.
* Copyright (c) 2023-2026 Vincent Yanzee J. Tan <https://vytdev.github.io>
*
* This project is licensed under the MIT License.
* This software is provided "as is" without warranty of any kind.
* See LICENSE for the full terms.
*/
import type { BlockType, StateName } from './types';
// TODO: try dynamic properties
const record: Record<string, Record<BlockType, StateName>> = {};
/**
* @class
* Manages the selected states of a debug stick item.
*/
export class DebugStateSelections {
/**
* @constructor
* Creates a new DebugStateSelections instance.
* @param id The persistence ID.
*/
constructor(id: string) {
this.id = id;
this._selections = record[id] ?? (record[id] = {});
}
/**
* @readonly
* The persistence ID.
*/
readonly id: string;
/**
* @private
* A table of selected block states.
*/
private _selections: Record<BlockType, StateName>;
/**
* Get the currently selected state of the debug stick tool for the given
* block type.
* @param blockType The block type identifier.
* @returns The selected state or null if not yet set.
*/
getSelectedStateForBlock(blockType: BlockType): StateName | null {
return this._selections[blockType] ?? null;
}
/**
* Set the currently selected state of the debug stick tool for the given
* block type.
* @param blockType The block type identifier.
* @param stateName The name of the block state to be set as selected.
*/
setSelectedStateForBlock(blockType: BlockType, stateName: StateName): void {
this._selections[blockType] = stateName;
}
}