This commit is contained in:
wuyanchen 2025-12-23 05:13:45 +08:00
parent e6caf2b5d6
commit 2da92db9f0
10 changed files with 861 additions and 1321 deletions

View File

@ -1,18 +1,5 @@
import { _decorator, Component, director, Game, game, v3, Vec3 } from "cc";
// 据报道微信的JavaScript运行时不支持通过WebSocket直接发送或数据类型。为了绕过这个问题你可以对这些数据类型进行猴子补丁将这些数据类型转换成微信能处理的格式。Uint8ArrayArrayWebSocket.send
const WebSocket_send = WebSocket.prototype.send;
WebSocket.prototype.send = function (data) {
if (data instanceof Uint8Array) {
WebSocket_send.call(this, data.slice().buffer);
} else if (Array.isArray(data)) {
WebSocket_send.call(this, new Uint8Array(data).buffer);
} else {
WebSocket_send.call(this, data);
}
};
import Colyseus, { RoomAvailable } from "db://colyseus-sdk/colyseus.js";
import Colyseus, { RoomAvailable } from "../net/colyseus/colyseus.js";
import { XNetEventKeys } from "../net/XNetEventKeys";
import { Global } from "../Global";
const { ccclass, property } = _decorator;

View File

@ -1,5 +1,8 @@
// Generated by dts-bundle-generator v9.5.1
import * as httpie from '@colyseus/httpie';
import { Packr } from '@colyseus/msgpackr';
export interface ITransportEventMap {
onopen?: ((ev: any) => any) | null;
onmessage?: ((ev: any) => any) | null;
@ -42,19 +45,19 @@ declare enum OPERATION {
DELETE_BY_REFID = 33,// This operation is only used at ENCODING time. During DECODING, DELETE_BY_REFID is converted to DELETE
ADD_BY_REFID = 129
}
declare const $track = "~track";
declare const $encoder = "~encoder";
declare const $decoder = "~decoder";
declare const $filter = "~filter";
declare const $getByIndex = "~getByIndex";
declare const $deleteByIndex = "~deleteByIndex";
declare const $changes = "~changes";
declare const $onEncodeEnd = "~onEncodeEnd";
declare const $onDecodeEnd = "~onDecodeEnd";
declare const $descriptors = "~descriptors";
declare const $numFields = "~__numFields";
declare const $refTypeFieldIndexes = "~__refTypeFieldIndexes";
declare const $viewFieldIndexes = "~__viewFieldIndexes";
declare const $track: unique symbol;
declare const $encoder: unique symbol;
declare const $decoder: unique symbol;
declare const $filter: unique symbol;
declare const $getByIndex: unique symbol;
declare const $deleteByIndex: unique symbol;
declare const $changes: unique symbol;
declare const $onEncodeEnd: unique symbol;
declare const $onDecodeEnd: unique symbol;
declare const $descriptors: unique symbol;
declare const $numFields = "$__numFields";
declare const $refTypeFieldIndexes = "$__refTypeFieldIndexes";
declare const $viewFieldIndexes = "$__viewFieldIndexes";
declare const $fieldIndexesByViewTag = "$__fieldIndexesByViewTag";
declare class TypeContext {
types: {
@ -98,22 +101,16 @@ declare class Root {
changeTrees: {
[refId: number]: ChangeTree;
};
allChanges: ChangeTreeList;
allFilteredChanges: ChangeTreeList;
changes: ChangeTreeList;
filteredChanges: ChangeTreeList;
allChanges: ChangeTree[];
allFilteredChanges: ChangeTree[];
changes: ChangeTree[];
filteredChanges: ChangeTree[];
constructor(types: TypeContext);
getNextUniqueId(): number;
add(changeTree: ChangeTree): boolean;
remove(changeTree: ChangeTree): number;
recursivelyMoveNextToParent(changeTree: ChangeTree): void;
moveNextToParent(changeTree: ChangeTree): void;
moveNextToParentInChangeTreeList(changeSetName: ChangeSetName, changeTree: ChangeTree): void;
enqueueChangeTree(changeTree: ChangeTree, changeSet: "changes" | "filteredChanges" | "allFilteredChanges" | "allChanges", queueRootNode?: ChangeTreeNode): void;
protected addToChangeTreeList(list: ChangeTreeList, changeTree: ChangeTree): ChangeTreeNode;
protected updatePositionsAfterRemoval(list: ChangeTreeList, removedPosition: number): void;
protected updatePositionsAfterMove(list: ChangeTreeList, node: ChangeTreeNode, newPosition: number): void;
removeChangeFromChangeSet(changeSetName: ChangeSetName, changeTree: ChangeTree): boolean;
removeChangeFromChangeSet(changeSetName: "allChanges" | "changes" | "filteredChanges" | "allFilteredChanges", changeTree: ChangeTree): boolean;
clear(): void;
}
declare class Encoder<T extends Schema = any> {
static BUFFER_SIZE: number;
@ -190,7 +187,7 @@ export type SchemaCallbacks = {
declare class ReferenceTracker {
refs: Map<number, Ref>;
refIds: WeakMap<Ref, number>;
refCount: {
refCounts: {
[refId: number]: number;
};
deletedRefs: Set<number>;
@ -215,7 +212,6 @@ declare class Decoder<T extends Schema = any> {
constructor(root: T, context?: TypeContext);
protected setState(root: T): void;
decode(bytes: Buffer, it?: Iterator$1, ref?: Ref): DataChange<any, string>[];
skipCurrentStructure(bytes: Buffer, it: Iterator$1, totalBytes: number): void;
getInstanceType(bytes: Buffer, it: Iterator$1, defaultType: typeof Schema): typeof Schema;
createInstanceOfType(type: typeof Schema): Schema;
removeChildRefs(ref: Collection, allChanges: DataChange[]): void;
@ -238,7 +234,7 @@ declare class MapSchema<V = any, K extends string = string> implements Map<K, V>
protected $items: Map<K, V>;
protected $indexes: Map<number, K>;
protected deletedItems: {
[index: string]: V;
[field: string]: V;
};
protected [$changes]: ChangeTree;
static [$encoder]: EncodeOperation<any>;
@ -331,34 +327,19 @@ export type ChangeSetName = "changes" | "allChanges" | "filteredChanges" | "allF
export interface IndexedOperations {
[index: number]: OPERATION;
}
export interface ChangeTreeNode {
changeTree: ChangeTree;
next?: ChangeTreeNode;
prev?: ChangeTreeNode;
position: number;
}
export interface ChangeTreeList {
next?: ChangeTreeNode;
tail?: ChangeTreeNode;
}
export interface ChangeSet {
indexes: {
[index: number]: number;
};
operations: number[];
queueRootNode?: ChangeTreeNode;
}
export interface ParentChain {
ref: Ref;
index: number;
next?: ParentChain;
queueRootIndex?: number;
}
declare class ChangeTree<T extends Ref = any> {
ref: T;
refId: number;
metadata: Metadata;
root?: Root;
parentChain?: ParentChain;
parent?: Ref;
parentIndex?: number;
/**
* Whether this structure is parent of a filtered structure.
*/
@ -379,7 +360,7 @@ declare class ChangeTree<T extends Ref = any> {
constructor(ref: T);
setRoot(root: Root): void;
setParent(parent: Ref, root?: Root, parentIndex?: number): void;
forEachChild(callback: (change: ChangeTree, at: any) => void): void;
forEachChild(callback: (change: ChangeTree, atIndex: number) => void): void;
operation(op: OPERATION): void;
change(index: number, operation?: OPERATION): void;
shiftChangeIndexes(shiftIndex: number): void;
@ -397,42 +378,10 @@ declare class ChangeTree<T extends Ref = any> {
* (Used in tests only)
*/
discardAll(): void;
ensureRefId(): void;
get changed(): boolean;
protected checkIsFiltered(parent: Ref, parentIndex: number, isNewChangeTree: boolean): void;
protected checkIsFiltered(parent: Ref, parentIndex: number): void;
protected _checkFilteredByParent(parent: Ref, parentIndex: number): void;
/**
* Get the immediate parent
*/
get parent(): Ref | undefined;
/**
* Get the immediate parent index
*/
get parentIndex(): number | undefined;
/**
* Add a parent to the chain
*/
addParent(parent: Ref, index: number): void;
/**
* Remove a parent from the chain
* @param parent - The parent to remove
* @returns true if parent was removed
*/
removeParent(parent?: Ref): boolean;
/**
* Find a specific parent in the chain
*/
findParent(predicate: (parent: Ref, index: number) => boolean): ParentChain | undefined;
/**
* Check if this ChangeTree has a specific parent
*/
hasParent(predicate: (parent: Ref, index: number) => boolean): boolean;
/**
* Get all parents as an array (for debugging/testing)
*/
getAllParents(): Array<{
ref: Ref;
index: number;
}>;
}
declare class StateView {
iterable: boolean;
@ -456,7 +405,7 @@ declare class StateView {
*/
changes: Map<number, IndexedOperations>;
constructor(iterable?: boolean);
add(obj: Ref, tag?: number, checkIncludeParent?: boolean): boolean;
add(obj: Ref, tag?: number, checkIncludeParent?: boolean): this;
protected addParentOf(childChangeTree: ChangeTree, tag: number): void;
remove(obj: Ref, tag?: number): this;
remove(obj: Ref, tag?: number, _isClear?: boolean): this;
@ -523,38 +472,24 @@ export interface Collection<K = any, V = any, IT = V> {
export type InferValueType<T extends DefinitionType> = T extends "string" ? string : T extends "number" ? number : T extends "int8" ? number : T extends "uint8" ? number : T extends "int16" ? number : T extends "uint16" ? number : T extends "int32" ? number : T extends "uint32" ? number : T extends "int64" ? number : T extends "uint64" ? number : T extends "float32" ? number : T extends "float64" ? number : T extends "boolean" ? boolean : T extends {
type: infer ChildType extends Constructor;
} ? InstanceType<ChildType> : T extends {
type: Array<infer ChildType>;
} ? (ChildType extends Record<string | number, string | number> ? ChildType[keyof ChildType][] : ChildType[]) : T extends {
type: {
map: infer ChildType;
};
} ? (ChildType extends Record<string | number, string | number> ? MapSchema<ChildType[keyof ChildType]> : MapSchema<ChildType>) : T extends {
type: {
set: infer ChildType;
};
} ? (ChildType extends Record<string | number, string | number> ? SetSchema<ChildType[keyof ChildType]> : SetSchema<ChildType>) : T extends {
type: {
collection: infer ChildType;
};
} ? (ChildType extends Record<string | number, string | number> ? CollectionSchema<ChildType[keyof ChildType]> : CollectionSchema<ChildType>) : T extends {
type: infer ChildType;
} ? (ChildType extends Record<string | number, string | number> ? ChildType[keyof ChildType] : ChildType) : T extends Array<infer ChildType extends Constructor> ? InstanceType<ChildType>[] : T extends Array<infer ChildType> ? (ChildType extends Record<string | number, string | number> ? ChildType[keyof ChildType][] : ChildType[]) : T extends {
type: infer ChildType extends PrimitiveType;
} ? ChildType : T extends Array<infer ChildType extends Constructor> ? InstanceType<ChildType>[] : T extends Array<infer ChildType extends RawPrimitiveType> ? ChildType[] : T extends {
array: infer ChildType extends Constructor;
} ? InstanceType<ChildType>[] : T extends {
array: infer ChildType;
} ? (ChildType extends Record<string | number, string | number> ? ChildType[keyof ChildType][] : ChildType[]) : T extends {
array: infer ChildType extends PrimitiveType;
} ? ChildType[] : T extends {
map: infer ChildType extends Constructor;
} ? MapSchema<InstanceType<ChildType>> : T extends {
map: infer ChildType;
} ? (ChildType extends Record<string | number, string | number> ? MapSchema<ChildType[keyof ChildType]> : MapSchema<ChildType>) : T extends {
map: infer ChildType extends PrimitiveType;
} ? MapSchema<ChildType> : T extends {
set: infer ChildType extends Constructor;
} ? SetSchema<InstanceType<ChildType>> : T extends {
set: infer ChildType;
} ? (ChildType extends Record<string | number, string | number> ? SetSchema<ChildType[keyof ChildType]> : SetSchema<ChildType>) : T extends {
set: infer ChildType extends PrimitiveType;
} ? SetSchema<ChildType> : T extends {
collection: infer ChildType extends Constructor;
} ? CollectionSchema<InstanceType<ChildType>> : T extends {
collection: infer ChildType;
} ? (ChildType extends Record<string | number, string | number> ? CollectionSchema<ChildType[keyof ChildType]> : CollectionSchema<ChildType>) : T extends Constructor ? InstanceType<T> : T extends Record<string | number, string | number> ? T[keyof T] : T extends PrimitiveType ? T : never;
collection: infer ChildType extends PrimitiveType;
} ? CollectionSchema<ChildType> : T extends Constructor ? InstanceType<T> : T extends PrimitiveType ? T : never;
export type NonFunctionProps<T> = Omit<T, {
[K in keyof T]: T[K] extends Function ? K : never;
}[keyof T]>;
@ -757,24 +692,24 @@ declare class ArraySchema<V = any> implements Array<V>, Collection<number, V> {
*/
toLocaleString(): string;
/** Iterator */
[Symbol.iterator](): ArrayIterator<V>;
[Symbol.iterator](): IterableIterator<V>;
static get [Symbol.species](): typeof ArraySchema;
[Symbol.unscopables]: any;
/**
* Returns an iterable of key, value pairs for every entry in the array
*/
entries(): ArrayIterator<[
entries(): IterableIterator<[
number,
V
]>;
/**
* Returns an iterable of keys in the array
*/
keys(): ArrayIterator<number>;
keys(): IterableIterator<number>;
/**
* Returns an iterable of values in the array
*/
values(): ArrayIterator<V>;
values(): IterableIterator<V>;
/**
* Determines whether an array includes a certain element, returning true or false as appropriate.
* @param searchElement The element to search for.
@ -904,9 +839,7 @@ declare class Schema {
* @param showContents display JSON contents of the instance
* @returns
*/
static debugRefIds(ref: Ref, showContents?: boolean, level?: number, decoder?: Decoder, keyPrefix?: string): string;
static debugRefIdEncodingOrder(ref: Ref, changeSet?: ChangeSetName): number[];
static debugRefIdsFromDecoder(decoder: Decoder): string;
static debugRefIds(ref: Ref, showContents?: boolean, level?: number): string;
/**
* Return a string representation of the changes on a Schema instance.
* The list of changes is cleared after each encode.
@ -918,14 +851,7 @@ declare class Schema {
static debugChanges(instance: Ref, isEncodeAll?: boolean): string;
static debugChangesDeep(ref: Ref, changeSetName?: "changes" | "allChanges" | "allFilteredChanges" | "filteredChanges"): string;
}
/**
* TODO: define a schema interface, which even having duplicate definitions, it could be used to get the callback proxy.
*
* ```ts
* export type SchemaCallbackProxy<RoomState> = (<T extends Schema>(instance: T) => CallbackProxy<T>);
* ```
*/
export type SchemaCallbackProxy<RoomState> = (<T>(instance: T) => CallbackProxy<T>);
export type SchemaCallbackProxy<RoomState> = (<T extends Schema>(instance: T) => CallbackProxy<T>);
export type CallbackProxy<T> = unknown extends T ? SchemaCallback<T> & CollectionCallback<any, any> : T extends Collection<infer K, infer V, infer _> ? CollectionCallback<K, V> : SchemaCallback<T>;
export type SchemaCallback<T> = {
/**
@ -992,7 +918,7 @@ export interface Serializer<State> {
}
export declare function registerSerializer(id: string, serializer: any): void;
export type SchemaConstructor<T = Schema> = new (...args: any[]) => T;
export declare function getStateCallbacks<T>(room: Room<T>): SchemaCallbackProxy<T>;
export declare function getStateCallbacks<T extends Schema>(room: Room<T>): SchemaCallbackProxy<T>;
export declare class SchemaSerializer<T extends Schema = any> implements Serializer<T> {
state: T;
decoder: Decoder<T>;
@ -1002,64 +928,6 @@ export declare class SchemaSerializer<T extends Schema = any> implements Seriali
teardown(): void;
handshake(bytes: Buffer, it?: Iterator$1): void;
}
declare enum FLOAT32_OPTIONS {
NEVER = 0,
ALWAYS = 1,
DECIMAL_ROUND = 3,
DECIMAL_FIT = 4
}
export interface Options {
useFloat32?: FLOAT32_OPTIONS;
useRecords?: boolean | ((value: any) => boolean);
structures?: {}[];
moreTypes?: boolean;
sequential?: boolean;
structuredClone?: boolean;
mapsAsObjects?: boolean;
variableMapSize?: boolean;
coercibleKeyAsNumber?: boolean;
copyBuffers?: boolean;
bundleStrings?: boolean;
useTimestamp32?: boolean;
largeBigIntToFloat?: boolean;
largeBigIntToString?: boolean;
useBigIntExtension?: boolean;
encodeUndefinedAsNil?: boolean;
maxSharedStructures?: number;
maxOwnStructures?: number;
mapAsEmptyObject?: boolean;
setAsEmptyObject?: boolean;
allowArraysInMapKeys?: boolean;
writeFunction?: () => any;
/** @deprecated use int64AsType: 'number' */
int64AsNumber?: boolean;
int64AsType?: "bigint" | "number" | "string";
shouldShareStructure?: (keys: string[]) => boolean;
getStructures?(): {}[];
saveStructures?(structures: {}[]): boolean | void;
onInvalidDate?: () => any;
}
export type UnpackOptions = {
start?: number;
end?: number;
lazy?: boolean;
} | number;
declare class Unpackr {
constructor(options?: Options);
unpack(messagePack: Buffer | Uint8Array, options?: UnpackOptions): any;
decode(messagePack: Buffer | Uint8Array, options?: UnpackOptions): any;
unpackMultiple(messagePack: Buffer | Uint8Array): any[];
unpackMultiple(messagePack: Buffer | Uint8Array, forEach: (value: any, start?: number, end?: number) => any): void;
}
declare class Packr extends Unpackr {
offset: number;
position: number;
buffer: Buffer | Uint8Array;
pack(value: any, encodeOptions?: number): Buffer;
encode(value: any, encodeOptions?: number): Buffer;
useBuffer(buffer: Buffer | Uint8Array): void;
clearSharedData(): void;
}
export type FunctionParameters<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
declare class EventEmitter<CallbackSignature extends (...args: any[]) => any> {
handlers: Array<CallbackSignature>;
@ -1136,21 +1004,6 @@ export declare class Room<State = any> {
private destroy;
private getMessageHandlerKey;
}
interface Options$1 {
reviver(key: string, value: any): any;
headers: Headers | Record<string, string>;
withCredentials: boolean;
redirect: boolean;
timeout: number;
body: any;
signal: AbortSignal;
}
interface Response$1<T = any> {
headers: Record<string, string>;
statusMessage: string;
statusCode: number;
data: T;
}
declare class HTTP {
protected client: Client;
headers: {
@ -1160,12 +1013,12 @@ declare class HTTP {
constructor(client: Client, headers?: {
[id: string]: string;
});
get<T = any>(path: string, options?: Partial<Options$1>): Promise<Response$1<T>>;
post<T = any>(path: string, options?: Partial<Options$1>): Promise<Response$1<T>>;
del<T = any>(path: string, options?: Partial<Options$1>): Promise<Response$1<T>>;
put<T = any>(path: string, options?: Partial<Options$1>): Promise<Response$1<T>>;
protected request(method: "get" | "post" | "put" | "del", path: string, options?: Partial<Options$1>): Promise<Response$1>;
protected getOptions(options: Partial<Options$1>): Partial<Options$1>;
get<T = any>(path: string, options?: Partial<httpie.Options>): Promise<httpie.Response<T>>;
post<T = any>(path: string, options?: Partial<httpie.Options>): Promise<httpie.Response<T>>;
del<T = any>(path: string, options?: Partial<httpie.Options>): Promise<httpie.Response<T>>;
put<T = any>(path: string, options?: Partial<httpie.Options>): Promise<httpie.Response<T>>;
protected request(method: "get" | "post" | "put" | "del", path: string, options?: Partial<httpie.Options>): Promise<httpie.Response>;
protected getOptions(options: Partial<httpie.Options>): Partial<httpie.Options>;
}
export interface AuthSettings {
path: string;
@ -1234,7 +1087,6 @@ export interface EndpointSettings {
secure: boolean;
port?: number;
pathname?: string;
searchParams?: string;
}
export interface ClientOptions {
headers?: {

View File

@ -2,7 +2,7 @@
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "b3d37852-12c5-433f-9b2f-1572b85fabda",
"uuid": "948df0a5-fd19-4537-acb3-4d6989fca934",
"files": [],
"subMetas": {},
"userData": {}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,12 @@
{
"ver": "1.0.0",
"importer": "*",
"imported": true,
"uuid": "a2e44177-4b76-4dc2-9bf2-c4ccf2b00c1a",
"files": [
".json",
".map"
],
"subMetas": {},
"userData": {}
}

View File

@ -0,0 +1,17 @@
{
"ver": "4.0.24",
"importer": "javascript",
"imported": true,
"uuid": "f19f1dfd-757c-4f38-9a51-435f16853554",
"files": [
".js"
],
"subMetas": {},
"userData": {
"loadPluginInEditor": true,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInMiniGame": true,
"isPlugin": true
}
}

View File

@ -1 +0,0 @@
"use strict";exports.methods={},exports.load=function(){},exports.unload=function(){};

View File

@ -1,17 +0,0 @@
{
"name": "colyseus-sdk",
"package_version": 2,
"version": "0.16.0",
"description": "Colyseus Multiplayer SDK for Cocos Creator",
"author": "Endel Dreyer",
"main": "browser.js",
"contributions": {
"asset-db": {
"mount": {
"path": "./runtime",
"readonly": true
}
}
},
"_storeId": "90765df9f9eeea9f12e6bffe40ed6a91"
}

View File

@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "javascript",
"imported": true,
"uuid": "b554cfc3-98f3-4c04-ac8b-fd4ca2621ffb",
"files": [],
"subMetas": {},
"userData": {}
}