Skip to content

Commit 53f3895

Browse files
committed
chore: add README and fix misc in pong-network
1 parent d5a77b7 commit 53f3895

File tree

7 files changed

+251
-59
lines changed

7 files changed

+251
-59
lines changed

.github/logo.png

20.1 KB
Loading

README.md

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,75 @@
1-
# Engine
1+
<div align="center">
2+
<br />
3+
<p>
4+
<a href="https://github.com/NanoForge-dev"><img src="https://github.com/NanoForge-dev/blob/main/.github/logo.png" width="546" alt="NanoForge" /></a>
5+
</p>
6+
<br />
7+
<p>
8+
<a href="https://github.com/NanoForge-dev/Engine/actions"><img src="https://github.com/NanoForge-dev/Engine/actions/workflows/tests.yml/badge.svg" alt="Tests status" /></a>
9+
<a href="https://github.com/NanoForge-dev/Engine/commits/main"><img src="https://img.shields.io/github/last-commit/NanoForge-dev/Engine.svg?logo=github&logoColor=ffffff" alt="Last commit." /></a>
10+
<a href="https://github.com/NanoForge-dev/Engine/graphs/contributors"><img src="https://img.shields.io/github/contributors/NanoForge-dev/Engine.svg?maxAge=3600&logo=github&logoColor=fff&color=00c7be" alt="contributors" /></a>
11+
</p>
12+
</div>
213

3-
This repository contains the full engine for NanoForge.
4-
It can be used by itself.
14+
## About
515

6-
The engine is made of multiple components:
16+
This repository contains multiple packages with separate [releases][github-releases]. Nanoforge is a powerful game engine for web browser.
717

8-
- [ecs-client](packages/ecs-client)
9-
- [ecs-server](packages/ecs-server)
10-
- [ecs-lib](packages/ecs-lib)
11-
- [input](packages/input)
12-
- [core](packages/core)
13-
- [common](packages/common)
14-
- [graphics-2d](packages/graphics-2d)
15-
- [asset-manager](packages/asset-manager)
16-
- [sound](packages/sound)
17-
- [music](packages/music)
18+
## Usage
1819

19-
This is the full nanoforge engine including all the default libraries.
20+
To use Nanoforge Engine, please refer to the [CLI documentation][cli-source] !
2021

