Skip to content

Commit

Permalink
Merge branch '0.15'
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed May 3, 2023
2 parents 1f5d455 + 06a88ad commit 47f325a
Show file tree
Hide file tree
Showing 29 changed files with 681 additions and 445 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
indent_size = 4

[*.hx]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
indent_size = 4
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,36 @@
</h3>
</div>

| Description | Status |
| ------| -------|
| Master Branch Build Status | [![Build Status](https://travis-ci.org/colyseus/colyseus-hx.svg?branch=master)](https://travis-ci.org/colyseus/colyseus-hx) |

## Running the demo project

First, download and install [Haxe](https://haxe.org/download/).

The [`example`](https://github.com/colyseus/colyseus-hx/blob/master/example/openfl) project can be compiled to `html5`, `neko`, `cpp`, `ios`, etc.
The [`example`](https://github.com/colyseus/colyseus-haxe/blob/master/example/openfl) project can be compiled to `html5`, `neko`, `cpp`, `ios`, etc.

It uses the `state_handler` room from the [colyseus-examples](https://github.com/colyseus/colyseus-examples) project, which you can find [here](https://github.com/colyseus/colyseus-examples/blob/master/rooms/02-state-handler.ts).

### Compiling the demo project to `html5`

```
git clone https://github.com/colyseus/colyseus-hx.git
cd colyseus-hx/example/openfl
git clone https://github.com/colyseus/colyseus-haxe.git
cd colyseus-haxe/example/openfl
haxelib install openfl
haxelib install lime
haxelib install colyseus-websocket
haxelib run lime test project.xml html5
```

## Development

Running the test-suite:

```
haxe hxml/test.js.hxml
```

## Dependencies

[colyseus-hx](https://github.com/colyseus/colyseus-hx) depends on [`colyseus-websocket`](https://github.com/colyseus/colyseus-websocket-hx)
[colyseus-haxe](https://github.com/colyseus/colyseus-haxe) depends on [`colyseus-websocket`](https://github.com/colyseus/colyseus-websocket-hx)

## License

Expand Down
1 change: 1 addition & 0 deletions build.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ io.colyseus.Room

-lib hxcpp
-lib colyseus-websocket
-lib tink_url

# this is for Mac OS X:
-D HXCPP_M64
Expand Down
34 changes: 18 additions & 16 deletions example/openfl/Source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,42 @@ class Main extends Sprite {
return;
}

trace("joinOrCreate, roomId: " + room.roomId);

this.room = room;
this.room.state.players.onAdd = function(player, key) {

this.room.state.players.onAdd((player, key) -> {
trace("PLAYER ADDED AT: ", key);

var cat = Assets.getMovieClip("library:NyanCatAnimation");
this.cats[key] = cat;
this.cats.set(key, cat);
cat.x = player.x;
cat.y = player.y;
addChild(cat);
}

this.room.state.players.onChange = function(player, key) {
trace("PLAYER CHANGED AT: ", key);
this.cats[key].x = player.x;
this.cats[key].y = player.y;
}
player.onChange((changes) -> {
this.cats.get(key).x = player.x;
this.cats.get(key).y = player.y;
});
});

this.room.state.players.onRemove = function(player, key) {
this.room.state.players.onRemove((player, key) -> {
trace("PLAYER REMOVED AT: ", key);
removeChild(this.cats[key]);
}
removeChild(this.cats.get(key));
});

this.room.onStateChange += function(state) {
trace("STATE CHANGE: " + Std.string(state));
this.room.onStateChange += (state) -> {
};

this.room.onMessage(0, function(message) {
this.room.onMessage(0, (message) -> {
trace("onMessage: 0 => " + message);
});

this.room.onMessage("type", function(message) {
this.room.onMessage("type", (message) -> {
trace("onMessage: 'type' => " + message);
});

this.room.onError += function(code: Int, message: String) {
this.room.onError += (code: Int, message: String) -> {
trace("ROOM ERROR: " + code + " => " + message);
};

Expand Down
2 changes: 2 additions & 0 deletions example/openfl/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

<haxelib name="openfl" />
<haxelib name="colyseus-websocket" />
<haxelib name="tink_url" />
<haxelib name="tink_await" />

<library path="Assets/library.swf" preload="true" />

Expand Down
33 changes: 0 additions & 33 deletions example/server/index.ts

This file was deleted.

52 changes: 35 additions & 17 deletions example/server/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
{
"private": true,
"name": "my-app",
"version": "1.0.0",
"description": "Usage Examples of Colyseus Game Server",
"main": "index.js",
"description": "npm init template for bootstrapping an empty Colyseus project",
"main": "lib/index.js",
"scripts": {
"start": "ts-node index.ts",
"schema-codegen": "schema-codegen rooms/TestRoom.ts --haxe --output ../heaps/src/"
},
"engines": {
"node": ">=14.0.0"
"start": "ts-node-dev --respawn --transpile-only src/index.ts",
"tsx": "tsx watch src/index.ts",
"loadtest": "ts-node loadtest/example.ts --room my_room --numClients 99",
"build": "npm run clean && tsc && node node_modules/copyfiles/copyfiles package.json ./lib && node node_modules/copyfiles/copyfiles arena.env ./lib",
"clean": "node node_modules/rimraf/bin lib",
"test": "mocha --require ts-node/register test/**_test.ts --exit --timeout 15000"
},
"author": "",
"license": "ISC",
"dependencies": {
"@colyseus/monitor": "^0.14.3",
"colyseus": "^0.14.0",
"cors": "^2.8.5",
"express": "^4.14.0",
"serve-index": "^1.8.0",
"superagent": "^3.8.1"
"license": "UNLICENSED",
"bugs": {
"url": "https://github.com/colyseus/create-colyseus/issues"
},
"homepage": "https://github.com/colyseus/create-colyseus#readme",
"devDependencies": {
"ts-node": "^8.10.2",
"typescript": "^3.5.3"
"@colyseus/loadtest": "^0.15.0-preview.10",
"@colyseus/testing": "^0.15.0-preview.1",
"@types/cors": "^2.8.6",
"@types/express": "^4.17.1",
"@types/mocha": "^8.2.3",
"copyfiles": "^2.4.1",
"mocha": "^9.0.2",
"rimraf": "^2.7.1",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"tsx": "^3.12.7",
"typescript": "^5.0.4"
},
"dependencies": {
"@colyseus/core": "^0.15.0-preview.8",
"@colyseus/monitor": "^0.15.0-preview.3",
"@colyseus/redis-driver": "^0.15.0-preview.0",
"@colyseus/redis-presence": "^0.15.0-preview.2",
"@colyseus/tools": "^0.15.0-preview.10",
"colyseus": "^0.15.0-preview.4",
"cors": "^2.8.5",
"express": "^4.16.4"
}
}
55 changes: 55 additions & 0 deletions example/server/src/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import config from "@colyseus/tools";

import { WebSocketTransport } from "@colyseus/ws-transport";
import { monitor } from "@colyseus/monitor";

import { RedisDriver } from "@colyseus/redis-driver";
import { RedisPresence } from "@colyseus/redis-presence";

/**
* Import your Room files
*/
import { MyRoom } from "./rooms/MyRoom";

export default config({
getId: () => "Your Colyseus App",

options: {
devMode: true,
driver: new RedisDriver(),
presence: new RedisPresence(),
},

initializeTransport: (options) => new WebSocketTransport(options),

initializeGameServer: (gameServer) => {
/**
* Define your room handlers:
*/
gameServer.define('my_room', MyRoom);

},

initializeExpress: (app) => {
/**
* Bind your custom express routes here:
*/
app.get("/", (req, res) => {
res.send(`Instance ID => ${process.env.NODE_APP_INSTANCE ?? "NONE"}`);
});

/**
* Bind @colyseus/monitor
* It is recommended to protect this route with a password.
* Read more: https://docs.colyseus.io/tools/monitor/
*/
app.use("/colyseus", monitor());
},


beforeListen: () => {
/**
* Before before gameServer.listen() is called.
*/
}
});
15 changes: 15 additions & 0 deletions example/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* IMPORTANT:
* ---------
* Do not manually edit this file if you'd like to use Colyseus Arena
*
* If you're self-hosting (without Arena), you can manually instantiate a
* Colyseus Server as documented here: 👉 https://docs.colyseus.io/server/api/#constructor-options
*/
import { listen } from "@colyseus/tools";

// Import arena config
import app from "./app.config";

// Create and listen on 2567 (or PORT environment variable.)
listen(app);
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class State extends Schema {
@type(Container) container = new Container();
}

export class TestRoom extends Room {
export class MyRoom extends Room {

async onCreate(options) {
async onCreate(options: any) {
this.setState(new State());

let int: number = 0;
Expand Down
36 changes: 22 additions & 14 deletions example/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
{
"compilerOptions": {
"outDir": "lib",
"module": "commonjs",
"lib": ["es6"],
"target": "es2016",
"declaration": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"sourceMap": false,
"esModuleInterop": true
},
"include": [
"**/*.ts"
]
"compilerOptions": {
"outDir": "lib",
"target": "es6",
"module": "commonjs",
"strict": true,
"allowJs": true,
"strictNullChecks": false,
"esModuleInterop": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"useDefineForClassFields": false
},
// other settings...
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
},

"include": [
"src"
]
}
10 changes: 6 additions & 4 deletions haxelib.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "colyseus",
"url" : "https://github.com/colyseus/colyseus-hx/",
"url" : "https://github.com/colyseus/colyseus-haxe/",
"license": "MIT",
"tags": ["multiplayer", "networking", "websockets", "netcode"],
"description": "Multiplayer Game Client for Haxe",
"version": "0.14.10",
"version": "0.15.0",
"classPath": "src/",
"releasenote": "Aidan's fixes for Haxe 4.2",
"releasenote": "Compatible with new version 0.15 of Colyseus server",
"contributors": ["endel"],
"dependencies": {
"colyseus-websocket": "1.0.7"
"colyseus-websocket": "1.0.12",
"tink_url": "0.5.0",
"tink_await": "0.6.0"
}
}
1 change: 1 addition & 0 deletions hxml/test.defaults.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
-cp src
-cp tests
-lib colyseus-websocket
-lib tink_url
# use deprecated haxe.unit.TestCase
-lib hx3compat
Loading

0 comments on commit 47f325a

Please sign in to comment.