Skip to content

Commit

Permalink
basic state machines (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragazo authored Jun 26, 2024
1 parent 225f9ec commit d47f76d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions extensions/StateMachine/extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "create and visualize state machines",
"useDev": false
}
47 changes: 47 additions & 0 deletions extensions/StateMachine/index.js
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);
})();

0 comments on commit d47f76d

Please sign in to comment.