|
| 1 | +//import { SwitchContext } from "./classes/switchcontext"; |
| 2 | +//import { SwitchManager } from "./classes/switchmanager"; |
| 3 | + |
| 4 | + |
| 5 | +namespace switchcase { |
| 6 | + |
| 7 | + |
| 8 | + /** |
| 9 | + * TODO: [X] Import SwitchManager and SwitchContext |
| 10 | + * TODO: [X] Hook-Up SwitchManager and SwitchContext (and switchBlock?) |
| 11 | + * TODO: [ ] Does caseBlockValue need to have the pointer decorator (to point to switchBlock)? |
| 12 | + * TODO: [ ] Can we put a test "game" inside this project? |
| 13 | + * TODO: [ ] If we do the above (test "game"), will it bloat people's games who import our switchcase extension? Options? |
| 14 | + * TODO: [ ] Assign Iconic FFVII Green to the Master Group and it's Children blocks |
| 15 | + * TODO: [ ] Create Master Group for each of these subgroups and blocks |
| 16 | + * TODO: [X] Assign weight so that Master Group is higher up in the list |
| 17 | + * TODO: [ ] Assign [Advanced] to Master Group so it is only available for advanced users (maybe?) |
| 18 | + * TODO: [ ] Need Subgroups... How to implement? |
| 19 | + */ |
| 20 | + |
| 21 | + /** |
| 22 | + * Switch Block |
| 23 | + * File: "switch.ts" |
| 24 | + * switchBlock(value: any); |
| 25 | + * block: "switch $value" |
| 26 | + * blockId: switchcase_switch_block |
| 27 | + * group: "Control" |
| 28 | + * weight: 90 |
| 29 | + * draggableParameters |
| 30 | + * draggableStatements=true |
| 31 | + * |
| 32 | + */ |
| 33 | + |
| 34 | + /** |
| 35 | + * Switch Context |
| 36 | + * File: "classes/switchcontext.ts" |
| 37 | + * SwitchContext { } |
| 38 | + * |
| 39 | + */ |
| 40 | + |
| 41 | + /** |
| 42 | + * Switch Manager |
| 43 | + * File: "classes/switchmanager.ts" |
| 44 | + * SwitchManager { } |
| 45 | + * |
| 46 | + */ |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + /** |
| 51 | + * Case Block Container |
| 52 | + */ |
| 53 | + //% block="case $match do $handler" |
| 54 | + //% blockId=switchcase_case_block |
| 55 | + //% group="Control" |
| 56 | + //% weight=90 |
| 57 | + //% draggableParameters |
| 58 | + //% draggableStatement=true |
| 59 | + export function caseBlock(name: string, match: any, handler: () => void): void { |
| 60 | + //Placeholder for CodeGen |
| 61 | + //currentSwitchCase.addCase(match, handler) |
| 62 | + //let cxt = switchManager.get |
| 63 | + |
| 64 | + //this should try to get before creating, so unless that changes, |
| 65 | + // this code should suffice as uber simple as it is... |
| 66 | + let cxt = switchcase.createSwitch(name); |
| 67 | + if (cxt) { |
| 68 | + cxt.addCase(match, handler); |
| 69 | + } |
| 70 | + // else { |
| 71 | + // cxt = switchcase.getSwitch(name); |
| 72 | + // } |
| 73 | + |
| 74 | + // cxt.addCase(match, handler); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Case Block Value |
| 79 | + * Outside of debugging, testing, or rare niche scenarios: this may not be useful |
| 80 | + */ |
| 81 | + //% block="[Advanced/Test/Debug] switch $name matches case $match?" |
| 82 | + //% blockId=switchcase_case_block_value |
| 83 | + //% group="Control" |
| 84 | + //% weight=80 |
| 85 | + //% draggableParameters |
| 86 | + export function caseBlockValue(name: string, match: any): boolean { |
| 87 | + //return match === switchValue || match == switchValue; |
| 88 | + let cxt = switchcase.createSwitch(name); |
| 89 | + if (cxt && cxt.IsValueSet) |
| 90 | + return cxt.matches(match); |
| 91 | + |
| 92 | + return false; |
| 93 | + |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Default-Case Block Container |
| 98 | + */ |
| 99 | + //% block="default case" |
| 100 | + //% blockId=switchcase_default_case_block |
| 101 | + //% group="Control" |
| 102 | + //% weight=70 |
| 103 | + //% draggableStatement=true |
| 104 | + export function defaultCaseBlock(name: string, handler: () => void): void { |
| 105 | + |
| 106 | + let cxt = switchcase.createSwitch(name); |
| 107 | + |
| 108 | + if (cxt) |
| 109 | + cxt.addDefault(handler); |
| 110 | + } |
| 111 | + |
| 112 | +} |
0 commit comments