-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"description": "create and visualize state machines", | ||
"useDev": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(function () { | ||
class StateMachine extends Extension { | ||
constructor(ide) { | ||
super('StateMachine'); | ||
} | ||
|
||
getMenu() { | ||
return { | ||
'visualize': function () { | ||
alert('Coming Soon!'); | ||
}, | ||
}; | ||
} | ||
|
||
getCategories() { | ||
return [ | ||
new Extension.Category('StateMachine', new Color(150, 150, 150)), | ||
]; | ||
} | ||
|
||
getPalette() { | ||
const blocks = [ | ||
new Extension.Palette.Block('smTransition'), | ||
new Extension.Palette.Block('smInState'), | ||
]; | ||
return [ | ||
new Extension.PaletteCategory('StateMachine', blocks, SpriteMorph), | ||
new Extension.PaletteCategory('StateMachine', blocks, StageMorph), | ||
]; | ||
} | ||
|
||
getBlocks() { | ||
return [ | ||
new Extension.Block('smTransition', 'command', 'StateMachine', 'transition %var to %s', [], function (machine, state) { | ||
this.doSetVar(machine, state); | ||
this.doStop(); | ||
}).terminal().for(SpriteMorph, StageMorph), | ||
new Extension.Block('smInState', 'predicate', 'StateMachine', '%var in state %s ?', [], function (machine, state) { | ||
const variables = this.context.variables; | ||
return variables.getVar(machine) == state; | ||
}).for(SpriteMorph, StageMorph), | ||
]; | ||
} | ||
} | ||
|
||
NetsBloxExtensions.register(StateMachine); | ||
})(); |