{"id":15839367,"url":"https://github.com/phasereditor2d/phasereditor2d-scripts-core","last_synced_at":"2025-08-12T14:32:57.867Z","repository":{"id":207860921,"uuid":"720279485","full_name":"PhaserEditor2D/phasereditor2d-scripts-core","owner":"PhaserEditor2D","description":"Core script nodes for Phaser Editor 2D.","archived":false,"fork":false,"pushed_at":"2024-01-11T10:42:33.000Z","size":104,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-05T10:35:31.862Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/PhaserEditor2D.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-18T02:05:26.000Z","updated_at":"2024-09-02T18:38:02.000Z","dependencies_parsed_at":"2024-10-24T07:45:02.683Z","dependency_job_id":"4a264515-9379-4ef8-811a-25c49ca390c3","html_url":"https://github.com/PhaserEditor2D/phasereditor2d-scripts-core","commit_stats":{"total_commits":85,"total_committers":1,"mean_commits":85.0,"dds":0.0,"last_synced_commit":"e92a037e7e21f4f62e1bb7db51cf75b58a69fef5"},"previous_names":["phasereditor2d/phasereditor2d-scripts-core"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhaserEditor2D%2Fphasereditor2d-scripts-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhaserEditor2D%2Fphasereditor2d-scripts-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhaserEditor2D%2Fphasereditor2d-scripts-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhaserEditor2D%2Fphasereditor2d-scripts-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PhaserEditor2D","download_url":"https://codeload.github.com/PhaserEditor2D/phasereditor2d-scripts-core/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229691401,"owners_count":18108405,"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-10-05T16:04:15.774Z","updated_at":"2024-12-14T10:21:49.212Z","avatar_url":"https://github.com/PhaserEditor2D.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Basic Phaser Editor 2D script nodes\n\nThis project contains the main scripts to use with a Phaser Editor 2D project.\n\nIt includes the basic script nodes and user components, especially, the `ScriptNode` and `UserComponent` classes.\n\nThese script nodes are very basic and may fit on any Phaser Editor 2D project.\n\nThe scripts are coded in TypeScript with ES modules.\n\n## Installing (NPM)\n\nInstall this package in your game:\n\n```\nnpm install @phasereditor2d/scripts-core\n```\n\nAlso, you should add this package to the `phasereditor2d.config.json` file in your project, in the `scripts` section:\n\n```json\n{\n    \"scripts\": [\"@phasereditor2d/scripts-code\"]\n}\n```\n\n## Installing (vanilla JS)\n\n* Get the files in the [browser](./browser/) folder and copy them into your JavaScript project. It includes Phaser Editor 2D files, JavaScript files, and TypeScript type definitions.\n* Add a `script` tag to the `index.html` file to load the `lib/phasereditor2d_scripts_core.js` file.\n\n## Summary\n\nThere are three groups of scripts: **Base**, **Event**, and **Action**.\n\n## User components\n\nThis package provides a couple of general-purpose user components. Including the `UserComponent` class, which is the base class for all user components.\n\n* `UserComponent` - it is a class you can use as the base class for your user components.\n* **Action Target** - it provides information to script nodes about what object is the target of an action.\n* **Assignment Operator** - to specify an operator (`=`, `+=`, or `=`) in the context of an assignment script-like action.\n\n### Base scripts\n\nContains basic/abstract functionality. Often, you will create prefab variants of them (extend them).\n\n* **ScriptNode** - the base class for all the scripts.\n* **Sprite Base Script** - base prefab for script nodes accessing sprite objects.\n* **Root Base Script** - a script node that registers itself into the game object and can be used as a container of other scripts.\n\n### Event scripts\n\nThese scripts listen to certain events. When the event is emitted, then executes the children, which are actions.\n\n* **On General Event** - registers to the given `eventEmitter` and listens to the given `eventName` event.\n* **On Awake Event** - listens to the `scene-awake` event of the scene.\n* **On Pointer Down Event** - listens to the `pointerdown` event of the game object.\n\n### Action scripts\n\nActions are scripts that are executed manually or by other nodes, like triggers or other actions.\n\n* **Callback Action** - executes the given `callback` expression.\n* **Start Scene Action** - starts the given `sceneKey` scene.\n* **Exec Action** - executes the given `targetAction`.\n* **Emit Event Action** - the given `eventEmitter` emits the given `eventName`.\n* **Alert Action** - shows the browser's alert dialog, with the given `message`.\n* **Console Log Action** - logs the given `message` to the browser's console.\n* **Destroy Action** - destroys the game object.\n* **Add To Parent Action** - adds the game object to the given parent.\n* **Exec Random Action** - executes a random child node.\n* **Exec Children Action** - executes all children nodes.\n* **Play Sprite Animation** - plays the given sprite animation.\n* **Set Angle Action** - sets the angle to the game object.\n* **Set Scale X/Y Action** - set the X or Y of the game object's scale.\n* **Set X/Y Action** - set the scale X/Y of the game object's position.\n* **Set Flip Action** - flips the game object vertically or horizontally.\n* **Spawn Object Action** - spawns an object in the world.\n\n## Target Action component\n\nThis user component is a hint to the action-like script nodes about what object is the target of the action. The possible targets are the game object of the script node (the default), or any of the arguments of the `execute(...)` method of the action.\n\nThe **Target* property of the component allows these values: `GAME_OBJECT` (default), `ARG_1`, `ARG_2`, `ARG_3`, etc...\n\nIf you are implementing a custom action script, you may want to look into the **Target Action** component to determine the object to receive the action. This is an example:\n\n```js\nclass MyAction {\n\n    execute(...args: any[]) {\n\n        const obj = TargetActionComp.getActionTarget(this, args);\n\n        this.performMyCustomAction(obj);\n    }\n}\n```\n\n## Assignment Operator component\n\nThere are script actions about to set a value to the game object. Like the case of the **Set X Action**.\nWith the **Assignment Operator**, you can specify the operator to use in the assignment: `=`, `+=`, or `*=`.\n\n## ScriptNode\n\nThe base of all the scripts. Probably it is already available in your project (if you generated it with Phaser Editor 2D).\n\nThis class provides methods for managing the node's children, and implementing the scene events: `awake`, `start`, and `update`.\n\n## Sprite Base Script\n\nA base script for all the scripts accessing sprite objects. It just overrides the `gameObject` property and sets its type to `Phaser.GameObjects.Sprite`. This helps IDE auto-completion and type-checking.\n\n## Root Base Script\n\nA base script that you can use to register the script node into the game object. In this way you can access the scripts associated to a game object.\n\nWhen you create a **RootScript**, it registers itself to the game object in this way:\n\n```\ngameObject[\"RootScript__scripts\"] = this;\n```\n\nYou can use the `key` parameter to register the root script node using another attribute. If the `key` parameter is `\"anotherScripts\"`, then it registers the root node like this:\n\n```\ngameObject[\"RootScript__anotherScripts\"] = this;\n```\n\nThe **RootScript** class contains utility methods for accessing the root script of a game object.\n\nThe static `getRoot()` method can be used for getting the root script:\n\n```\nconst script = RootScript.getRoot(someGameObject);\nconst otherScript = RootScript.getRoot(someGameObject, \"anotherScripts\");\n```\n\nThe static `hasRoot()` method tells if the game object is a root script:\n\n```\nif (RootScript.hasRoot(gameObject, \"myScripts\")) {\n    ....\n}\n```\n\nThe static `getChildren()` method returns the children of the root script:\n\n```\nconst children = RootScript.getChildren(gameObject, \"myScripts\");\n```\n\nYou can create variants of the **RootScript** and use different keys.\n\n## On General Event\n\nAn event script node. It registers to the given `eventEmitter` and listens to the given `eventName``. When the event is fired, it executes the children's action nodes. \n\nYou can create handy prefab variants for different events, like the **On Pointer Down Event** prefab.\n\nYou can select an `eventEmitter` from the following list:\n\n* `game.events`\n* `scene.events`\n* `scene.loader`\n* `scene.input`\n* `scene.input.keyboard`\n* `scene.anims`\n* `gameObject` (by default)\n\n## OnPointerDownScript\n\nAn event script. It is a prefab variant of the **On General Event** node. It listens to the `pointerdown` event of the game object and executes the children's action nodes.\n\nIf the game object's input is not set when the scene \"awakes\", then this script calls the `gameObject.setInteractive()` method.\n\n## Callback Action\n\nAn action script. It executes the given `callback` expression. You can use this script for executing custom methods from your prefabs or scenes.\n\n## Start Scene Action\n\nAn action script. It starts the given `sceneKey` scene.\n\n## Exec Action\n\nAn action script. It executes the given `targetAction`. You can use this script for executing an action node from the script tree.\n\nFor example, let's say you have a **JumpAction** for jumping a character. But you want to call this action when different events are fired:\n\n- When you click a jump button.\n- When you press the `SPACE` key.\n- When you press the `UP` button of an external gamepad.\n\nSo, you can use different **ExecActionScript** nodes in different contexts, but referencing the same **JumpAction** node.\n\n## Emit Event Action\n\nAn action script. It calls the emit method of the given `eventEmitter` with the given `eventName`. As an argument of the event, it uses the argument received in the `execute()` method.\n\nLike in the **OnEventScript**, you can select an `eventEmitter` from a list:\n\n* `game.events`\n* `scene.events`\n* `scene.loader`\n* `scene.input`\n* `scene.input.keyboard`\n* `scene.anims`\n* `gameObject` (by default)\n\n## Alert Action\n\nAn action script that shows the given `message` in the browser's Alert dialog.\n\n## Console Log Action\n\nAn action script that logs the given `message` in the browser's console.\n\n## Destroy Action\n\nAn action script that destroys the game object.\n\n## Add To Parent Action\n\nThis action adds the game object to the given **Parent Container**.\n\nThis action allows the **Action Target Config** component.\n\n## Exec Random Action\n\nThis action picks a random child and executes it.\n\n## Exec Children Action\n\nThis action executes all children nodes.\n\n## Play Sprite Animation\n\nThe action plays the given **Animation Key** in the game object. You can set the **Ignore If Playing** parameter.\n\nThis action allows the **Action Target Config** component.\n\n## Set Angle Action\n\nAn action to set the given **Angle** to the game object. \n\nThis action allows the **Action Target Config** component.\n\n## Set Scale X/Y Action\n\nAn action to set the given **X** or **Y** to the game object. \n\nThis action allows the **Action Target Config** component.\n\n## Set Flip Action\n\nAn action to set flip the game object. It looks into the **Flip Vertical** and **Flip Horizontal** properties. \n\nThis action allows the **Action Target Config** component.\n\n## Spawn Object Action\n\nThis action creates an instance of the given **Object Prefab** and adds it to the world. If the **Spawn In Parent Position** parameter is checked, then it sets the position of the new object to the same position as the script's game object. \n\nFinally, it executes the children nodes and passes the new object as the first argument.\n\nThis action allows the **Action Target Config** component.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphasereditor2d%2Fphasereditor2d-scripts-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphasereditor2d%2Fphasereditor2d-scripts-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphasereditor2d%2Fphasereditor2d-scripts-core/lists"}