21-
In order to manage this project we use (pnpm)[https://pnpm.io/]
22+
First, install the CLI :
2223

23-
## Installing dependencies
24-
25-
To install dependencies run:
26-
27-
```sh
28-
pnpm i
29-
```
30-
31-
## Building
32-
33-
To build the project run:
34-
35-
```sh
36-
pnpm build
24+
```bash
25+
npm install -g @nanoforge-dev/cli
3726
```
3827

39-
## Tests
28+
And then create a new project :
4029

41-
To run tests use:
42-
43-
```sh
44-
pnpm test
30+
```bash
31+
nf new
4532
```
4633

47-
## Setting up a test project
48-
49-
In order to setup a test project see (this)[https://github.com/NanoForge-dev/Engine/docs/Introduction.md]
34+
## Packages
35+
36+
- `@nanoforge-dev/common` ([source][common-source]) - Common interfaces and utilities used by Nanoforge Engine
37+
- `@nanoforge-dev/core` ([source][core-source]) - A core package that contains game main loop
38+
- `@nanoforge-dev/ecs-lib` ([source][ecs-lib-source]) - A powerful data structure for managing game entities (_do not use this in your projects_)
39+
- `@nanoforge-dev/ecs-client` ([source][ecs-client-source]) - A wrapper of `@nanoforge-dev/ecs-lib` for client-side usage
40+
- `@nanoforge-dev/ecs-server` ([source][ecs-server-source]) - A wrapper of `@nanoforge-dev/ecs-lib` for server-side usage
41+
- `@nanoforge-dev/config` ([source][config-source]) - A wrapper of `class-validator` and `class-transformer` to imports validation and transformation decorators
42+
- `@nanoforge-dev/graphics-2d` ([source][graphics-2d-source]) - A base 2D graphics library
43+
- `@nanoforge-dev/asset-manager` ([source][asset-manager-source]) - A manager for loading assets to uniform workwith between client and server
44+
- `@nanoforge-dev/network-client` ([source][network-client-source]) - A network lib with tcp and udp support for client-side usage
45+
- `@nanoforge-dev/network-server` ([source][network-server-source]) - A network lib with tcp and udp support for server-side usage
46+
- `@nanoforge-dev/input` ([source][input-source]) - An input manager for handling keyboard and mouse events
47+
- `@nanoforge-dev/music` ([source][music-source]) - A music player for your game
48+
- `@nanoforge-dev/sound` ([source][sound-source]) - A sound manager for your game
49+
50+
## Contributing
51+
52+
Please read through our [contribution guidelines][contributing] before starting a pull request. We welcome contributions of all kinds, not just code! If you're stuck for ideas, look for the [good first issue][good-first-issue] label on issues in the repository. If you have any questions about the project, feel free to ask them on [Discussions][discussions]. Before creating your own issue or pull request, always check to see if one already exists! Don't rush contributions, take your time and ensure you're doing it correctly.
53+
54+
## Help
55+
56+
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please ask on [Discussions][discussions].
57+
58+
[contributing]: https://github.com/NanoForge-dev/Engine/blob/main/.github/CONTRIBUTING.md
59+
[discussions]: https://github.com/NanoForge-dev/Engine/discussions
60+
[cli-source]: https://github.com/NanoForge-dev/CLI
61+
[github-releases]: https://github.com/NanoForge-dev/Engine/releases
62+
[asset-manager-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/asset-manager
63+
[common-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/common
64+
[config-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/config
65+
[core-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/core
66+
[ecs-client-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/ecs-client
67+
[ecs-lib-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/ecs-lib
68+
[ecs-server-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/ecs-server
69+
[graphics-2d-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/graphics-2d
70+
[input-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/input
71+
[music-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/music
72+
[network-client-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/network-client
73+
[network-server-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/network-server
74+
[sound-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/sound
75+
[good-first-issue]: https://github.com/NanoForge-dev/Engine/contribute

example/pong-network/client/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const main = async (options: IRunOptions) => {
7878

7979
return new Promise((resolve) => {
8080
const check = () => {
81-
if (network.udp?.isConnected()) {
81+
if (network.udp.isConnected()) {
8282
resolve();
8383
} else {
8484
setTimeout(check, 50);
@@ -89,6 +89,6 @@ export const main = async (options: IRunOptions) => {
8989
}
9090

9191
await waitForConnection();
92-
network.tcp?.sendData(new TextEncoder().encode(JSON.stringify({ type: "play" })));
92+
network.tcp.sendData(new TextEncoder().encode(JSON.stringify({ type: "play" })));
9393
app.run();
9494
};

example/pong-network/client/systems.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ export const controlPlayer = (registry: Registry, ctx: Context) => {
3131
const downPressed = input.isKeyPressed(Controller.down);
3232
if (upPressed == downPressed) {
3333
if (Controller.lastPressedUp || Controller.lastPressedDown) {
34-
network.tcp?.sendData(
34+
network.tcp.sendData(
3535
new TextEncoder().encode(JSON.stringify({ type: "input", key: "stop" })),
3636
);
3737
Controller.lastPressedDown = false;
3838
Controller.lastPressedUp = false;
3939
}
4040
} else if (upPressed && !Controller.lastPressedUp) {
41-
network.tcp?.sendData(new TextEncoder().encode(JSON.stringify({ type: "input", key: "up" })));
41+
network.tcp.sendData(new TextEncoder().encode(JSON.stringify({ type: "input", key: "up" })));
4242
Controller.lastPressedUp = true;
4343
} else if (downPressed && !Controller.lastPressedDown) {
4444
network.tcp?.sendData(
@@ -63,7 +63,7 @@ export function draw(registry: Registry) {
6363

6464
export function packetHandler(registry: Registry, ctx: Context) {
6565
const network = ctx.libs.getNetwork<NetworkClientLibrary>();
66-
const jsonPackets = network.tcp?.getReceivedPackets().map((packet) => {
66+
const jsonPackets = network.tcp.getReceivedPackets().map((packet) => {
6767
return JSON.parse(new TextDecoder().decode(packet));
6868
});
6969

example/pong-network/server/systems.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export function move(registry: Registry, ctx: Context) {
2020
}
2121

2222
function sendMoveAll(id: number, vel: Velocity, pos: Position, network: NetworkServerLibrary) {
23-
if (!network || !network.tcp) return;
2423
network.tcp.sendToEverybody(
2524
new TextEncoder().encode(
2625
JSON.stringify({
@@ -34,7 +33,6 @@ function sendMoveAll(id: number, vel: Velocity, pos: Position, network: NetworkS
3433
}
3534

3635
function connectNewClient(newCli: number, network: NetworkServerLibrary, zip: any) {
37-
if (!network || !network.tcp) return;
3836
network.tcp.sendToClient(
3937
newCli,
4038
new TextEncoder().encode(JSON.stringify({ type: "assignId", assigned: "ball", id: 0 })),
@@ -79,7 +77,7 @@ function handleClientInput(clientId: number, key: string, network: NetworkServer
7977
export function packetHandler(registry: Registry, ctx: Context) {
8078
const zip = registry.getZipper([Position, Velocity]);
8179
const network = ctx.libs.getNetwork<NetworkServerLibrary>();
82-
if (!network || !network.tcp) return;
80+
8381
if (network.tcp.getConnectedClients().indexOf(cli1) == -1) cli1 = -1;
8482
if (network.tcp.getConnectedClients().indexOf(cli2) == -1) cli2 = -1;
8583
const clientPackets = network.tcp.getReceivedPackets();

packages/network-client/README.md

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,96 @@
1-
# Engine Network Client
1+
<div align="center">
2+
<br />
3+
<p>
4+
<a href="https://github.com/NanoForge-dev"><img src="https://github.com/NanoForge-dev/blob/main/.github/logo.png" width="546" alt="NanoForge" /></a>
5+
</p>
6+
<br />
7+
<p>
8+
<a href="https://www.npmjs.com/package/@nanoforge-dev/network-client"><img src="https://img.shields.io/npm/v/@nanoforge-dev/network-client.svg?maxAge=3600" alt="npm version" /></a>
9+
<a href="https://www.npmjs.com/package/@nanoforge-dev/network-client"><img src="https://img.shields.io/npm/dt/@nanoforge-dev/network-client.svg?maxAge=3600" alt="npm downloads" /></a>
10+
<a href="https://github.com/NanoForge-dev/Engine/actions"><img src="https://github.com/NanoForge-dev/Engine/actions/workflows/tests.yml/badge.svg" alt="Tests status" /></a>
11+
<a href="https://github.com/NanoForge-dev/Engine/commits/main/packages/network-client"><img src="https://img.shields.io/github/last-commit/NanoForge-dev/Engine.svg?logo=github&logoColor=ffffff&path=packages%2Fnetwork-client" alt="Last commit." /></a>
12+
</p>
13+
</div>
14+
15+
## About
16+
17+
`@nanoforge-dev/network-client` is a network lib with tcp and udp support for client-side usage.
18+
19+
## Installation
20+
21+
**Node.js 24.11.0 or newer is required.**
22+
23+
```sh
24+
npm install @nanoforge-dev/network-client
25+
yarn add @nanoforge-dev/network-client
26+
pnpm add @nanoforge-dev/network-client
27+
bun add @nanoforge-dev/network-client
28+
```
29+
30+
## Example usage
31+
32+
Initilize the library in your main file.
33+
34+
```ts
35+
import { type IRunOptions } from "@nanoforge-dev/common";
36+
import { NanoforgeFactory } from "@nanoforge-dev/core";
37+
import { ECSClientLibrary } from "@nanoforge-dev/ecs-client";
38+
39+
export function main(options: IRunClientOptions) {
40+
const app = NanoforgeFactory.createClient();
41+
42+
const network = new NetworkClientLibrary();
43+
44+
app.useNetwork(network);
45+
46+
app.init(options);
47+
48+
app.run();
49+
}
50+
```
51+
52+
Use to receive packets
53+
54+
```ts
55+
export function myReceiveSystem(registry: Registry, ctx: Context) {
56+
const network = ctx.libs.getNetwork<NetworkClientLibrary>();
57+
58+
network.tcp.getReceivedPackets().forEach((packet) => {
59+
const data = JSON.parse(new TextDecoder().decode(packet));
60+
// Do something with the data
61+
});
62+
}
63+
```
64+
65+
Use to send packets
66+
67+
```ts
68+
export function mySendSystem(registry: Registry, ctx: Context) {
69+
const network = ctx.libs.getNetwork<NetworkClientLibrary>();
70+
71+
// Do something to get a data
72+
const packet = new TextEncoder().encode(JSON.stringify(data));
73+
network.tcp.sendPacket(packet);
74+
}
75+
```
76+
77+
## Links
78+
79+
- [GitHub][source]
80+
- [npm][npm]
81+
82+
## Contributing
83+
84+
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
85+
[documentation][documentation].
86+
See [the contribution guide][contributing] if you'd like to submit a PR.
87+
88+
## Help
89+
90+
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to ask questions in [discussions][discussions].
91+
92+
[documentation]: https://github.com/NanoForge-dev/Engine
93+
[discussions]: https://github.com/NanoForge-dev/Engine/discussions
94+
[source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/network-client
95+
[npm]: https://www.npmjs.com/package/@nanoforge-dev/network-client
96+
[contributing]: https://github.com/NanoForge-dev/Engine/blob/main/.github/CONTRIBUTING.md

packages/network-server/README.md

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,98 @@
1-
# Engine Network Manager
1+
<div align="center">
2+
<br />
3+
<p>
4+
<a href="https://github.com/NanoForge-dev"><img src="https://github.com/NanoForge-dev/blob/main/.github/logo.png" width="546" alt="NanoForge" /></a>
5+
</p>
6+
<br />
7+
<p>
8+
<a href="https://www.npmjs.com/package/@nanoforge-dev/network-server"><img src="https://img.shields.io/npm/v/@nanoforge-dev/network-server.svg?maxAge=3600" alt="npm version" /></a>
9+
<a href="https://www.npmjs.com/package/@nanoforge-dev/network-server"><img src="https://img.shields.io/npm/dt/@nanoforge-dev/network-server.svg?maxAge=3600" alt="npm downloads" /></a>
10+
<a href="https://github.com/NanoForge-dev/Engine/actions"><img src="https://github.com/NanoForge-dev/Engine/actions/workflows/tests.yml/badge.svg" alt="Tests status" /></a>
11+
<a href="https://github.com/NanoForge-dev/Engine/commits/main/packages/network-server"><img src="https://img.shields.io/github/last-commit/NanoForge-dev/Engine.svg?logo=github&logoColor=ffffff&path=packages%2Fnetwork-server" alt="Last commit." /></a>
12+
</p>
13+
</div>
214

3-
## Installing dependencies
15+
## About
416

5-
To install dependencies run:
17+
`@nanoforge-dev/network-server` is a network lib with tcp and udp support for server-side usage.
18+
19+
## Installation
20+
21+
**Node.js 24.11.0 or newer is required.**
622

723
```sh
8-
pnpm i
24+
npm install @nanoforge-dev/network-server
25+
yarn add @nanoforge-dev/network-server
26+
pnpm add @nanoforge-dev/network-server
27+
bun add @nanoforge-dev/network-server
928
```
1029

11-
## Building
30+
## Example usage
1231

13-
To build the project run:
32+
Initilize the library in your main file.
1433

15-
```sh
16-
pnpm build
34+
```ts
35+
import { type IRunOptions } from "@nanoforge-dev/common";
36+
import { NanoforgeFactory } from "@nanoforge-dev/core";
37+
import { ECSServerLibrary } from "@nanoforge-dev/ecs-server";
38+
39+
export function main(options: IRunServerOptions) {
40+
const app = NanoforgeFactory.createServer();
41+
42+
const network = new NetworkServerLibrary();
43+
44+
app.useNetwork(network);
45+
46+
app.init(options);
47+
48+
app.run();
49+
}
1750
```
1851

19-
## Tests
52+
Use to receive packets
2053

21-
To run tests use:
54+
```ts
55+
export function myReceiveSystem(registry: Registry, ctx: Context) {
56+
const network = ctx.libs.getNetwork<NetworkServerLibrary>();
2257

23-
```sh
24-
pnpm test
58+
network.tcp.getReceivedPackets().forEach((packets, client) => {
59+
packets.forEach((packet) => {
60+
const data = JSON.parse(new TextDecoder().decode(packet));
61+
// Do something with the data
62+
});
63+
});
64+
}
65+
```
66+
67+
Use to send packets to everyones
68+
69+
```ts
70+
export function mySendSystem(registry: Registry, ctx: Context) {
71+
const network = ctx.libs.getNetwork<NetworkServerLibrary>();
72+
73+
// Do something to get a data
74+
const packet = new TextEncoder().encode(JSON.stringify(data));
75+
network.tcp.sendToEverybody(packet);
76+
}
2577
```
78+
79+
## Links
80+
81+
- [GitHub][source]
82+
- [npm][npm]
83+
84+
## Contributing
85+
86+
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
87+
[documentation][documentation].
88+
See [the contribution guide][contributing] if you'd like to submit a PR.
89+
90+
## Help
91+
92+
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to ask questions in [discussions][discussions].
93+
94+
[documentation]: https://github.com/NanoForge-dev/Engine
95+
[discussions]: https://github.com/NanoForge-dev/Engine/discussions
96+
[source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/network-server
97+
[npm]: https://www.npmjs.com/package/@nanoforge-dev/network-server
98+
[contributing]: https://github.com/NanoForge-dev/Engine/blob/main/.github/CONTRIBUTING.md

0 commit comments

Comments
 (0)