Skip to content

Commit 036434f

Browse files
authored
feat: add mkdocs for documentation to deploy to gh-pages (#171)
1 parent 73a7d41 commit 036434f

File tree

7 files changed

+364
-264
lines changed

7 files changed

+364
-264
lines changed

.github/workflows/gh_pages.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 📑 GitHub Pages
2+
on:
3+
push:
4+
branches:
5+
- "master"
6+
- "3.4"
7+
- "4.1"
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-python@v4
18+
with:
19+
python-version: 3.x
20+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
21+
- uses: actions/cache@v3
22+
with:
23+
key: mkdocs-material-${{ env.cache_id }}
24+
path: .cache
25+
restore-keys: |
26+
mkdocs-material-
27+
- run: pip install mkdocs-material
28+
- run: mkdocs gh-deploy --force

README.md

Lines changed: 21 additions & 264 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# JavaScript language binding for Godot game engine
1+
# GodotJS - JavaScript language binding for Godot game engine
22

33
This module implements JavaScript/TypeScript language support for the Godot game engine using [QuickJS](https://bellard.org/quickjs/) as the JavaScript engine.
44

@@ -13,275 +13,32 @@ This module implements JavaScript/TypeScript language support for the Godot game
1313
- Full code completion support for all Godot APIs including signals and enumerations
1414
- Debug in Visual Studio Code with the [plugin](https://marketplace.visualstudio.com/items?itemName=geequlim.godot-javascript-debug) - currently not available for 4.x
1515

16-
## Installation
16+
### Getting started
1717

18-
No installation or setup necessary. The binaries for download are the complete, usable Godot editor and engine with JavaScript/TypeScript language support.
19-
20-
## Download
21-
22-
You can try the pre-compiled binaries from the [release page](https://github.com/GodotExplorer/ECMAScript/releases) or get the binaries with the latest commits from the [GitHub build action result](https://github.com/GodotExplorer/ECMAScript/actions).
23-
24-
## Compilation
25-
26-
1. Clone the source code of [godot](https://github.com/godotengine/godot)
27-
2. Clone this module and put it into `godot/modules/` and make sure the folder name of this module is `javascript`
28-
3. [Recompile the godot engine](https://docs.godotengine.org/en/4.1/development/compiling/index.html) - Use ``scons`` with those additional options ``warnings=extra werror=yes module_text_server_fb_enabled=yes`` to show all potential errors
29-
30-
![Build Godot with ECMAScript](https://github.com/GodotExplorer/ECMAScript/workflows/Build%20Godot%20with%20ECMAScript/badge.svg)
31-
32-
## Usage
33-
34-
### How to export script class to Godot
35-
36-
1. Define your JavaScript class and inherit from a Godot class, then export it as the **default** entry:
37-
38-
```js
39-
// The default export entry is treated as an exported class to Godot
40-
export default class MySprite extends godot.Sprite {
41-
// this is _init() in GDScript
42-
constructor() {
43-
super();
44-
}
45-
46-
_ready() {}
47-
48-
_process(delta) {}
49-
}
50-
```
51-
52-
2. Save the script with extension `.mjs`
53-
3. Attach the script file to the node or resource object like you do with GDScript
54-
55-
### How to export signals
56-
57-
```js
58-
export default class MySprite extends godot.Sprite {}
59-
// register game_over signal to MySprite class
60-
godot.register_signal(MySprite, "game_over");
61-
```
62-
63-
### How to export properties
64-
65-
```js
66-
export default class MySprite extends godot.Sprite {
67-
_process(delta) {
68-
// Yes! We can use operators in JavaScript like GDScript
69-
this.position += this.direction * delta;
70-
}
71-
}
72-
// export 'direction' properties to MySprite Godot inspector
73-
godot.register_property(MySprite, "direction", new godot.Vector2(1, 0));
74-
```
75-
76-
There are 2 ways of using the `godot.register_property`. The third parameter can either be a default value for the property you're trying to export or an object giving a more detailed description of how the editor should show it.
77-
78-
```js
79-
function register_property(target: GodotClass | godot.Object, name: string, value: any);
80-
function register_property(target: GodotClass | godot.Object, name: string, info: PropertyInfo);
81-
```
82-
83-
So calling the `register_property` like this:
84-
85-
```js
86-
godot.register_property(MyClass, "number_value", 3.14);
87-
```
88-
89-
Is the simplified version of:
90-
91-
```js
92-
godot.register_property(MyClass, "number_value", {
93-
type: godot.TYPE_REAL,
94-
hint: godot.PropertyHint.PROPERTY_HINT_NONE,
95-
hint_string: "",
96-
default: 3.14,
97-
});
98-
```
99-
100-
For more detail on how to use it, [click here](https://github.com/Geequlim/ECMAScript/issues/24#issuecomment-655584829).
101-
102-
### About the API
18+
Read the [getting-started](https://geequlim.github.io/ecmascript/getting-started).
10319

104-
All of Godot's APIs are defined within the `godot` namespace.
20+
## Getting the engine
10521

106-
No API names have been renamed or changed, so you shouldn't need to change your habits.
107-
108-
| GDScript | JavaScript |
109-
| ---------------------- | ---------------------------- |
110-
| null | null |
111-
| int | number |
112-
| float | number |
113-
| String | string |
114-
| Array | Array |
115-
| Dictionary | Object |
116-
| NodePath | string |
117-
| Object | godot.Object |
118-
| Resource | godot.Resource |
119-
| Vector2 | godot.Vector2 |
120-
| Color | godot.Color |
121-
| sin(v) | godot.sin(v) |
122-
| print(v) | godot.print(v) |
123-
| PI | godot.PI |
124-
| Color.black | godot.Color.black |
125-
| Control.CursorShape | godot.Control.CursorShape |
126-
| Label.Align.ALIGN_LEFT | godot.Label.Align.ALIGN_LEFT |
127-
128-
#### API specification:
129-
130-
- Keys of Dictionary are converted to String in JavaScript
131-
- Signals are defined as constants to their classes
132-
```
133-
godot.Control.resized === 'resized' // true
134-
```
135-
- Additional functions
136-
- `godot.register_signal(cls, signal_name)` to register signals
137-
- `godot.register_property(cls, name, default_value)` to define and export properties
138-
- `godot.register_class(cls, name)` to register named class manually
139-
- `godot.set_script_tooled(cls, tooled)` to set `tooled` of the class
140-
- `godot.set_script_icon(cls, path)` to set icon of the class
141-
- `godot.get_type(val)` Returns the internal type of the given `Variant` object, using the `godot.TYPE_*`
142-
- `godot.yield(target, signal)` Returns a Promise which will be resolved when the signal emitted
143-
- `requestAnimationFrame(callback)` registers a callback function to be called every frame, returns a request ID.
144-
- `cancelAnimationFrame(request_id)` to cancel a previously scheduled frame request
145-
- `require(module_id)` to load a CommonJS module or load a resource file
146-
- `$` is the alias of `Node.get_node`
147-
- Using signals in the ECMAScript way
148-
- Allow passing functions for `godot.Object.connect`, `godot.Object.disconnect`, and `godot.Object.is_connected`
149-
```js
150-
this.panel.connect(godot.Control.resized, (size) => {
151-
console.log("The size of the panel changed to:", size);
152-
});
153-
```
154-
- Using `await` to wait for signals
155-
```js
156-
await godot.yield(
157-
this.get_tree().create_timer(1),
158-
godot.SceneTreeTimer.timeout
159-
);
160-
console.log("After one second to show");
161-
```
162-
- Preload resources with ECMAScript import statement
163-
```js
164-
import ICON from "res://icon.png";
165-
```
166-
- Multi-threading with minimal [Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Worker) (**This is an experimental feature**)
167-
168-
- Start a new thread with Worker
169-
```js
170-
const worker = new Worker("worker.js"); // Run worker.js in a new thread context
171-
worker.postMessage({ type: "load_dlc", value: "dlc01.pck" });
172-
worker.onmessage = function (msg) {
173-
console.log("[MainThread] received message from worker thread:", msg);
174-
};
175-
```
176-
- Transfer value in different thread context with `godot.abandon_value` and `godot.adopt_value`
177-
178-
```js
179-
// In worker thread
180-
let id = godot.abandon_value(object);
181-
postMessage({ type: "return_value", id: id });
182-
183-
// In the host thread
184-
worker.onmessage = function (msg) {
185-
if (typeof msg === "object" && msg.type === "return_value") {
186-
let value_from_worker = godot.adopt_value(msg.id);
187-
}
188-
};
189-
```
190-
191-
### TypeScript support
192-
193-
- Run the menu command `Project > Tools > JavaScript > Generate TypeScript Project` from the Godot editor to generate a TypeScript project
194-
- Run `tsc -w -p .` under your project folder in the terminal to compile scripts
195-
196-
#### Code completion
197-
198-
- Code completion in TS will automatically work once the TypeScript project is generated by the above steps.
199-
- Code completion in VSCode is achieved by the property `"types": "./godot.d.ts"` in the generated package.json file of the TypeScript project. The `godot.d.ts` file can be generated alone via the `Project > Tools > ECMAScript > Generate TypeScript Declaration File` editor menu option and added to a `package.json` file manually to achieve this without a full TypeScript project.
200-
201-
#### Example TypeScript Usage
202-
203-
Compile your `ts` script to a `.mjs` file then we can attach it to a node in godot editor.
204-
205-
Most of the `register` functions are available as various decorators as seen below.
206-
207-
```ts
208-
import { signal, property, tool, onready, node } from "./decorators";
209-
210-
@tool // make the script runnable in godot editor
211-
export default class InputLine extends godot.HBoxContainer {
212-
// define a signal
213-
@signal
214-
static readonly OnTextChanged: string;
215-
216-
// expose a node property
217-
@node
218-
icon: godot.Sprite;
219-
220-
// register offset property with the godot inspector with default value of Vector2(0, 0)
221-
@property({ default: godot.Vector2.ZERO })
222-
offset: godot.Vector2;
223-
224-
// register properties for godot editor inspector
225-
@property({ type: godot.VariantType.TYPE_STRING })
226-
get title() {
227-
return this._title;
228-
}
229-
set title(v: string) {
230-
this._title = v;
231-
if (this._label) {
232-
this._label.text = v;
233-
}
234-
}
235-
private _title: string;
236-
237-
@property({ default: "Input text here" })
238-
get hint() {
239-
return this._hint;
240-
}
241-
set hint(v: string) {
242-
this._hint = v;
243-
if (this.edit) {
244-
this.edit.hint_tooltip = v;
245-
this.edit.placeholder_text = v;
246-
}
247-
}
248-
private _hint: string;
249-
250-
get label(): godot.Label {
251-
return this._label;
252-
}
253-
protected _label: godot.Label;
254-
255-
// call get_node('LineEdit') and assign the returned value to 'this.edit' automatically when the node is ready
256-
@onready("LineEdit")
257-
edit: godot.LineEdit;
258-
259-
get text(): string {
260-
return this.edit?.text;
261-
}
262-
263-
_ready() {
264-
// get first child with the type of godot.Label
265-
this._label = this.get_node(godot.Label);
22+
No installation or setup necessary. The binaries for download are the complete, usable Godot editor and engine with JavaScript/TypeScript language support.
26623

267-
// Apply the inspector filled values with property setters
268-
this.title = this.title;
269-
this.hint = this.hint;
24+
### Binary downloads
25+
Download the binaries from the [release page](https://github.com/GodotExplorer/ECMAScript/releases).
27026

271-
this.edit.connect(godot.LineEdit.text_changed, (text: string) => {
272-
this.emit_signal(InputLine.OnTextChanged, text);
273-
});
274-
}
275-
}
276-
```
27+
### Compiling from source
28+
- Clone the source code of [godot](https://github.com/godotengine/godot):
29+
- ``git clone [email protected]:godotengine/godot.git`` or
30+
- ``git clone https://github.com/godotengine/godot.git``
31+
- Clone this module and put it into `godot/modules/javascript`:
32+
- ``git clone [email protected]:Geequlim/ECMAScript.git godot/modules/javascript`` or
33+
- ``git clone https://github.com/Geequlim/ECMAScript.git godot/modules/javascript``
34+
- [Recompile the godot engine](https://docs.godotengine.org/en/4.1/development/compiling/index.html)
35+
- Use ``scons`` with those additional options ``warnings=extra werror=yes module_text_server_fb_enabled=yes`` to show all potential errors
27736

278-
## Demo
37+
## Documentation, Tutorials & Demos
27938

280-
You can try demos in the [ECMAScriptDemos](https://github.com/Geequlim/ECMAScriptDemos)
39+
Read this [documentation](https://geequlim.github.io/ecmascript/getting-started) or look at the tutorials or demos:
28140

282-
## Developer notes
28341

284-
- This package is not compatible with MSVC, you will get build errors in quickjs.
285-
- The script also build the `on_tag.yml` script which automates the github release publishing.
286-
\*\* The `on_tag.yml` functionality tries to sleep until all jobs with the same `sha` are completed. It should be fine to run whenever, but depending on how github actions culls long running jobs you might want to make sure that all/(most of) the builds look good before tagging.
287-
- They should definitely be fixed & enabled at some point, **so please submit a PR if you have any ideas of how to do that!**
42+
- [ECMAScriptDemos](https://github.com/Geequlim/ECMAScriptDemos) - Demos
43+
- [godot-ECMAScript-cookbook](https://github.com/why-try313/godot-ECMAScript-cookbook/wiki) - Tutorial
44+
- [godot-typescript-starter](https://github.com/citizenll/godot-typescript-starter) - Template

0 commit comments

Comments
 (0)