-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaseblock2.ts
More file actions
112 lines (93 loc) · 3.1 KB
/
caseblock2.ts
File metadata and controls
112 lines (93 loc) · 3.1 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//import { SwitchContext } from "./classes/switchcontext";
//import { SwitchManager } from "./classes/switchmanager";
namespace switchcase {
/**
* TODO: [X] Import SwitchManager and SwitchContext
* TODO: [X] Hook-Up SwitchManager and SwitchContext (and switchBlock?)
* TODO: [ ] Does caseBlockValue need to have the pointer decorator (to point to switchBlock)?
* TODO: [ ] Can we put a test "game" inside this project?
* TODO: [ ] If we do the above (test "game"), will it bloat people's games who import our switchcase extension? Options?
* TODO: [ ] Assign Iconic FFVII Green to the Master Group and it's Children blocks
* TODO: [ ] Create Master Group for each of these subgroups and blocks
* TODO: [X] Assign weight so that Master Group is higher up in the list
* TODO: [ ] Assign [Advanced] to Master Group so it is only available for advanced users (maybe?)
* TODO: [ ] Need Subgroups... How to implement?
*/
/**
* Switch Block
* File: "switch.ts"
* switchBlock(value: any);
* block: "switch $value"
* blockId: switchcase_switch_block
* group: "Control"
* weight: 90
* draggableParameters
* draggableStatements=true
*
*/
/**
* Switch Context
* File: "classes/switchcontext.ts"
* SwitchContext { }
*
*/
/**
* Switch Manager
* File: "classes/switchmanager.ts"
* SwitchManager { }
*
*/
/**
* Case Block Container
*/
//% block="case $match do $handler"
//% blockId=switchcase_case_block
//% group="Core"
//% weight=90
//% draggableParameters=reporter
//% draggableStatement=reporter
export function caseBlock(name: string, match: any, handler: () => void): void {
//Placeholder for CodeGen
//currentSwitchCase.addCase(match, handler)
//let cxt = switchManager.get
//this should try to get before creating, so unless that changes,
// this code should suffice as uber simple as it is...
let cxt = switchcase.createSwitch(name);
if (cxt) {
cxt.addCase(match, handler);
}
// else {
// cxt = switchcase.getSwitch(name);
// }
// cxt.addCase(match, handler);
}
/**
* Case Block Value
* Outside of debugging, testing, or rare niche scenarios: this may not be useful
*/
//% block="[Advanced/Test/Debug] switch $name matches case $match?"
//% blockId=switchcase_case_block_value
//% group="Advanced"
//% weight=80
//% draggableParameters=reporter
export function caseBlockValue(name: string, match: any): boolean {
//return match === switchValue || match == switchValue;
let cxt = switchcase.createSwitch(name);
if (cxt && cxt.IsValueSet)
return cxt.matches(match);
return false;
}
/**
* Default-Case Block Container
*/
//% block="default case"
//% blockId=switchcase_default_case_block
//% group="Control"
//% weight=70
//% draggableStatement=enabled
export function defaultCaseBlock(name: string, handler: () => void): void {
let cxt = switchcase.createSwitch(name);
if (cxt)
cxt.addDefault(handler);
}
}