remove github, add logger
This commit is contained in:
parent
eee1861752
commit
add6db3bb6
12 changed files with 99 additions and 116 deletions
6
.github/dependabot.yml
vendored
6
.github/dependabot.yml
vendored
|
@ -1,6 +0,0 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
42
.github/workflows/build.yml
vendored
42
.github/workflows/build.yml
vendored
|
@ -1,42 +0,0 @@
|
|||
name: Build
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "./src"
|
||||
- "./tests"
|
||||
push:
|
||||
paths:
|
||||
- "./src"
|
||||
- "./tests"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set Node.js 16.x
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16.x
|
||||
|
||||
- name: Run install
|
||||
uses: borales/actions-yarn@v4
|
||||
with:
|
||||
cmd: install # will run `yarn install` command
|
||||
|
||||
- name: Install aftman
|
||||
uses: ok-nick/setup-aftman@v0.3.0
|
||||
|
||||
- name: Build
|
||||
uses: borales/actions-yarn@v4
|
||||
with:
|
||||
cmd: build # will run `yarn build` command
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: goopler
|
||||
path: build.rbxl
|
33
.github/workflows/lint.yml
vendored
33
.github/workflows/lint.yml
vendored
|
@ -1,33 +0,0 @@
|
|||
name: Lint
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "./src"
|
||||
- "./tests"
|
||||
push:
|
||||
paths:
|
||||
- "./src"
|
||||
- "./tests"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ESLint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set Node.js 16.x
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16.x
|
||||
|
||||
- name: Run install
|
||||
uses: borales/actions-yarn@v4
|
||||
with:
|
||||
cmd: install # will run `yarn install` command
|
||||
|
||||
- name: Lint
|
||||
uses: borales/actions-yarn@v4
|
||||
with:
|
||||
cmd: lint # will run `yarn lint` command
|
|
@ -33,6 +33,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@rbxts/character-promise": "^1.0.2",
|
||||
"@rbxts/log": "^0.6.3",
|
||||
"@rbxts/matter": "^0.6.2-ts.6",
|
||||
"@rbxts/plasma": "^0.4.1-ts.1",
|
||||
"@rbxts/rewire": "^0.3.0",
|
||||
|
|
|
@ -45,9 +45,9 @@ export function start<S extends object>(host: Host, state: S): [World, S] {
|
|||
})
|
||||
|
||||
if (host === Host.All || host === Host.Server) {
|
||||
const _ServerState = state as serverState
|
||||
const ServerState = state as serverState
|
||||
|
||||
startTags(world, tags)
|
||||
startTags(world, tags, ServerState)
|
||||
}
|
||||
|
||||
if (host === Host.All || host === Host.Client) {
|
||||
|
|
|
@ -6,27 +6,17 @@ import { clientState } from "./state"
|
|||
type ComponentNames = keyof typeof Components
|
||||
type ComponentConstructors = (typeof Components)[ComponentNames]
|
||||
|
||||
const DEBUG_SPAWN = "Spawn %ds%d with %s"
|
||||
const DEBUG_DESPAWN = "Despawn %ds%d"
|
||||
const DEBUG_MODIFY = "Modify %ds%d adding %s, removing %s"
|
||||
|
||||
let connection: RBXScriptConnection | undefined
|
||||
|
||||
/**
|
||||
* Starts the replication receiver.
|
||||
*
|
||||
* @param world - The world to replicate components in
|
||||
* @param ClientState - The client state for the ECS
|
||||
* @param client - The client state for the ECS
|
||||
*/
|
||||
export function start(world: World, ClientState: clientState): void {
|
||||
export function start(world: World, client: clientState): void {
|
||||
if (connection) return
|
||||
|
||||
function debugPrint(message: string, args: () => (string | number)[]): void {
|
||||
if (ClientState.debugEnabled) {
|
||||
print("ECS Replication>", string.format(message, ...args()))
|
||||
}
|
||||
}
|
||||
|
||||
const replicationEvent = waitForEvent("EcsReplication")
|
||||
const serverToClientEntity = new Map<string, AnyEntity>()
|
||||
|
||||
|
@ -38,7 +28,11 @@ export function start(world: World, ClientState: clientState): void {
|
|||
if (clientId !== undefined && next(componentMap)[0] === undefined) {
|
||||
world.despawn(clientId)
|
||||
serverToClientEntity.delete(serverId)
|
||||
debugPrint(DEBUG_DESPAWN, () => [clientId, serverId])
|
||||
client.logger.Debug(
|
||||
"ECS Replication> Despawn {@clientId}s{@serverId}",
|
||||
clientId,
|
||||
serverId
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -72,7 +66,12 @@ export function start(world: World, ClientState: clientState): void {
|
|||
if (clientId === undefined) {
|
||||
const clientId = world.spawn(...componentsToInsert)
|
||||
serverToClientEntity.set(serverId, clientId)
|
||||
debugPrint(DEBUG_SPAWN, () => [clientId, serverId, insertNames.join(",")])
|
||||
client.logger.Debug(
|
||||
"ECS Replication> Spawn {@clientId}s{@serverId} with {@insertNames}",
|
||||
clientId,
|
||||
serverId,
|
||||
insertNames.join(",")
|
||||
)
|
||||
} else {
|
||||
if (componentsToInsert.size() > 0) {
|
||||
world.insert(clientId, ...componentsToInsert)
|
||||
|
@ -82,12 +81,13 @@ export function start(world: World, ClientState: clientState): void {
|
|||
world.remove(clientId, ...componentsToRemove)
|
||||
}
|
||||
|
||||
debugPrint(DEBUG_MODIFY, () => [
|
||||
client.logger.Debug(
|
||||
"ECS Replication> Modify {@clientId}s{serverId} adding {@insertNames}, removing {@removeNames}",
|
||||
clientId,
|
||||
serverId,
|
||||
insertNames.size() > 0 ? insertNames.join(", ") : "nothing",
|
||||
removeNames.size() > 0 ? removeNames.join(", ") : "nothing"
|
||||
])
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,54 @@
|
|||
/* eslint-disable roblox-ts/no-private-identifier */
|
||||
|
||||
import { CharacterRigR6 } from "@rbxts/character-promise"
|
||||
import { Logger } from "@rbxts/log"
|
||||
import { InputKind } from "ReplicatedStorage/inputKind"
|
||||
|
||||
/**
|
||||
* The client ECS state.
|
||||
*/
|
||||
export class clientState {
|
||||
[index: string]: unknown
|
||||
character?: CharacterRigR6
|
||||
player?: Player
|
||||
debugEnabled = false
|
||||
isRunning = false
|
||||
constructor(
|
||||
player: Player,
|
||||
character: CharacterRigR6,
|
||||
debugEnabled: boolean,
|
||||
isRunning: boolean,
|
||||
// lastProcessedCommand: Inputkind,
|
||||
|
||||
logger: Logger
|
||||
) {
|
||||
this.character = character
|
||||
this.player = player
|
||||
this.debugEnabled = debugEnabled
|
||||
this.isRunning = isRunning
|
||||
// this.lastProcessedCommand = lastProcessedCommand
|
||||
|
||||
this.logger = logger
|
||||
}
|
||||
|
||||
player: Player
|
||||
character: CharacterRigR6
|
||||
debugEnabled: boolean
|
||||
isRunning: boolean
|
||||
lastProcessedCommand?: InputKind
|
||||
|
||||
logger: Logger
|
||||
}
|
||||
|
||||
/**
|
||||
* The server ECS state.
|
||||
*/
|
||||
export class serverState {
|
||||
[index: string]: unknown
|
||||
constructor(
|
||||
logger: Logger
|
||||
) {
|
||||
this.logger = logger
|
||||
}
|
||||
|
||||
logger: Logger
|
||||
}
|
||||
|
||||
/**
|
||||
* The shared ECS state.
|
||||
*/
|
||||
export type sharedState = serverState & clientState
|
|
@ -2,6 +2,7 @@ import { AnyEntity, Component, World } from "@rbxts/matter"
|
|||
import { CollectionService } from "@rbxts/services"
|
||||
import { getIdAttribute } from "ReplicatedStorage/idAttribute"
|
||||
import { Model, Transform } from "./components"
|
||||
import { serverState } from "./state"
|
||||
|
||||
export type ComponentConstructor<T extends object> = () => Component<T>
|
||||
|
||||
|
@ -15,7 +16,8 @@ const connections: RBXScriptConnection[] = []
|
|||
*/
|
||||
export function start(
|
||||
world: World,
|
||||
bound: ReadonlyMap<string, ComponentConstructor<object>>
|
||||
bound: ReadonlyMap<string, ComponentConstructor<object>>,
|
||||
server: serverState
|
||||
): void {
|
||||
function spawnBound<T extends object>(
|
||||
instance: Instance,
|
||||
|
@ -26,13 +28,13 @@ export function start(
|
|||
if (instance.PrimaryPart) {
|
||||
primaryPart = instance.PrimaryPart
|
||||
} else {
|
||||
warn("Attempted to tag a model that has no primary part:", instance)
|
||||
server.logger.Warn("Attempted to tag a model that has no primary part: {@instance}", instance)
|
||||
return
|
||||
}
|
||||
} else if (instance.IsA("BasePart")) {
|
||||
primaryPart = instance
|
||||
} else {
|
||||
warn("Attempted to tag an instance that is not a Model or BasePart:", instance)
|
||||
server.logger.Warn("Attempted to tag an instance that is not a Model or BasePart: {@instance}", instance)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { useEvent, World } from "@rbxts/matter"
|
||||
import { Players } from "@rbxts/services"
|
||||
import * as Components from "ReplicatedStorage/ecs/components"
|
||||
import { serverState } from "ReplicatedStorage/ecs/state"
|
||||
import { getEvent } from "ReplicatedStorage/remotes"
|
||||
|
||||
type ComponentName = keyof typeof Components
|
||||
|
@ -20,7 +21,7 @@ const replicatedComponents: ReadonlySet<ComponentConstructor> = REPLICATED_COMPO
|
|||
|
||||
getEvent("EcsReplication")
|
||||
|
||||
function replication(world: World): void {
|
||||
function replication(world: World, server: serverState): void {
|
||||
const replicationEvent = getEvent("EcsReplication")
|
||||
|
||||
let payload: Map<string, Map<ComponentName, { data?: Components.GooplerComponent }>> | undefined
|
||||
|
@ -43,7 +44,7 @@ function replication(world: World): void {
|
|||
}
|
||||
}
|
||||
|
||||
print("Sending initial payload to", player)
|
||||
server.logger.Debug("Sending initial payload to {@player}", player)
|
||||
replicationEvent.FireClient(player, payload)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import Log, { Logger } from "@rbxts/log"
|
||||
import { start } from "ReplicatedStorage/ecs"
|
||||
import { serverState } from "ReplicatedStorage/ecs/state"
|
||||
import { Host } from "ReplicatedStorage/hosts"
|
||||
|
@ -6,7 +7,14 @@ import { getEvent } from "ReplicatedStorage/remotes"
|
|||
|
||||
const HOST = Host.Server
|
||||
|
||||
const ServerState = new serverState()
|
||||
const serverLogger = Logger.configure()
|
||||
.EnrichWithProperty("Roblox-TS Version", _VERSION)
|
||||
.WriteTo(Log.RobloxOutput())
|
||||
.Create()
|
||||
|
||||
const ServerState = new serverState(
|
||||
serverLogger
|
||||
)
|
||||
|
||||
// We only do this here at the moment to create a dummy event for replication.
|
||||
// In the future this will be created by the replication system.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { CharacterRigR6 } from "@rbxts/character-promise"
|
||||
import Log, { Logger } from "@rbxts/log"
|
||||
import { Players } from "@rbxts/services"
|
||||
import { start } from "ReplicatedStorage/ecs"
|
||||
import { clientState } from "ReplicatedStorage/ecs/state"
|
||||
|
@ -7,11 +8,19 @@ import { setEnvironment } from "ReplicatedStorage/idAttribute"
|
|||
|
||||
const HOST = Host.Client
|
||||
|
||||
const ClientState = new clientState()
|
||||
const clientLogger = Logger.configure()
|
||||
.EnrichWithProperty("Roblox-TS Version", _VERSION)
|
||||
.WriteTo(Log.RobloxOutput())
|
||||
.Create()
|
||||
|
||||
const player = Players.LocalPlayer
|
||||
ClientState.character = (player.Character || player.CharacterAdded.Wait()[0]) as CharacterRigR6
|
||||
ClientState.player = player
|
||||
const ClientState = new clientState(
|
||||
Players.LocalPlayer,
|
||||
(Players.LocalPlayer.Character || Players.LocalPlayer.CharacterAdded.Wait()[0]) as CharacterRigR6,
|
||||
false,
|
||||
false,
|
||||
|
||||
clientLogger
|
||||
)
|
||||
|
||||
setEnvironment(HOST)
|
||||
start(HOST, ClientState)
|
12
yarn.lock
12
yarn.lock
|
@ -91,11 +91,23 @@
|
|||
resolved "https://registry.yarnpkg.com/@rbxts/compiler-types/-/compiler-types-2.1.1-types.0.tgz#a1f02b57402dffec474dd6656ec1d8a897b9756b"
|
||||
integrity sha512-wBRma9MgPbOxvCaQEUvraHLHAmLFGW9R6fT65+MBu3uCYM6vUNWj8l4dHRxgkUK8lnGYdGWxsr/sZFk8sdvwog==
|
||||
|
||||
"@rbxts/log@^0.6.3":
|
||||
version "0.6.3"
|
||||
resolved "https://registry.yarnpkg.com/@rbxts/log/-/log-0.6.3.tgz#65b51a897a2d646457db95b563ade3313e08d0be"
|
||||
integrity sha512-YZpDvjL7yif9aYuNAkuM9vnegcwQmOwX0CfvGfWvrzCpmARY4Ey2pTMhoEgxKo36HcdPPi3aLxmcuvn0NHrPPg==
|
||||
dependencies:
|
||||
"@rbxts/message-templates" "^0.3.1"
|
||||
|
||||
"@rbxts/matter@^0.6.2-ts.6":
|
||||
version "0.6.4"
|
||||
resolved "https://registry.yarnpkg.com/@rbxts/matter/-/matter-0.6.4.tgz#49ff6ce56bada1ce7c5e2715a05daaa3fb7615e6"
|
||||
integrity sha512-84naXqNpUfb5aCEcKf99wdqNnNAuwXh4B73GMQBzrUGiF70m0EWTdmm0qHihdlghGPrCRBSFeYK5esMJvKs/SQ==
|
||||
|
||||
"@rbxts/message-templates@^0.3.1":
|
||||
version "0.3.2"
|
||||
resolved "https://registry.yarnpkg.com/@rbxts/message-templates/-/message-templates-0.3.2.tgz#85169980cf73f659282aa9846290ceaf06967167"
|
||||
integrity sha512-79onYskH3pgrBT73Zs+biQ31vAVvupKQaxGNWGjyGsxwNhO2YaN/qkut0bvOshaGa+ZzqAXApRVrN8ifIMPiMQ==
|
||||
|
||||
"@rbxts/plasma@^0.4.1-ts.1":
|
||||
version "0.4.1-ts.1"
|
||||
resolved "https://registry.yarnpkg.com/@rbxts/plasma/-/plasma-0.4.1-ts.1.tgz#3d8db367c3220e6b6953cdddbf8af9f087165392"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue