From 89825444e17d9fe2a704bf75a816c36e6f0468f7 Mon Sep 17 00:00:00 2001 From: Lean Mendoza Date: Wed, 20 Sep 2023 12:08:41 -0300 Subject: [PATCH 1/5] wip --- packages/@dcl/ecs/src/engine/component.ts | 10 + ...row-only-value-set-component-definition.ts | 9 + .../lww-element-set-component-definition.ts | 25 +- packages/@dcl/sdk-commands/package-lock.json | 10 +- packages/@dcl/sdk/src/observables.ts | 434 ++++-------------- 5 files changed, 138 insertions(+), 350 deletions(-) diff --git a/packages/@dcl/ecs/src/engine/component.ts b/packages/@dcl/ecs/src/engine/component.ts index 3e13b637a..423bb7c76 100644 --- a/packages/@dcl/ecs/src/engine/component.ts +++ b/packages/@dcl/ecs/src/engine/component.ts @@ -169,6 +169,11 @@ export interface LastWriteWinElementSetComponentDefinition extends BaseCompon * @param val - The initial value if it doesn't exist */ getOrCreateMutable(entity: Entity, initialValue?: T): T + + /** + * @internal + */ + updatedFromCrdtIterator(): Iterable } /** * @public @@ -199,6 +204,11 @@ export interface GrowOnlyValueSetComponentDefinition extends BaseComponent * @returns */ get(entity: Entity): DeepReadonlySet + + /** + * @internal + */ + updatedFromCrdtIterator(): Iterable<[Entity, number]> } /** diff --git a/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts b/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts index ffb5916d4..10df16fc3 100644 --- a/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts +++ b/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts @@ -48,6 +48,7 @@ export function createValueSetComponentDefinitionFromSchema( } const data = new Map() const dirtyIterator = new Set() + const updatedFromCrdtIterator = new Map() const queuedCommands: AppendValueMessageBody[] = [] // only sort the array if the latest (N) element has a timestamp <= N-1 @@ -148,12 +149,15 @@ export function createValueSetComponentDefinitionFromSchema( getCrdtUpdates() { // return a copy of the commands, and then clear the local copy dirtyIterator.clear() + updatedFromCrdtIterator.clear() return queuedCommands.splice(0, queuedCommands.length) }, updateFromCrdt(_body) { if (_body.type === CrdtMessageType.APPEND_VALUE) { const buf = new ReadWriteByteBuffer(_body.data) append(_body.entityId, schema.deserialize(buf) as DeepReadonly) + + updatedFromCrdtIterator.set(_body.entityId, (updatedFromCrdtIterator.get(_body.entityId) || 0) + 1) } return [null, undefined] }, @@ -166,6 +170,11 @@ export function createValueSetComponentDefinitionFromSchema( AppendValueOperation.write(entity, 0, componentId, buf.toBinary(), buffer) } } + }, + *updatedFromCrdtIterator(): Iterable<[Entity, number]> { + for (const [entity, newOnesCount] of updatedFromCrdtIterator) { + yield [entity, newOnesCount] + } } } diff --git a/packages/@dcl/ecs/src/engine/lww-element-set-component-definition.ts b/packages/@dcl/ecs/src/engine/lww-element-set-component-definition.ts index 983a803d1..a1438186f 100644 --- a/packages/@dcl/ecs/src/engine/lww-element-set-component-definition.ts +++ b/packages/@dcl/ecs/src/engine/lww-element-set-component-definition.ts @@ -51,7 +51,8 @@ export function createUpdateLwwFromCrdt( componentId: number, timestamps: Map, schema: Pick, 'serialize' | 'deserialize'>, - data: Map + data: Map, + updatedFromCrdtIterator: Set ) { /** * Process the received message only if the lamport number recieved is higher @@ -126,6 +127,7 @@ export function createUpdateLwwFromCrdt( } else { data.delete(entity) } + updatedFromCrdtIterator.add(entity) return [null, data.get(entity)] } @@ -168,7 +170,8 @@ export function createGetCrdtMessagesForLww( timestamps: Map, dirtyIterator: Set, schema: Pick, 'serialize'>, - data: Map + data: Map, + updatedFromCrdtIterator: Set ) { return function* () { for (const entity of dirtyIterator) { @@ -198,6 +201,7 @@ export function createGetCrdtMessagesForLww( } } dirtyIterator.clear() + updatedFromCrdtIterator.clear() } } @@ -211,6 +215,7 @@ export function createComponentDefinitionFromSchema( ): LastWriteWinElementSetComponentDefinition { const data = new Map() const dirtyIterator = new Set() + const updatedFromCrdtIterator = new Set() const timestamps = new Map() return { @@ -303,8 +308,20 @@ export function createComponentDefinitionFromSchema( yield entity } }, - getCrdtUpdates: createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data), - updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data), + *updatedFromCrdtIterator(): Iterable { + for (const entity of updatedFromCrdtIterator) { + yield entity + } + }, + getCrdtUpdates: createGetCrdtMessagesForLww( + componentId, + timestamps, + dirtyIterator, + schema, + data, + updatedFromCrdtIterator + ), + updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data, updatedFromCrdtIterator), dumpCrdtStateToBuffer: createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, data) } } diff --git a/packages/@dcl/sdk-commands/package-lock.json b/packages/@dcl/sdk-commands/package-lock.json index 6ec34e060..6fe98eb36 100644 --- a/packages/@dcl/sdk-commands/package-lock.json +++ b/packages/@dcl/sdk-commands/package-lock.json @@ -59,16 +59,13 @@ }, "../inspector": { "version": "0.1.0", - "dependencies": { - "earcut": "^2.2.4" - }, "devDependencies": { "@babylonjs/core": "^6.18.0", "@babylonjs/gui": "^6.18.0", "@babylonjs/inspector": "^6.18.0", "@babylonjs/loaders": "^6.18.0", "@babylonjs/materials": "^6.18.0", - "@dcl/asset-packs": "^0.0.0-20230913161419.commit-562cd5d", + "@dcl/asset-packs": "^0.0.0-20230915180527.commit-250509a", "@dcl/ecs": "file:../ecs", "@dcl/ecs-math": "2.0.2", "@dcl/mini-rpc": "^1.0.7", @@ -76,7 +73,6 @@ "@dcl/schemas": "^8.2.3-20230718182824.commit-356025c", "@reduxjs/toolkit": "^1.9.5", "@testing-library/react": "^14.0.0", - "@types/earcut": "^2.1.1", "@types/jest-environment-puppeteer": "^5.0.3", "@types/node": "^18.11.18", "@types/node-fetch": "^2.6.4", @@ -2840,7 +2836,7 @@ "@babylonjs/inspector": "^6.18.0", "@babylonjs/loaders": "^6.18.0", "@babylonjs/materials": "^6.18.0", - "@dcl/asset-packs": "^0.0.0-20230913161419.commit-562cd5d", + "@dcl/asset-packs": "^0.0.0-20230915180527.commit-250509a", "@dcl/ecs": "file:../ecs", "@dcl/ecs-math": "2.0.2", "@dcl/mini-rpc": "^1.0.7", @@ -2848,7 +2844,6 @@ "@dcl/schemas": "^8.2.3-20230718182824.commit-356025c", "@reduxjs/toolkit": "^1.9.5", "@testing-library/react": "^14.0.0", - "@types/earcut": "^2.1.1", "@types/jest-environment-puppeteer": "^5.0.3", "@types/node": "^18.11.18", "@types/node-fetch": "^2.6.4", @@ -2861,7 +2856,6 @@ "classnames": "^2.3.2", "decentraland-ui": "^4.10.0", "dotenv": "^16.3.1", - "earcut": "^2.2.4", "esbuild": "^0.18.17", "fp-future": "^1.0.1", "jest-environment-jsdom": "^29.5.0", diff --git a/packages/@dcl/sdk/src/observables.ts b/packages/@dcl/sdk/src/observables.ts index 0033f1ef8..bf5fad6a5 100644 --- a/packages/@dcl/sdk/src/observables.ts +++ b/packages/@dcl/sdk/src/observables.ts @@ -1,257 +1,30 @@ import { Observable } from './internal/Observable' -import { QuaternionType, Vector3Type } from '@dcl/ecs' +import { Vector3Type, engine } from '@dcl/ecs' import { ManyEntityAction, SendBatchResponse, subscribe } from '~system/EngineApi' let subscribeFunction: typeof subscribe = subscribe -/** @public */ -export type InputEventResult = { - /** Origin of the ray, relative to the scene */ - origin: Vector3Type - /** Direction vector of the ray (normalized) */ - direction: Vector3Type - /** ID of the pointer that triggered the event */ - buttonId: number - /** Does this pointer event hit any object? */ - hit?: { - /** Length of the ray */ - length: number - /** If the ray hits a mesh the intersection point will be this */ - hitPoint: Vector3Type - /** If the mesh has a name, it will be assigned to meshName */ - meshName: string - /** Normal of the hit */ - normal: Vector3Type - /** Normal of the hit, in world space */ - worldNormal: Vector3Type - /** Hit entity ID if any */ - entityId: unknown +const wrappedSubscribeFunction = instanceSubscriberFunction() +function createSubscriber(eventName: string) { + return () => { + wrappedSubscribeFunction(eventName) } } -/** @public */ -export type GlobalInputEventResult = InputEventResult & { - /** - * DOWN = 0, - * UP = 1 - */ - type: 0 | 1 -} - -/** @public */ -export type RaycastResponsePayload = { - queryId: string - queryType: string - payload: T -} - -/** @public */ -export type GizmoDragEndEvent = { - type: 'gizmoDragEnded' - transforms: Array<{ - position: Vector3Type - rotation: QuaternionType - scale: Vector3Type - entityId: unknown - }> -} - -/** @public */ -export type GizmoSelectedEvent = { - type: 'gizmoSelected' - gizmoType: 'MOVE' | 'ROTATE' | 'SCALE' | 'NONE' - entities: string[] -} - /// --- EVENTS --- /** @public */ export type IEventNames = keyof IEvents -/** @public */ -export type EngineEvent = { - /** eventName */ - type: T - data: Readonly -} - /** * @public * Note: Don't use `on` prefix for IEvents to avoid redundancy with `event.on("onEventName")` syntax. */ export interface IEvents { - /** - * `positionChanged` is triggered when the position of the camera changes - * This event is throttled to 10 times per second. - */ - positionChanged: { - /** Camera position relative to the base parcel of the scene */ - position: Vector3Type - - /** Camera position, this is a absolute world position */ - cameraPosition: Vector3Type - - /** Eye height, in meters. */ - playerHeight: number - } - - /** - * `rotationChanged` is triggered when the rotation of the camera changes. - * This event is throttled to 10 times per second. - */ - rotationChanged: { - /** Degree vector. Same as entities */ - rotation: Vector3Type - /** Rotation quaternion, useful in some scenarios. */ - quaternion: QuaternionType - } - - /** - * `cameraModeChanged` is triggered when the user changes the camera mode - */ - cameraModeChanged: { - /** - * FIRST_PERSON = 0, - * THIRD_PERSON = 1, - * FREE_CAMERA = 2 - */ - cameraMode: 0 | 1 | 2 - } - - /** - * `idleStateChanged` is triggered when the user not moves for a defined period of time - */ - idleStateChanged: { - isIdle: boolean - } - playerExpression: { expressionId: string } - /** - * `pointerUp` is triggered when the user releases an input pointer. - * It could be a VR controller, a touch screen or the mouse. - */ - pointerUp: InputEventResult - - /** - * `pointerDown` is triggered when the user press an input pointer. - * It could be a VR controller, a touch screen or the mouse. - */ - pointerDown: InputEventResult - - /** - * `pointerEvent` is triggered when the user press or releases an input pointer. - * It could be a VR controller, a touch screen or the mouse. - * - * @deprecated use actionButtonEvent instead - */ - pointerEvent: GlobalInputEventResult - - /** - * `actionButtonEvent` is triggered when the user press or releases an input pointer. - * It could be a VR controller, a touch screen or the mouse. - * - * This event is exactly the same as `pointerEvent` but the logic in the ECS had an unsolvable - * condition that required us to create this new event to handle more cases for new buttons. - */ - actionButtonEvent: GlobalInputEventResult - - /** - * `raycastResponse` is triggered in response to a raycast query - */ - raycastResponse: RaycastResponsePayload - - /** - * `chatMessage` is triggered when the user sends a message through chat entity. - */ - chatMessage: { - id: string - sender: string - message: string - isCommand: boolean - } - - /** - * `onChange` is triggered when an entity changes its own internal state. - * Dispatched by the `ui-*` entities when their value is changed. It triggers a callback. - * Notice: Only entities with ID will be listening for click events. - */ - onChange: { - value?: any - /** ID of the pointer that triggered the event */ - pointerId?: number - } - - /** - * `onEnter` is triggered when the user hits the "Enter" key from the keyboard - * Used principally by the Chat internal scene - */ - onEnter: unknown - - /** - * `onPointerLock` is triggered when the user clicks the world canvas and the - * pointer locks to it so the pointer moves the camera - */ - onPointerLock: { - locked?: boolean - } - - /** - * `onAnimationEnd` is triggered when an animation clip gets finish - */ - onAnimationEnd: { - clipName: string - } - - /** - * `onFocus` is triggered when an entity focus is active. - * Dispatched by the `ui-input` and `ui-password` entities when the value is changed. - * It triggers a callback. - * - * Notice: Only entities with ID will be listening for click events. - */ - onFocus: { - /** ID of the entitiy of the event */ - entityId: unknown - /** ID of the pointer that triggered the event */ - pointerId: number - } - - /** - * `onBlur` is triggered when an entity loses its focus. - * Dispatched by the `ui-input` and `ui-password` entities when the value is changed. - * It triggers a callback. - * - * Notice: Only entities with ID will be listening for click events. - */ - onBlur: { - /** ID of the entitiy of the event */ - entityId: unknown - /** ID of the pointer that triggered the event */ - pointerId: number - } - - /** The onClick event is only used for UI elements */ - onClick: { - entityId: unknown - } - - /** - * This event gets triggered when an entity leaves the scene fences. - */ - entityOutOfScene: { - entityId: unknown - } - - /** - * This event gets triggered when an entity enters the scene fences. - */ - entityBackInScene: { - entityId: unknown - } - /** * This event gets triggered when the user enters the scene */ @@ -274,73 +47,6 @@ export interface IEvents { message: string } - /** - * This is triggered once the scene should start. - */ - sceneStart: unknown - - /** - * This is triggered once the builder scene is loaded. - */ - builderSceneStart: unknown - - /** - * This is triggered once the builder scene is unloaded. - */ - builderSceneUnloaded: unknown - - /** - * After checking entities outside the fences, if any is outside, this event - * will be triggered with all the entities outside the scene. - */ - entitiesOutOfBoundaries: { - entities: string[] - } - - uuidEvent: { - uuid: string - payload: any - } - - onTextSubmit: { - text: string - } - - metricsUpdate: { - given: Record - limit: Record - } - - limitsExceeded: { - given: Record - limit: Record - } - - /** For gizmos */ - gizmoEvent: GizmoDragEndEvent | GizmoSelectedEvent - - externalAction: { - type: string - [key: string]: any - } - - stateEvent: { - type: string - payload: any - } - - /** This is triggered at least for each videoStatus change */ - videoEvent: { - componentId: string - videoClipId: string - /** Status, can be NONE = 0, ERROR = 1, LOADING = 2, READY = 3, PLAYING = 4,BUFFERING = 5 */ - videoStatus: number - /** Current offset position in seconds */ - currentOffset: number - /** Video length in seconds. Can be -1 */ - totalVideoLength: number - } - /** This is trigger everytime a profile is changed */ profileChanged: { ethAddress: string @@ -374,23 +80,6 @@ export interface IEvents { distance: number } } - - /** Triggered when pointer start hovering an entities' shape */ - pointerHoverEnter: unknown - - /** Triggered when pointer stop hovering an entities' shape */ - pointerHoverExit: unknown -} - -/** - * @internal - * This function generates a callback that is passed to the Observable - * constructor to subscribe to the events of the DecentralandInterface - */ -function createSubscriber(eventName: string) { - return () => { - subscribeFunction({ eventId: eventName }).catch(console.error) - } } /** @@ -416,13 +105,6 @@ export const onLeaveSceneObservable = new Observable(cr * @deprecated This function is an inheritance of ECS6, it's here temporary for the feature parity, please read the news and docs to know how handle when it's removed. Use onLeaveSceneObservable instead. */ export const onLeaveScene = onLeaveSceneObservable -/** - * This event is triggered after all the resources of the scene were loaded (models, textures, etc...) - * @public - * @deprecated This function is an inheritance of ECS6, it's here temporary for the feature parity, please read the news and docs to know how handle when it's removed. - */ -export const onSceneReadyObservable = new Observable(createSubscriber('sceneStart')) - /** * @public * @deprecated This function is an inheritance of ECS6, it's here temporary for the feature parity, please read the news and docs to know how handle when it's removed. @@ -431,12 +113,6 @@ export const onPlayerExpressionObservable = new Observable(createSubscriber('videoEvent')) - /** * @public * @deprecated This function is an inheritance of ECS6, it's here temporary for the feature parity, please read the news and docs to know how handle when it's removed. @@ -504,19 +180,10 @@ export async function pollEvents(sendBatch: (body: ManyEntityAction) => Promise< onLeaveSceneObservable.notifyObservers(data as IEvents['onLeaveScene']) break } - case 'sceneStart': { - onSceneReadyObservable.notifyObservers(data as IEvents['sceneStart']) - break - } case 'playerExpression': { onPlayerExpressionObservable.notifyObservers(data as IEvents['playerExpression']) break } - case 'videoEvent': { - const videoData = data as IEvents['videoEvent'] - onVideoEvent.notifyObservers(videoData) - break - } case 'profileChanged': { onProfileChanged.notifyObservers(data as IEvents['profileChanged']) break @@ -545,3 +212,94 @@ export async function pollEvents(sendBatch: (body: ManyEntityAction) => Promise< } } } + +/** + * @internal + * + * @returns the subscriber function + */ +function createSdk6FallbackSubscriber() { + return (eventName: string) => { + subscribeFunction({ eventId: eventName }).catch(console.error) + } +} + +/** + * @internal + * + * @returns the subscriber function + */ +function createSdk7Subscriber() { + let systemEnabled = false + const enableProcessing: Record = { + onEnterScene: false, + onLeaveScene: false, + playerExpression: false, + profileChanged: false, + playerConnected: false, + playerDisconnected: false, + onRealmChanged: false, + playerClicked: false, + comms: false + } + + function processLeaveEnterScene(dt: number) { + PlayerIdentityData + } + + function system(dt: number) { + // Quick exit if observables aren't being used at all + if (!systemEnabled) return + + if (enableProcessing.onEnterScene || enableProcessing.onLeaveScene) { + processLeaveEnterScene(dt) + } + } + + engine.addSystem(system, Number.MAX_VALUE) + + return (eventName: string) => { + // If is a valid event name and hasn't been enabled yet + if (eventName in enableProcessing && !enableProcessing[eventName as IEventNames]) { + systemEnabled = true + + enableProcessing[eventName as IEventNames] = true + switch (eventName) { + case 'onEnterScene': + break + case 'onLeaveScene': + break + case 'playerExpression': + break + case 'profileChanged': + break + case 'playerConnected': + break + case 'playerDisconnected': + break + case 'onRealmChanged': + break + case 'playerClicked': + break + case 'comms': + break + } + } + } +} + +/** + * @internal + */ +function instanceSubscriberFunction() { + const FORCE_SDK6_SUBSCRIBER = true + + // __SDK6_FALLBACK_SUPPORT should be exposed in the runtime + const shouldFallbackSdk6 = FORCE_SDK6_SUBSCRIBER || (globalThis as any).__SDK6_FALLBACK_SUPPORT + + if (shouldFallbackSdk6) { + return createSdk6FallbackSubscriber() + } else { + return createSdk7Subscriber() + } +} From db5e323982d77a00de8f3bbe73c3eb4080a48bac Mon Sep 17 00:00:00 2001 From: Lean Mendoza Date: Wed, 20 Sep 2023 16:32:33 -0300 Subject: [PATCH 2/5] wip --- packages/@dcl/ecs/src/engine/component.ts | 6 +- ...row-only-value-set-component-definition.ts | 6 +- .../lww-element-set-component-definition.ts | 6 +- .../etc/playground-assets.api.md | 304 ++++++------------ packages/@dcl/sdk/src/observables.ts | 11 +- scripts/protocol-buffer-generation/index.ts | 6 +- 6 files changed, 117 insertions(+), 222 deletions(-) diff --git a/packages/@dcl/ecs/src/engine/component.ts b/packages/@dcl/ecs/src/engine/component.ts index 423bb7c76..670e0b74c 100644 --- a/packages/@dcl/ecs/src/engine/component.ts +++ b/packages/@dcl/ecs/src/engine/component.ts @@ -172,8 +172,9 @@ export interface LastWriteWinElementSetComponentDefinition extends BaseCompon /** * @internal + * @returns a set with entities changed */ - updatedFromCrdtIterator(): Iterable + getEntitiesUpdatedFromCrdt(): Set } /** * @public @@ -207,8 +208,9 @@ export interface GrowOnlyValueSetComponentDefinition extends BaseComponent /** * @internal + * @returns a map with entities as key and how many values was appended to the set as value */ - updatedFromCrdtIterator(): Iterable<[Entity, number]> + getEntitiesUpdatedFromCrdt(): Map } /** diff --git a/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts b/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts index 10df16fc3..06916b903 100644 --- a/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts +++ b/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts @@ -171,10 +171,8 @@ export function createValueSetComponentDefinitionFromSchema( } } }, - *updatedFromCrdtIterator(): Iterable<[Entity, number]> { - for (const [entity, newOnesCount] of updatedFromCrdtIterator) { - yield [entity, newOnesCount] - } + getEntitiesUpdatedFromCrdt(): Map { + return updatedFromCrdtIterator } } diff --git a/packages/@dcl/ecs/src/engine/lww-element-set-component-definition.ts b/packages/@dcl/ecs/src/engine/lww-element-set-component-definition.ts index a1438186f..5d4e89ef3 100644 --- a/packages/@dcl/ecs/src/engine/lww-element-set-component-definition.ts +++ b/packages/@dcl/ecs/src/engine/lww-element-set-component-definition.ts @@ -308,10 +308,8 @@ export function createComponentDefinitionFromSchema( yield entity } }, - *updatedFromCrdtIterator(): Iterable { - for (const entity of updatedFromCrdtIterator) { - yield entity - } + getEntitiesUpdatedFromCrdt(): Set { + return updatedFromCrdtIterator }, getCrdtUpdates: createGetCrdtMessagesForLww( componentId, diff --git a/packages/@dcl/playground-assets/etc/playground-assets.api.md b/packages/@dcl/playground-assets/etc/playground-assets.api.md index d2bd85cd4..90af0e9d4 100644 --- a/packages/@dcl/playground-assets/etc/playground-assets.api.md +++ b/packages/@dcl/playground-assets/etc/playground-assets.api.md @@ -71,6 +71,15 @@ export const enum AvatarAnchorPointType { // @public (undocumented) export const AvatarAttach: LastWriteWinElementSetComponentDefinition; +// @public (undocumented) +export const AvatarBase: LastWriteWinElementSetComponentDefinition; + +// @public (undocumented) +export const AvatarEmoteCommand: LastWriteWinElementSetComponentDefinition; + +// @public (undocumented) +export const AvatarEquippedData: LastWriteWinElementSetComponentDefinition; + // @public (undocumented) export const AvatarModifierArea: LastWriteWinElementSetComponentDefinition; @@ -514,6 +523,9 @@ export const componentDefinitionByName: { "core::AudioSource": LwwComponentGetter>; "core::AudioStream": LwwComponentGetter>; "core::AvatarAttach": LwwComponentGetter>; + "core::AvatarBase": LwwComponentGetter>; + "core::AvatarEmoteCommand": LwwComponentGetter>; + "core::AvatarEquippedData": LwwComponentGetter>; "core::AvatarModifierArea": LwwComponentGetter>; "core::AvatarShape": LwwComponentGetter>; "core::Billboard": LwwComponentGetter>; @@ -526,6 +538,7 @@ export const componentDefinitionByName: { "core::MeshCollider": LwwComponentGetter>; "core::MeshRenderer": LwwComponentGetter>; "core::NftShape": LwwComponentGetter>; + "core::PlayerIdentityData": LwwComponentGetter>; "core::PointerEvents": LwwComponentGetter>; "core::PointerEventsResult": GSetComponentGetter>; "core::PointerLock": LwwComponentGetter>; @@ -819,14 +832,6 @@ export function Engine(options?: IEngineOptions): IEngine; // @public export const engine: IEngine; -// Warning: (ae-missing-release-tag) "EngineEvent" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type EngineEvent = { - type: T; - data: Readonly; -}; - // @public (undocumented) export const EngineInfo: LastWriteWinElementSetComponentDefinition; @@ -951,28 +956,6 @@ export function getComponentEntityTree(engine: Pick; -// Warning: (ae-missing-release-tag) "GizmoDragEndEvent" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type GizmoDragEndEvent = { - type: 'gizmoDragEnded'; - transforms: Array<{ - position: Vector3Type; - rotation: QuaternionType; - scale: Vector3Type; - entityId: unknown; - }>; -}; - -// Warning: (ae-missing-release-tag) "GizmoSelectedEvent" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type GizmoSelectedEvent = { - type: 'gizmoSelected'; - gizmoType: 'MOVE' | 'ROTATE' | 'SCALE' | 'NONE'; - entities: string[]; -}; - // Warning: (ae-missing-release-tag) "GlobalDirectionRaycastOptions" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -985,13 +968,6 @@ export type GlobalDirectionRaycastSystemOptions = { direction?: PBVector3; }; -// Warning: (ae-missing-release-tag) "GlobalInputEventResult" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type GlobalInputEventResult = InputEventResult & { - type: 0 | 1; -}; - // Warning: (ae-missing-release-tag) "GlobalTargetRaycastOptions" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -1074,99 +1050,20 @@ export type IEventNames = keyof IEvents; // // @public (undocumented) export interface IEvents { - // (undocumented) - actionButtonEvent: GlobalInputEventResult; - // (undocumented) - builderSceneStart: unknown; - // (undocumented) - builderSceneUnloaded: unknown; - // (undocumented) - cameraModeChanged: { - cameraMode: 0 | 1 | 2; - }; - // (undocumented) - chatMessage: { - id: string; - sender: string; - message: string; - isCommand: boolean; - }; // (undocumented) comms: { sender: string; message: string; }; // (undocumented) - entitiesOutOfBoundaries: { - entities: string[]; - }; - // (undocumented) - entityBackInScene: { - entityId: unknown; - }; - // (undocumented) - entityOutOfScene: { - entityId: unknown; - }; - // (undocumented) - externalAction: { - type: string; - [key: string]: any; - }; - // (undocumented) - gizmoEvent: GizmoDragEndEvent | GizmoSelectedEvent; - // (undocumented) - idleStateChanged: { - isIdle: boolean; - }; - // (undocumented) - limitsExceeded: { - given: Record; - limit: Record; - }; - // (undocumented) - metricsUpdate: { - given: Record; - limit: Record; - }; - // (undocumented) - onAnimationEnd: { - clipName: string; - }; - // (undocumented) - onBlur: { - entityId: unknown; - pointerId: number; - }; - // (undocumented) - onChange: { - value?: any; - pointerId?: number; - }; - // (undocumented) - onClick: { - entityId: unknown; - }; - // (undocumented) - onEnter: unknown; - // (undocumented) onEnterScene: { userId: string; }; // (undocumented) - onFocus: { - entityId: unknown; - pointerId: number; - }; - // (undocumented) onLeaveScene: { userId: string; }; // (undocumented) - onPointerLock: { - locked?: boolean; - }; - // (undocumented) onRealmChanged: { domain: string; room: string; @@ -1174,10 +1071,6 @@ export interface IEvents { displayName: string; }; // (undocumented) - onTextSubmit: { - text: string; - }; - // (undocumented) playerClicked: { userId: string; ray: { @@ -1199,53 +1092,10 @@ export interface IEvents { expressionId: string; }; // (undocumented) - pointerDown: InputEventResult; - // (undocumented) - pointerEvent: GlobalInputEventResult; - // (undocumented) - pointerHoverEnter: unknown; - // (undocumented) - pointerHoverExit: unknown; - // (undocumented) - pointerUp: InputEventResult; - // (undocumented) - positionChanged: { - position: Vector3Type; - cameraPosition: Vector3Type; - playerHeight: number; - }; - // (undocumented) profileChanged: { ethAddress: string; version: number; }; - // (undocumented) - raycastResponse: RaycastResponsePayload; - // (undocumented) - rotationChanged: { - rotation: Vector3Type; - quaternion: QuaternionType; - }; - // (undocumented) - sceneStart: unknown; - // (undocumented) - stateEvent: { - type: string; - payload: any; - }; - // (undocumented) - uuidEvent: { - uuid: string; - payload: any; - }; - // (undocumented) - videoEvent: { - componentId: string; - videoClipId: string; - videoStatus: number; - currentOffset: number; - totalVideoLength: number; - }; } // @public (undocumented) @@ -1314,23 +1164,6 @@ export const enum InputAction { IA_WALK = 9 } -// Warning: (ae-missing-release-tag) "InputEventResult" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type InputEventResult = { - origin: Vector3Type; - direction: Vector3Type; - buttonId: number; - hit?: { - length: number; - hitPoint: Vector3Type; - meshName: string; - normal: Vector3Type; - worldNormal: Vector3Type; - entityId: unknown; - }; -}; - // @public export const inputSystem: IInputSystem; @@ -1919,27 +1752,11 @@ export const onRealmChangedObservable: Observable<{ displayName: string; }>; -// Warning: (ae-missing-release-tag) "onSceneReadyObservable" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export const onSceneReadyObservable: Observable; - // Warning: (ae-missing-release-tag) "onUpdate" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) export function onUpdate(deltaTime: number): Promise; -// Warning: (ae-missing-release-tag) "onVideoEvent" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export const onVideoEvent: Observable<{ - componentId: string; - videoClipId: string; - videoStatus: number; - currentOffset: number; - totalVideoLength: number; -}>; - // @public export type OverflowType = 'hidden' | 'scroll' | 'visible'; @@ -2021,6 +1838,74 @@ export namespace PBAvatarAttach { export function encode(message: PBAvatarAttach, writer?: _m0.Writer): _m0.Writer; } +// @public (undocumented) +export interface PBAvatarBase { + // (undocumented) + bodyShapeUrn: string; + // (undocumented) + eyesColor: PBColor3 | undefined; + // (undocumented) + hairColor: PBColor3 | undefined; + // (undocumented) + name: string; + // (undocumented) + skinColor: PBColor3 | undefined; +} + +// @public (undocumented) +export namespace PBAvatarBase { + // (undocumented) + export function decode(input: _m0.Reader | Uint8Array, length?: number): PBAvatarBase; + // (undocumented) + export function encode(message: PBAvatarBase, writer?: _m0.Writer): _m0.Writer; +} + +// @public (undocumented) +export interface PBAvatarEmoteCommand { + // (undocumented) + emoteCommand: PBAvatarEmoteCommand_EmoteCommand | undefined; +} + +// @public (undocumented) +export namespace PBAvatarEmoteCommand { + // (undocumented) + export function decode(input: _m0.Reader | Uint8Array, length?: number): PBAvatarEmoteCommand; + // (undocumented) + export function encode(message: PBAvatarEmoteCommand, writer?: _m0.Writer): _m0.Writer; +} + +// @public (undocumented) +export interface PBAvatarEmoteCommand_EmoteCommand { + // (undocumented) + emoteUrn: string; + // (undocumented) + loop: boolean; +} + +// @public (undocumented) +export namespace PBAvatarEmoteCommand_EmoteCommand { + // (undocumented) + export function decode(input: _m0.Reader | Uint8Array, length?: number): PBAvatarEmoteCommand_EmoteCommand; + // (undocumented) + export function encode(message: PBAvatarEmoteCommand_EmoteCommand, writer?: _m0.Writer): _m0.Writer; +} + +// @public (undocumented) +export interface PBAvatarEquippedData { + // (undocumented) + emotesUrns: string[]; + // (undocumented) + wearableUrns: string[]; +} + +// @public (undocumented) +export namespace PBAvatarEquippedData { + // (undocumented) + export function decode(input: _m0.Reader | Uint8Array, length?: number): PBAvatarEquippedData; + // (undocumented) + export function encode(message: PBAvatarEquippedData, writer?: _m0.Writer): _m0.Writer; +} + // @public (undocumented) export interface PBAvatarModifierArea { area: PBVector3 | undefined; @@ -2414,6 +2299,21 @@ export namespace PBNftShape { export function encode(message: PBNftShape, writer?: _m0.Writer): _m0.Writer; } +// @public (undocumented) +export interface PBPlayerIdentityData { + address: string; + // (undocumented) + isGuest: boolean; +} + +// @public (undocumented) +export namespace PBPlayerIdentityData { + // (undocumented) + export function decode(input: _m0.Reader | Uint8Array, length?: number): PBPlayerIdentityData; + // (undocumented) + export function encode(message: PBPlayerIdentityData, writer?: _m0.Writer): _m0.Writer; +} + // @public (undocumented) export interface PBPointerEvents { pointerEvents: PBPointerEvents_Entry[]; @@ -2922,6 +2822,9 @@ export namespace Plane { export function transform(plane: ReadonlyPlane, transformation: Matrix.ReadonlyMatrix): MutablePlane; } +// @public (undocumented) +export const PlayerIdentityData: LastWriteWinElementSetComponentDefinition; + // @public (undocumented) export const PointerEvents: LastWriteWinElementSetComponentDefinition; @@ -3126,15 +3029,6 @@ export const enum RaycastQueryType { RQT_QUERY_ALL = 1 } -// Warning: (ae-missing-release-tag) "RaycastResponsePayload" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type RaycastResponsePayload = { - queryId: string; - queryType: string; - payload: T; -}; - // @public (undocumented) export const RaycastResult: LastWriteWinElementSetComponentDefinition; diff --git a/packages/@dcl/sdk/src/observables.ts b/packages/@dcl/sdk/src/observables.ts index bf5fad6a5..5136b225c 100644 --- a/packages/@dcl/sdk/src/observables.ts +++ b/packages/@dcl/sdk/src/observables.ts @@ -1,5 +1,5 @@ import { Observable } from './internal/Observable' -import { Vector3Type, engine } from '@dcl/ecs' +import { Vector3Type, engine, PlayerIdentityData, Transform } from '@dcl/ecs' import { ManyEntityAction, SendBatchResponse, subscribe } from '~system/EngineApi' let subscribeFunction: typeof subscribe = subscribe @@ -244,7 +244,14 @@ function createSdk7Subscriber() { } function processLeaveEnterScene(dt: number) { - PlayerIdentityData + // const transformUpdated = (Transform as any).getEntitiesChangedFromCrdt() + // for (const [entityId, data] of engine.getEntitiesWith(PlayerIdentityData)) { + // if (transformUpdated.has(entityId)) { + // if (Transform.getOrNull(entityId) === null) { + // } else { + // } + // } + // } } function system(dt: number) { diff --git a/scripts/protocol-buffer-generation/index.ts b/scripts/protocol-buffer-generation/index.ts index 176dbba21..6bdb6b437 100644 --- a/scripts/protocol-buffer-generation/index.ts +++ b/scripts/protocol-buffer-generation/index.ts @@ -10,11 +10,7 @@ import fs from 'fs-extra' import { FileDescriptorStandardOption, runCommand } from '../utils/shellCommand' import { PROTO_COMPILER_PATH, TS_PROTO_PLUGIN_PATH } from './protoConst' -const AVATAR_BASE = 1087 -const AVATAR_EMOTE_COMMAND = 1088 -const PLAYER_IDENTITY_DATA = 1089 -const AVATAR_EQUIPPED_DATA = 1091 -const NON_EXPOSED_LIST: number[] = [AVATAR_BASE, AVATAR_EMOTE_COMMAND, AVATAR_EQUIPPED_DATA, PLAYER_IDENTITY_DATA] +const NON_EXPOSED_LIST: number[] = [] /** * @param componentPath - Argument of execution '--component-path' From b95f37a16ec85931c2d71d0a5f1a2d885474fc3b Mon Sep 17 00:00:00 2001 From: Lean Mendoza Date: Thu, 21 Sep 2023 01:03:44 -0300 Subject: [PATCH 3/5] emote command grow only set --- packages/@dcl/ecs/src/engine/component.ts | 2 +- ...row-only-value-set-component-definition.ts | 12 +++++----- .../etc/playground-assets.api.md | 8 +++---- .../generateIndex.ts | 24 ++++++++++++------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/packages/@dcl/ecs/src/engine/component.ts b/packages/@dcl/ecs/src/engine/component.ts index 670e0b74c..ca59c2c9b 100644 --- a/packages/@dcl/ecs/src/engine/component.ts +++ b/packages/@dcl/ecs/src/engine/component.ts @@ -196,7 +196,7 @@ export interface GrowOnlyValueSetComponentDefinition extends BaseComponent * @param val - The final value. The Set will freeze the value, it won't be editable from * the script. */ - addValue(entity: Entity, val: DeepReadonly): DeepReadonlySet + addValue(entity: Entity, val: DeepReadonly, ts: number): DeepReadonlySet /** * Get the readonly component of the entity (to mutate it, use getMutable instead), diff --git a/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts b/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts index 06916b903..be2cf381e 100644 --- a/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts +++ b/packages/@dcl/ecs/src/engine/grow-only-value-set-component-definition.ts @@ -28,7 +28,7 @@ function sortByTimestamp(a: { timestamp: number }, b: { timestamp: number }) { */ export type ValueSetOptions = { // function that returns a timestamp from the value - timestampFunction: (value: DeepReadonly) => number + timestampFunction?: (value: DeepReadonly) => number // max elements to store in memory, ordered by timestamp maxElements: number } @@ -79,14 +79,14 @@ export function createValueSetComponentDefinitionFromSchema( } } - function append(entity: Entity, value: DeepReadonly) { + function append(entity: Entity, value: DeepReadonly, ts: number) { let row = data.get(entity) if (!row) { row = { raw: [], frozenSet: emptyReadonlySet as any } data.set(entity, row) } const usedValue = schema.extend ? (schema.extend(value) as DeepReadonly) : value - const timestamp = options.timestampFunction(usedValue as any) + const timestamp = options.timestampFunction ? options.timestampFunction(usedValue as any) : ts if (__DEV__) { // only freeze the objects in dev mode to warn the developers because // it is an expensive operation @@ -122,8 +122,8 @@ export function createValueSetComponentDefinitionFromSchema( return emptyReadonlySet as any } }, - addValue(entity: Entity, rawValue: DeepReadonly) { - const { set, value } = append(entity, rawValue) + addValue(entity: Entity, rawValue: DeepReadonly, ts: number) { + const { set, value } = append(entity, rawValue, ts) dirtyIterator.add(entity) const buf = new ReadWriteByteBuffer() schema.serialize(value, buf) @@ -155,7 +155,7 @@ export function createValueSetComponentDefinitionFromSchema( updateFromCrdt(_body) { if (_body.type === CrdtMessageType.APPEND_VALUE) { const buf = new ReadWriteByteBuffer(_body.data) - append(_body.entityId, schema.deserialize(buf) as DeepReadonly) + append(_body.entityId, schema.deserialize(buf) as DeepReadonly, _body.timestamp) updatedFromCrdtIterator.set(_body.entityId, (updatedFromCrdtIterator.get(_body.entityId) || 0) + 1) } diff --git a/packages/@dcl/playground-assets/etc/playground-assets.api.md b/packages/@dcl/playground-assets/etc/playground-assets.api.md index 90af0e9d4..da3246947 100644 --- a/packages/@dcl/playground-assets/etc/playground-assets.api.md +++ b/packages/@dcl/playground-assets/etc/playground-assets.api.md @@ -75,7 +75,7 @@ export const AvatarAttach: LastWriteWinElementSetComponentDefinition; // @public (undocumented) -export const AvatarEmoteCommand: LastWriteWinElementSetComponentDefinition; +export const AvatarEmoteCommand: GrowOnlyValueSetComponentDefinition; // @public (undocumented) export const AvatarEquippedData: LastWriteWinElementSetComponentDefinition; @@ -524,7 +524,7 @@ export const componentDefinitionByName: { "core::AudioStream": LwwComponentGetter>; "core::AvatarAttach": LwwComponentGetter>; "core::AvatarBase": LwwComponentGetter>; - "core::AvatarEmoteCommand": LwwComponentGetter>; + "core::AvatarEmoteCommand": GSetComponentGetter>; "core::AvatarEquippedData": LwwComponentGetter>; "core::AvatarModifierArea": LwwComponentGetter>; "core::AvatarShape": LwwComponentGetter>; @@ -988,7 +988,7 @@ export const GltfContainerLoadingState: LastWriteWinElementSetComponentDefinitio // @public (undocumented) export interface GrowOnlyValueSetComponentDefinition extends BaseComponent { - addValue(entity: Entity, val: DeepReadonly): DeepReadonlySet; + addValue(entity: Entity, val: DeepReadonly, ts: number): DeepReadonlySet; // (undocumented) readonly componentType: ComponentType.GrowOnlyValueSet; get(entity: Entity): DeepReadonlySet; @@ -3595,7 +3595,7 @@ export type Unpacked = T extends (infer U)[] ? U : T; // @public (undocumented) export type ValueSetOptions = { - timestampFunction: (value: DeepReadonly) => number; + timestampFunction?: (value: DeepReadonly) => number; maxElements: number; }; diff --git a/scripts/protocol-buffer-generation/generateIndex.ts b/scripts/protocol-buffer-generation/generateIndex.ts index 167b2dbec..bd7d77b9f 100644 --- a/scripts/protocol-buffer-generation/generateIndex.ts +++ b/scripts/protocol-buffer-generation/generateIndex.ts @@ -3,6 +3,17 @@ import * as path from 'path' import { Component } from './generateComponent' import generateExportedTypes from './generateExportedTypes' +type GrowOnlySetOptions = { + maxElements: number + timestampFunctionStr: string +} + +const growOnlySets: Record = { + PointerEventsResult: { timestampFunctionStr: `(t) => t.timestamp`, maxElements: 100 }, + VideoEvent: { timestampFunctionStr: `(t) => t.timestamp`, maxElements: 100 }, + AvatarEmoteCommand: { timestampFunctionStr: `undefined`, maxElements: 100 } +} + function importComponent(component: Component) { return `import { ${component.componentPascalName}Schema } from './${component.componentPascalName}.gen'; import { PB${component.componentPascalName} } from './pb/decentraland/sdk/components/${component.componentFile}.gen'` } @@ -15,18 +26,15 @@ function exportComponent(component: Component) { return `export * from './pb/decentraland/sdk/components/${component.componentFile}.gen'` } -function isGrowOnlyValueSet(component: Component): boolean { - return component.componentPascalName === 'PointerEventsResult' || component.componentPascalName === 'VideoEvent' -} - function defineComponentDecl(component: Component) { - if (isGrowOnlyValueSet(component)) { + if (component.componentPascalName in growOnlySets) { + const growOnlySetProps = growOnlySets[component.componentPascalName] return `/** @public */ export const ${component.componentPascalName}: GSetComponentGetter> = ( engine ) => /* @__PURE__ */ engine.defineValueSetComponentFromSchema("core::${component.componentPascalName}", ${component.componentPascalName}Schema, { - timestampFunction: (t) => t.timestamp, - maxElements: 100 + timestampFunction: ${growOnlySetProps.timestampFunctionStr}, + maxElements: ${growOnlySetProps.maxElements} })`.trim() } else { return `/** @public */ export const ${component.componentPascalName}: LwwComponentGetter> = engine => @@ -38,7 +46,7 @@ function defineComponentDecl(component: Component) { const skipExposeGlobally: string[] = ['Animator', 'MeshRenderer', 'MeshCollider', 'Material'] function defineGlobalComponentDecl(component: Component) { if (skipExposeGlobally.includes(component.componentPascalName)) return '' - if (isGrowOnlyValueSet(component)) { + if (component.componentPascalName in growOnlySets) { return `/** @public */ export const ${component.componentPascalName}: GrowOnlyValueSetComponentDefinition = /* @__PURE__ */ components.${component.componentPascalName}(engine)`.trim() } else { return `/** @public */ export const ${component.componentPascalName}: LastWriteWinElementSetComponentDefinition = /* @__PURE__ */ components.${component.componentPascalName}(engine)`.trim() From 35bc202e4e9692fd8b9f85a24ba2357a21c706c2 Mon Sep 17 00:00:00 2001 From: Lean Mendoza Date: Thu, 21 Sep 2023 03:21:32 -0300 Subject: [PATCH 4/5] add deprecated flags --- scripts/rpc-api-generation/index.ts | 46 ++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/scripts/rpc-api-generation/index.ts b/scripts/rpc-api-generation/index.ts index 75cc6b0ff..bf857cd16 100644 --- a/scripts/rpc-api-generation/index.ts +++ b/scripts/rpc-api-generation/index.ts @@ -22,6 +22,14 @@ type ProtoServiceDefinition = { > } +const deprecatedApiMethods: Record = { + CommunicationsController: ['send'], + EngineApi: ['sendBatch', 'subscribe', 'unsubscribe'], + EthereumController: ['requirePayment', 'signMessage', 'convertMessageToObject', 'getUserAccount'], + Players: ['getPlayerData', 'getPlayersInScene', 'getConnectedPlayers'], + UserIdentity: ['getUserPublicKey'] +} + export async function compileProtoApi() { try { await internalCompile() @@ -37,7 +45,10 @@ const NON_EXPOSED_LIST_NAMES: string[] = [ 'Permissions', 'DevTools', 'Permissions', - 'ParcelIdentity' + 'ParcelIdentity', + 'EnvironmentApi', + 'Scene', + 'UserActionModule' ] async function internalCompile() { @@ -54,12 +65,14 @@ async function internalCompile() { if (NON_EXPOSED_LIST_NAMES.includes(api.name)) continue const types: Set = new Set() const functions: string[] = [] + const deprecatedMethods = deprecatedApiMethods[api.name] || [] + for (const [methodName, method] of Object.entries(api.def.methods)) { types.add(method.requestType) types.add(method.responseType) + functions.push( - `export declare function ${method.requestStream ? '*' : ''}${methodName}(body: ${ - method.requestType + `export declare function ${method.requestStream ? '*' : ''}${methodName}(body: ${method.requestType }): Promise<${method.responseType}>` ) } @@ -68,9 +81,8 @@ async function internalCompile() { mkdirSync(path.resolve(apiModuleDirPath)) let indexContent = '' - indexContent += `import type {${Array.from(types).join(', ')}} from './../../proto/decentraland/kernel/apis/${ - api.fileName - }.gen'\n` + indexContent += `import type {${Array.from(types).join(', ')}} from './../../proto/decentraland/kernel/apis/${api.fileName + }.gen'\n` indexContent += functions.join('\n') writeFileSync(path.resolve(apiModuleDirPath, `index.gen.ts`), indexContent) @@ -85,7 +97,7 @@ async function internalCompile() { rmSync(path.resolve(apiModuleDirPath, 'index.gen.ts')) const moduleDTsPath = path.resolve(apiModuleDirPath, 'index.d.ts') - processDeclarations(api.name, moduleDTsPath) + processDeclarations(api.name, moduleDTsPath, deprecatedMethods) apisDTsContent += ` /** @@ -94,7 +106,7 @@ async function internalCompile() { ` apisDTsContent += readFileSync(moduleDTsPath).toString() - rmSync(apiModuleDirPath, { recursive: true, force: true }) + // rmSync(apiModuleDirPath, { recursive: true, force: true }) } writeFileSync(path.resolve(outModulesPath, 'index.d.ts'), apisDTsContent) @@ -141,7 +153,7 @@ async function preprocessProtoGeneration(protoPath: string) { return apis } -function processDeclarations(apiName: string, filePath: string) { +function processDeclarations(apiName: string, filePath: string, deprecatedMethods: string[]) { const decFile = readFileSync(filePath).toString() const blocks: string[] = [] @@ -161,6 +173,20 @@ function processDeclarations(apiName: string, filePath: string) { where += 'declare module'.length } while (where) - const content = blocks.join('\n\t// Function declaration section').replace(/import(.*)\n/g, '') + let content = blocks.join('\n\t// Function declaration section').replace(/import(.*)\n/g, '') + + const deprecatedString = ` /**\n * @deprecated\n **/ \n` + for (const methodName of deprecatedMethods) { + let searchMethodText = ` export function ${methodName}` + if (content.indexOf(searchMethodText) === -1) { + searchMethodText = ` export function *${methodName}` + if (content.indexOf(searchMethodText) === -1) { + continue + } + } + + content = content.replace(searchMethodText, `${deprecatedString}${searchMethodText}`) + } + writeFileSync(filePath, `declare module "~system/${apiName}" {\n${content}\n}`) } From d6d00dc0fbeaa68e116ba4af9aec3393c7e3a468 Mon Sep 17 00:00:00 2001 From: Mateo Kuruk Miccino Date: Thu, 21 Sep 2023 21:47:04 -0300 Subject: [PATCH 5/5] Revert "add deprecated flags" due to the extract in https://github.com/decentraland/js-sdk-toolchain/pull/746 This reverts commit 35bc202e4e9692fd8b9f85a24ba2357a21c706c2. --- scripts/rpc-api-generation/index.ts | 46 +++++++---------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/scripts/rpc-api-generation/index.ts b/scripts/rpc-api-generation/index.ts index bf857cd16..75cc6b0ff 100644 --- a/scripts/rpc-api-generation/index.ts +++ b/scripts/rpc-api-generation/index.ts @@ -22,14 +22,6 @@ type ProtoServiceDefinition = { > } -const deprecatedApiMethods: Record = { - CommunicationsController: ['send'], - EngineApi: ['sendBatch', 'subscribe', 'unsubscribe'], - EthereumController: ['requirePayment', 'signMessage', 'convertMessageToObject', 'getUserAccount'], - Players: ['getPlayerData', 'getPlayersInScene', 'getConnectedPlayers'], - UserIdentity: ['getUserPublicKey'] -} - export async function compileProtoApi() { try { await internalCompile() @@ -45,10 +37,7 @@ const NON_EXPOSED_LIST_NAMES: string[] = [ 'Permissions', 'DevTools', 'Permissions', - 'ParcelIdentity', - 'EnvironmentApi', - 'Scene', - 'UserActionModule' + 'ParcelIdentity' ] async function internalCompile() { @@ -65,14 +54,12 @@ async function internalCompile() { if (NON_EXPOSED_LIST_NAMES.includes(api.name)) continue const types: Set = new Set() const functions: string[] = [] - const deprecatedMethods = deprecatedApiMethods[api.name] || [] - for (const [methodName, method] of Object.entries(api.def.methods)) { types.add(method.requestType) types.add(method.responseType) - functions.push( - `export declare function ${method.requestStream ? '*' : ''}${methodName}(body: ${method.requestType + `export declare function ${method.requestStream ? '*' : ''}${methodName}(body: ${ + method.requestType }): Promise<${method.responseType}>` ) } @@ -81,8 +68,9 @@ async function internalCompile() { mkdirSync(path.resolve(apiModuleDirPath)) let indexContent = '' - indexContent += `import type {${Array.from(types).join(', ')}} from './../../proto/decentraland/kernel/apis/${api.fileName - }.gen'\n` + indexContent += `import type {${Array.from(types).join(', ')}} from './../../proto/decentraland/kernel/apis/${ + api.fileName + }.gen'\n` indexContent += functions.join('\n') writeFileSync(path.resolve(apiModuleDirPath, `index.gen.ts`), indexContent) @@ -97,7 +85,7 @@ async function internalCompile() { rmSync(path.resolve(apiModuleDirPath, 'index.gen.ts')) const moduleDTsPath = path.resolve(apiModuleDirPath, 'index.d.ts') - processDeclarations(api.name, moduleDTsPath, deprecatedMethods) + processDeclarations(api.name, moduleDTsPath) apisDTsContent += ` /** @@ -106,7 +94,7 @@ async function internalCompile() { ` apisDTsContent += readFileSync(moduleDTsPath).toString() - // rmSync(apiModuleDirPath, { recursive: true, force: true }) + rmSync(apiModuleDirPath, { recursive: true, force: true }) } writeFileSync(path.resolve(outModulesPath, 'index.d.ts'), apisDTsContent) @@ -153,7 +141,7 @@ async function preprocessProtoGeneration(protoPath: string) { return apis } -function processDeclarations(apiName: string, filePath: string, deprecatedMethods: string[]) { +function processDeclarations(apiName: string, filePath: string) { const decFile = readFileSync(filePath).toString() const blocks: string[] = [] @@ -173,20 +161,6 @@ function processDeclarations(apiName: string, filePath: string, deprecatedMethod where += 'declare module'.length } while (where) - let content = blocks.join('\n\t// Function declaration section').replace(/import(.*)\n/g, '') - - const deprecatedString = ` /**\n * @deprecated\n **/ \n` - for (const methodName of deprecatedMethods) { - let searchMethodText = ` export function ${methodName}` - if (content.indexOf(searchMethodText) === -1) { - searchMethodText = ` export function *${methodName}` - if (content.indexOf(searchMethodText) === -1) { - continue - } - } - - content = content.replace(searchMethodText, `${deprecatedString}${searchMethodText}`) - } - + const content = blocks.join('\n\t// Function declaration section').replace(/import(.*)\n/g, '') writeFileSync(filePath, `declare module "~system/${apiName}" {\n${content}\n}`) }