Skip to content

Commit a7c03f1

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

File tree

7 files changed

+251
-67
lines changed

7 files changed

+251
-67
lines changed

.github/logo.png

20.1 KB
Loading

README.md

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,73 @@
1-
# Engine
2-
3-
This repository contains the full engine for NanoForge.
4-
It can be used by itself.
5-
6-
The engine is made of multiple components:
7-
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-
19-
This is the full nanoforge engine including all the default libraries.
20-
21-
In order to manage this project we use (pnpm)[https://pnpm.io/]
22-
23-
## Installing dependencies
24-
25-
To install dependencies run:
26-
27-
```sh
28-
pnpm i
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>
13+
14+
## About
15+
16+
This repository contains multiple packages with separate [releases][github-releases]. Nanoforge is a powerful game engine for web browser.
17+
18+
## Usage
19+
20+
To use Nanoforge Engine, please refer to the [CLI documentation][cli-source] !
21+
22+
First, install the CLI :
23+
```bash
24+
npm install -g @nanoforge-dev/cli
2925
```
3026

31-
## Building
32-
33-
To build the project run:
34-
35-
```sh
36-
pnpm build
27+
And then create a new project :
28+
```bash
29+
nf new
3730
```
3831

39-
## Tests
40-
41-
To run tests use:
42-
43-
```sh
44-
pnpm test
45-
```
46-
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]
32+
## Packages
33+
34+
- `@nanoforge-dev/common` ([source][common-source]) - Common interfaces and utilities used by Nanoforge Engine
35+
- `@nanoforge-dev/core` ([source][core-source]) - A core package that contains game main loop
36+
- `@nanoforge-dev/ecs-lib` ([source][ecs-lib-source]) - A powerful data structure for managing game entities (*do not use this in your projects*)
37+
- `@nanoforge-dev/ecs-client` ([source][ecs-client-source]) - A wrapper of `@nanoforge-dev/ecs-lib` for client-side usage
38+
- `@nanoforge-dev/ecs-server` ([source][ecs-server-source]) - A wrapper of `@nanoforge-dev/ecs-lib` for server-side usage
39+
- `@nanoforge-dev/config` ([source][config-source]) - A wrapper of `class-validator` and `class-transformer` to imports validation and transformation decorators
40+
- `@nanoforge-dev/graphics-2d` ([source][graphics-2d-source]) - A base 2D graphics library
41+
- `@nanoforge-dev/asset-manager` ([source][asset-manager-source]) - A manager for loading assets to uniform workwith between client and server
42+
- `@nanoforge-dev/network-client` ([source][network-client-source]) - A network lib with tcp and udp support for client-side usage
43+
- `@nanoforge-dev/network-server` ([source][network-server-source]) - A network lib with tcp and udp support for server-side usage
44+
- `@nanoforge-dev/input` ([source][input-source]) - An input manager for handling keyboard and mouse events
45+
- `@nanoforge-dev/music` ([source][music-source]) - A music player for your game
46+
- `@nanoforge-dev/sound` ([source][sound-source]) - A sound manager for your game
47+
48+
## Contributing
49+
50+
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.
51+
52+
## Help
53+
54+
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].
55+
56+
[contributing]: https://github.com/NanoForge-dev/Engine/blob/main/.github/CONTRIBUTING.md
57+
[discussions]: https://github.com/NanoForge-dev/Engine/discussions
58+
[cli-source]: https://github.com/NanoForge-dev/CLI
59+
[github-releases]: https://github.com/NanoForge-dev/Engine/releases
60+
[asset-manager-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/asset-manager
61+
[common-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/common
62+
[config-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/config
63+
[core-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/core
64+
[ecs-client-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/ecs-client
65+
[ecs-lib-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/ecs-lib
66+
[ecs-server-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/ecs-server
67+
[graphics-2d-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/graphics-2d
68+
[input-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/input
69+
[music-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/music
70+
[network-client-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/network-client
71+
[network-server-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/network-server
72+
[sound-source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/sound
73+
[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: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,93 @@
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+
```ts
34+
import { type IRunOptions } from "@nanoforge-dev/common";
35+
import { NanoforgeFactory } from "@nanoforge-dev/core";
36+
import { ECSClientLibrary } from "@nanoforge-dev/ecs-client";
37+
38+
export function main(options: IRunClientOptions) {
39+
const app = NanoforgeFactory.createClient();
40+
41+
const network = new NetworkClientLibrary();
42+
43+
app.useNetwork(network);
44+
45+
app.init(options);
46+
47+
app.run();
48+
}
49+
```
50+
51+
Use to receive packets
52+
```ts
53+
export function myReceiveSystem(registry: Registry, ctx: Context) {
54+
const network = ctx.libs.getNetwork<NetworkClientLibrary>();
55+
56+
network.tcp.getReceivedPackets().forEach(packet => {
57+
const data = JSON.parse(new TextDecoder().decode(packet));
58+
// Do something with the data
59+
});
60+
}
61+
```
62+
63+
Use to send packets
64+
```ts
65+
export function mySendSystem(registry: Registry, ctx: Context) {
66+
const network = ctx.libs.getNetwork<NetworkClientLibrary>();
67+
68+
// Do something to get a data
69+
const packet = new TextEncoder().encode(JSON.stringify(data));
70+
network.tcp.sendPacket(packet);
71+
}
72+
```
73+
74+
## Links
75+
76+
- [GitHub][source]
77+
- [npm][npm]
78+
79+
## Contributing
80+
81+
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
82+
[documentation][documentation].
83+
See [the contribution guide][contributing] if you'd like to submit a PR.
84+
85+
## Help
86+
87+
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].
88+
89+
[documentation]: https://github.com/NanoForge-dev/Engine
90+
[discussions]: https://github.com/NanoForge-dev/Engine/discussions
91+
[source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/network-client
92+
[npm]: https://www.npmjs.com/package/@nanoforge-dev/network-client
93+
[contributing]: https://github.com/NanoForge-dev/Engine/blob/main/.github/CONTRIBUTING.md

packages/network-server/README.md

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,95 @@
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.
33+
```ts
34+
import { type IRunOptions } from "@nanoforge-dev/common";
35+
import { NanoforgeFactory } from "@nanoforge-dev/core";
36+
import { ECSServerLibrary } from "@nanoforge-dev/ecs-server";
1437

15-
```sh
16-
pnpm build
38+
export function main(options: IRunServerOptions) {
39+
const app = NanoforgeFactory.createServer();
40+
41+
const network = new NetworkServerLibrary();
42+
43+
app.useNetwork(network);
44+
45+
app.init(options);
46+
47+
app.run();
48+
}
1749
```
1850

19-
## Tests
20-
21-
To run tests use:
51+
Use to receive packets
52+
```ts
53+
export function myReceiveSystem(registry: Registry, ctx: Context) {
54+
const network = ctx.libs.getNetwork<NetworkServerLibrary>();
55+
56+
network.tcp.getReceivedPackets().forEach((packets, client) => {
57+
packets.forEach((packet) => {
58+
const data = JSON.parse(new TextDecoder().decode(packet));
59+
// Do something with the data
60+
});
61+
});
62+
}
63+
```
2264

23-
```sh
24-
pnpm test
65+
Use to send packets to everyones
66+
```ts
67+
export function mySendSystem(registry: Registry, ctx: Context) {
68+
const network = ctx.libs.getNetwork<NetworkServerLibrary>();
69+
70+
// Do something to get a data
71+
const packet = new TextEncoder().encode(JSON.stringify(data));
72+
network.tcp.sendToEverybody(packet);
73+
}
2574
```
75+
76+
## Links
77+
78+
- [GitHub][source]
79+
- [npm][npm]
80+
81+
## Contributing
82+
83+
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
84+
[documentation][documentation].
85+
See [the contribution guide][contributing] if you'd like to submit a PR.
86+
87+
## Help
88+
89+
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].
90+
91+
[documentation]: https://github.com/NanoForge-dev/Engine
92+
[discussions]: https://github.com/NanoForge-dev/Engine/discussions
93+
[source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/network-server
94+
[npm]: https://www.npmjs.com/package/@nanoforge-dev/network-server
95+
[contributing]: https://github.com/NanoForge-dev/Engine/blob/main/.github/CONTRIBUTING.md

0 commit comments

Comments
 (0)