Skip to content

Commit

Permalink
Feature: Initialize the repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
robloxiandemo committed Jun 28, 2023
0 parents commit de787ff
Show file tree
Hide file tree
Showing 28 changed files with 1,965 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Bug Report
about: File a report to assist us in improving.
title: ""
labels: Bug
assignees: ""
---

**Describe the Bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**The Expected Behavior**
A clear and concise description of what was expected to occur.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment (please provide the following information):**

- OS: [e.g. Windows, Mac, Linux]
- Package Version(s) [e.g. Signal: 0.1.0]

**Additional Context**
Add any additional pieces of context regarding your problem here.
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Feature Request
about: Suggest an idea for this project!
title: ""
labels: Feature
assignees: ""
---

**What package would this be relating to?**

**Describe your problem here:**

**Describe the solution that you'd like:**
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/queston_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: Ask a Question
about: Ask us a question regarding something within the project!
title: ""
labels: Question
assignees: ""
---

**What is your question?**
56 changes: 56 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Compiled Lua sources
luac.out

# luarocks build files
*.src.rock
*.zip
*.tar.gz

# Object files
*.o
*.os
*.ko
*.obj
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo
*.def
*.exp

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Roblox Studio lock files
/*.rbxl.lock
/*.rbxlx.lock

# Roblox Studio files
/*.rbxl
/*.rbxlx

# Miscellaneous
/.vscode
/roblox.toml
/node_modules
/out
/include
*.tsbuildinfo
3 changes: 3 additions & 0 deletions .luarc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"languageMode": "strict"
}
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"tabWidth": 4,
"trailingComma": "all",
"useTabs": true
}
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Demo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
132 changes: 132 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# (Mutable) Fast Replica

This is a fork of [@rbxts/fast-replica](https://www.npmjs.com/package/@rbxts/fast-replica) that removes the reliance of the `DeepReadonly` type, allowing for mutable permutations to pass. Everyrthing else is the same ([this uses version 3.0.2 of @rbxts/fast-replica](https://www.npmjs.com/package/@rbxts/fast-replica/v/3.0.2)).

A simple and intuitive package for sharing data from server to client. Structured in a similar manner to `@flamework/networking`.

This is preferable to `@rbxts/replica-service` if you are looking for fully pre-defined replicas that will be automatically initialized before use.

## API:

### FastReplica (Shared)

FastReplica.createReplicas<Replicas>(initialData: Replicas): GlobalReplicas
The Replicas that will be created, it is considered good practice to only call this once.

### Replica Client

#### readonly Replica.Name: string

The ID the Replica identifies as.

#### Replica.Loaded

Whether the server has sent information to the replica yet. Do **NOT** modify this value.

#### Replica.GetValue(): DeepReadonly<Data>

Returns the current value of the Replica.

#### Replica.Started: Signal<(data: DeepReadonly<Data>) => void>

A signal that fires when the replica is first initialized by the server. Do note that you can use the Replica before then, but it will only contain the initial value.

#### Replica.Changed: Signal<(data: DeepReadonly<Data>) => void>

A signal that fires every time the server sends new data to the client.

#### Replica.PathChanged: Signal<(path: Path<Data>, value: PathValue<P>) => void>

A signal that fires when the server only changes a specific path.

### Replica Server

#### readonly Replica.Name: string

The ID the Replica identifies as.

#### Replica.SetValue(clients: Player | Player[] | "All", Value: Data): void

Syncs the value provided with the clients specified within the arguments.

#### Replica.SetPath(clients: Player | Player[] | "All", path: Path<Data> Value: Data): void

Syncs the specific path value to the clients provided

#### Replica.Assimilate(clients: Player | Player[]): void

Assimilate the client's value back to what "All" should have.

#### Replica.GetValue(player: Player): Data

Fetches the value the specific player current is using.

#### Replica.Started: Signal<(player: Player, data: DeepReadonly<Data>) => void>

A signal that fires when a player is first initialized by the server.

#### Replica.Changed: Signal<(player: Player, data: DeepReadonly<Data>) => void>

A signal that fires every time the server sends new data to a client.

#### Replica.PathChanged: Signal<(path: Path<Data>, value: PathValue<P>) => void>

A signal that fires when the only a specific path on the provided clients will be changed.

## Code Examples:

### Shared

```TS
// shared/replicas.ts
import { FastReplica } from "@rbxts/fast-replica";

type Replicas = { Profile: { Level: number } };
export const globalReplicas = FastReplica.createReplicas<Replicas>({
Profile: { Level: 0 }, // Initial Value (For when not replicated and default replication)
State: "Intermission", // Can be any value that could be naturally replicated via RemoteEvents!
ExtraData: {
Players: {
Local: 1,
},
},
})
```

### Client

```TS
// client/replicas.ts
import { globalReplicas } from "shared/replicas";
export const Replicas = globalReplicas.client;
```

```TS
import { Replicas } from "client/replicas";

Replicas.Profile.Changed.Connect((value, old) => print(value.Level)); // Fires every time the Value is changed on the server.
Replicas.State.Started.Connect((value) => print(value)); // This fires when the server first syncs the data.
print(Replicas.State.GetValue()); // Fetches and prints the value.
Replicas.ExtraData.PathChanged.Connect((path, value) => print(`Path changed: ${path}: ${value}`));
```

### Server

```TS
// server/replicas.ts
import { globalReplicas } from "shared/replicas";
export const Replicas = globalReplicas.server;
```

```TS
import { Replicas } from "client/replicas";
import { Players } from "@rbxts/services";

task.wait(2.5)
Replicas.Profile.Started.Connect((player: Player, value) => print(`${player.DisplayName}: ${tostring(value)}`)); // Fires when the server sends the initial data to a player.
Replicas.Profile.Changed.Connect((player: Player, value) => print(`${player.DisplayName}: ${tostring(value)}`)); // Fires every time the server sends data to a player.
Replicas.Profile.SetPath("All", "Level", { Level: 10 }); // Sets the value to every player.
Replicas.State.SetValue(Players.GetPlayers(), "Spectating"); // This accepts Player instances or an array of Players as well!
print(Replicas.State.GetValue(Players.GetPlayers()[0])); // Prints the value for a specific player.
Replicas.ExtraData.SetPath("All", "Players.Local", 2);
```
1 change: 1 addition & 0 deletions aftman.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tools = { lua-lsp = "JohnnyMorganz/[email protected]", rojo = "rojo-rbx/[email protected]", selene = "Kampfkarren/[email protected]", stylua = "JohnnyMorganz/[email protected]", wally = "UpliftGames/[email protected]" }
68 changes: 68 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "@rbxts/rbxts-fast-replica",
"version": "1.0.0",
"description": "A (mutable) simple and intuitive package for sharing data from server to client.",
"main": "src/init.lua",
"types": "src/index.d.ts",
"files": [
"src"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1."
},
"repository": {
"type": "git",
"url": "https://github.com/rbxts-libraries/rbxts-mutable-fast-replica.git"
},
"author": {
"name": "RobloxianDemo",
"url": "https://github.com/RobloxianDemo"
},
"contributors": [
{
"name": "RobloxianDemo",
"url": "https://github.com/RobloxianDemo"
}
],
"keywords": [
"array",
"fast",
"fast-replica",
"list",
"table",
"replica",
"replication",
"roblox",
"roblox-typescript",
"roblox-ts",
"service",
"sorter",
"utility"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/rbxts-libraries/rbxts-mutable-fast-replica/issues"
},
"homepage": "https://github.com/rbxts-libraries/rbxts-mutable-fast-replica/README.md",
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@rbxts/compiler-types": "^2.1.0-types.1",
"@rbxts/types": "^1.0.701",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-roblox-ts": "^0.0.31",
"prettier": "^2.8.8",
"typescript": "^4.9.5"
},
"dependencies": {
"@rbxts/goodsignal": "^0.0.5",
"@rbxts/services": "^1.5.1",
"@rbxts/t": "^2.2.1",
"github-label-presets": "^1.3.0"
}
}
9 changes: 9 additions & 0 deletions selene.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
std = "roblox"

[rules]
parenthese_conditions = "allow"
multiple_statements = "allow"
global_usage = "allow"

[config]
unused_variable = { allow_unused_self = true }
19 changes: 19 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ReplicaClient from "./replica-client";
import ReplicaServer from "./replica-server";
declare type Replicas = {
[key in string]: unknown;
};
declare type ServerReplicas<R> = {
[key in keyof R]: ReplicaServer<R[key]>;
};
declare type ClientReplicas<R> = {
[key in keyof R]: ReplicaClient<R[key]>;
};
declare type GlobalReplicas<R extends Replicas> = {
server: ServerReplicas<R>;
client: ClientReplicas<R>;
};
export declare namespace FastReplica {
const createReplicas: <R extends Replicas>(initialValues: R) => GlobalReplicas<R>;
}
export {};
Loading

0 comments on commit de787ff

Please sign in to comment.