{"id":13745203,"url":"https://github.com/cassiozen/State-Machine","last_synced_at":"2025-05-09T04:34:39.508Z","repository":{"id":753872,"uuid":"408212","full_name":"cassiozen/State-Machine","owner":"cassiozen","description":"Javascript Hierarchical Finite State Machine","archived":false,"fork":false,"pushed_at":"2016-05-31T16:54:55.000Z","size":50,"stargazers_count":158,"open_issues_count":1,"forks_count":33,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-05-06T16:09:08.495Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cassiozen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-12-08T17:15:09.000Z","updated_at":"2025-02-18T13:20:06.000Z","dependencies_parsed_at":"2022-07-05T13:30:57.349Z","dependency_job_id":null,"html_url":"https://github.com/cassiozen/State-Machine","commit_stats":null,"previous_names":["cassiozen/as3-state-machine"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassiozen%2FState-Machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassiozen%2FState-Machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassiozen%2FState-Machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassiozen%2FState-Machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cassiozen","download_url":"https://codeload.github.com/cassiozen/State-Machine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253192803,"owners_count":21868991,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T05:01:24.800Z","updated_at":"2025-05-09T04:34:39.273Z","avatar_url":"https://github.com/cassiozen.png","language":"JavaScript","readme":"Hierarchical State Machine\n==========================\n\n### About\nThis module allows you to create both single-level and hierarchical finite state machines.\nState Machines are composed of states, and each state has (optional) callbacks for entering and exiting state. It's also possible to restrict the transition from states using the *from* property.\n\n### Usage\nAvailable states can be set with addState and initial state can be set using initialState setter.\n\nThe following example creates a state machine for a player model with 3 states (Playing, paused and stopped)\n\n```javascript\n var playerSM = new StateMachine();\n\n playerSM.addState(\"playing\",{ enter: this.onPlayingEnter, exit: this.onPlayingExit, from:[\"paused\",\"stopped\"] });\n playerSM.addState(\"paused\",{ enter: this.onPausedEnter, from:\"playing\"});\n playerSM.addState(\"stopped\",{ enter: this.onStoppedEnter, from:\"*\"});\n\n playerSM.on('transition_denied', this.handleTransitionDenied);\n playerSM.on('transition_complete', this.handleTransitionComplete);\n\n playerSM.initialState = \"stopped\";\n```\n\nIt's also possible to create hierarchical state machines using the argument \"parent\" in the addState method. This example shows the creation of a hierarchical state machine for the monster of a game (Its a simplified version of the state machine used to control the AI in the original Quake game)\n\n```javascript\n var monsterSM = new StateMachine();\n monsterSM.addState(\"idle\",{enter:this.onIdle, from:[\"smash\", \"punch\", \"missle attack\"]});\n monsterSM.addState(\"attack\",{enter:this.onAttack, from:\"idle\"});\n monsterSM.addState(\"melee attack\",{parent:\"attack\", enter:this.onMeleeAttack, from:\"attack\"});\n monsterSM.addState(\"smash\",{parent:\"melee attack\", enter:this.onSmash});\n monsterSM.addState(\"punch\",{parent:\"melee attack\", enter:this.onPunch});\n monsterSM.addState(\"missle attack\",{parent:\"attack\", enter:this.onMissle});\n monsterSM.addState(\"die\",{enter:this.onDead, from:[\"smash\", \"punch\", \"missle attack\"]});\n\n monsterSM.initialState = \"idle\";\n```\n\n### Install\n* [npm](http://npmjs.org/): `npm install --save hierarchical-fsm`\n* [Download](https://raw.githubusercontent.com/cassiozen/State-Machine/master/lib/StateMachine.js)\n\n### Ports\n* [ActionScript 3](https://github.com/cassiozen/State-Machine/tree/as3)\n* [Dart](https://github.com/JesterXL/Dart-JXL-State-Machine)\n* [Lua (Corona)](https://github.com/JesusEspejo/Lua-Corona-SDK-State-Machine)\n\n### License\n\nCopyright (c) 2009-16 Cássio M. Antonio\n\nReleased under the Open Source MIT license, which gives you the possibility to use it and modify it in every circumstance.\n","funding_links":[],"categories":["Unsorted"],"sub_categories":["Other API"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcassiozen%2FState-Machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcassiozen%2FState-Machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcassiozen%2FState-Machine/lists"}