Skip to content

Commit

Permalink
chore: helper functions for InputModifier (#1035)
Browse files Browse the repository at this point in the history
* Initial implementation of helper function for InputModifier

* Updated protocol, regenerated API and run a lint pass

* Added addStandardModifier helper function

* Fixed properties naming

* Helper function iteration. Added documentation.

* Helper function iteration. Added documentation.

* Added helper function to @dcl/ecs/src/components/Index.ts

* Lint fix

* Updated index.ts and types.ts

* Updated API

* Updated types.ts and API

* fix tests

* Updated InputModifier helper and tests

* update playground assetsmd

* Removed unused import

---------

Co-authored-by: Gonzalo DCL <[email protected]>
  • Loading branch information
AlejandroAlvarezMelucciDCL and gonpombo8 authored Nov 21, 2024
1 parent c13aef2 commit 2c002ca
Show file tree
Hide file tree
Showing 25 changed files with 151 additions and 62 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/decentraland/js-sdk-toolchain/issues",
"dependencies": {
"@actions/core": "^1.10.0",
"@dcl/protocol": "1.0.0-11599848164.commit-ef74edc",
"@dcl/protocol": "1.0.0-11780504028.commit-c886080",
"@dcl/quickjs-emscripten": "^0.21.0-3680274614.commit-1808aa1",
"@dcl/ts-proto": "1.153.0",
"@types/fs-extra": "^9.0.12",
Expand Down
44 changes: 44 additions & 0 deletions packages/@dcl/ecs/src/components/extended/InputModifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { IEngine, LastWriteWinElementSetComponentDefinition } from '../../engine'
import { InputModifier, PBInputModifier_StandardInput, PBInputModifier } from '../generated/index.gen'
import {} from '../generated/InputModifier.gen'

/**
* @public
*/
export interface InputModifierHelper {
/**
* @returns a input modifier mode
*/
Standard: (standard: PBInputModifier_StandardInput) => PBInputModifier['mode']
}

/**
* @public
*/
export interface InputModifierComponentDefinitionExtended
extends LastWriteWinElementSetComponentDefinition<PBInputModifier> {
/**
* InputModifier helper with constructor
*/
Mode: InputModifierHelper
}

const InputModifierHelper: InputModifierHelper = {
Standard(standard: PBInputModifier_StandardInput) {
return {
$case: 'standard',
standard
}
}
}

export function defineInputModifierComponent(
engine: Pick<IEngine, 'defineComponentFromSchema'>
): InputModifierComponentDefinitionExtended {
const theComponent = InputModifier(engine)

return {
...theComponent,
Mode: InputModifierHelper
}
}
5 changes: 5 additions & 0 deletions packages/@dcl/ecs/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { defineTransformComponent, TransformComponentExtended } from './manual/T
import { AudioStreamComponentDefinitionExtended, defineAudioStreamComponent } from './extended/AudioStream'
import { MediaState } from './generated/pb/decentraland/sdk/components/common/media_state.gen'
import { defineVirtualCameraComponent, VirtualCameraComponentDefinitionExtended } from './extended/VirtualCamera'
import { defineInputModifierComponent, InputModifierComponentDefinitionExtended } from './extended/InputModifier'

export * from './generated/index.gen'

Expand Down Expand Up @@ -60,6 +61,10 @@ export const Tween: LwwComponentGetter<TweenComponentDefinitionExtended> = (engi
export const VirtualCamera: LwwComponentGetter<VirtualCameraComponentDefinitionExtended> = (engine) =>
defineVirtualCameraComponent(engine)

/* @__PURE__*/
export const InputModifier: LwwComponentGetter<InputModifierComponentDefinitionExtended> = (engine) =>
defineInputModifierComponent(engine)

/**
* @alpha
*/
Expand Down
1 change: 1 addition & 0 deletions packages/@dcl/ecs/src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export type { NameComponent, NameType } from './manual/Name'
export type { ISyncComponents, ISyncComponentsType } from './manual/SyncComponents'
export type { INetowrkEntity, INetowrkEntityType } from './manual/NetworkEntity'
export type { INetowrkParent, INetowrkParentType } from './manual/NetworkParent'
export type { InputModifierHelper, InputModifierComponentDefinitionExtended } from './extended/InputModifier'
5 changes: 4 additions & 1 deletion packages/@dcl/ecs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
TweenComponentDefinitionExtended,
INetowrkEntity,
INetowrkParent,
VirtualCameraComponentDefinitionExtended
VirtualCameraComponentDefinitionExtended,
InputModifierComponentDefinitionExtended
} from './components/types'
import { NameComponent } from './components/manual/Name'

Expand All @@ -47,6 +48,8 @@ export const MeshCollider: MeshColliderComponentDefinitionExtended = /* @__PURE_
export const Name: NameComponent = components.Name(engine)
export const Tween: TweenComponentDefinitionExtended = /* @__PURE__*/ components.Tween(engine)
export const VirtualCamera: VirtualCameraComponentDefinitionExtended = /* @__PURE__*/ components.VirtualCamera(engine)
export const InputModifier: InputModifierComponentDefinitionExtended = /* @__PURE__*/ components.InputModifier(engine)

/**
* @alpha
* This is going to be used for sync components through a server.
Expand Down
17 changes: 16 additions & 1 deletion packages/@dcl/playground-assets/etc/playground-assets.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1421,8 +1421,21 @@ export const enum InputAction {
IA_WALK = 9
}

// Warning: (ae-missing-release-tag) "InputModifier" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const InputModifier: InputModifierComponentDefinitionExtended;

// @public (undocumented)
export interface InputModifierComponentDefinitionExtended extends LastWriteWinElementSetComponentDefinition<PBInputModifier> {
Mode: InputModifierHelper;
}

// @public (undocumented)
export const InputModifier: LastWriteWinElementSetComponentDefinition<PBInputModifier>;
export interface InputModifierHelper {
// (undocumented)
Standard: (standard: PBInputModifier_StandardInput) => PBInputModifier['mode'];
}

// @public
export const inputSystem: IInputSystem;
Expand Down Expand Up @@ -3891,8 +3904,10 @@ export const TextShape: LastWriteWinElementSetComponentDefinition<PBTextShape>;
// @public (undocumented)
export interface Texture {
filterMode?: TextureFilterMode | undefined;
offset?: PBVector2 | undefined;
// (undocumented)
src: string;
tiling?: PBVector2 | undefined;
wrapMode?: TextureWrapMode | undefined;
}

Expand Down
14 changes: 7 additions & 7 deletions packages/@dcl/sdk-commands/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@dcl/sdk-commands/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@dcl/inspector": "file:../inspector",
"@dcl/linker-dapp": "^0.14.2",
"@dcl/mini-comms": "1.0.1-20230216163137.commit-a4c75be",
"@dcl/protocol": "1.0.0-11599848164.commit-ef74edc",
"@dcl/protocol": "1.0.0-11780504028.commit-c886080",
"@dcl/quests-client": "^1.0.3",
"@dcl/quests-manager": "^0.1.4",
"@dcl/rpc": "^1.1.1",
Expand Down
15 changes: 15 additions & 0 deletions test/ecs/components/InputModifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,19 @@ describe('Generated InputModifier ProtoBuf', () => {
}
})
})
it('should test Standar modifier', () => {
const newEngine = Engine()
const InputModifier = components.InputModifier(newEngine)

testComponentSerialization(InputModifier, {
mode: InputModifier.Mode.Standard({
disableAll: true,
disableWalk: true,
disableJog: true,
disableRun: true,
disableJump: true,
disableEmote: true
})
})
})
})
8 changes: 6 additions & 2 deletions test/ecs/components/Material.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ describe('Generated Material ProtoBuf', () => {
texture: {
wrapMode: TextureWrapMode.TWM_MIRROR,
filterMode: TextureFilterMode.TFM_POINT,
src: 'not-casla'
src: 'not-casla',
tiling: undefined,
offset: undefined
}
}
},
Expand All @@ -87,7 +89,9 @@ describe('Generated Material ProtoBuf', () => {
texture: {
wrapMode: TextureWrapMode.TWM_MIRROR,
filterMode: TextureFilterMode.TFM_TRILINEAR,
src: 'not-casla'
src: 'not-casla',
tiling: undefined,
offset: undefined
}
}
},
Expand Down
12 changes: 7 additions & 5 deletions test/ecs/components/UiBackground.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ describe('Generated UiBackground ProtoBuf', () => {
texture: {
src: 'some-src',
wrapMode: TextureWrapMode.TWM_CLAMP,
filterMode: TextureFilterMode.TFM_BILINEAR
filterMode: TextureFilterMode.TFM_BILINEAR,
tiling: undefined,
offset: undefined
}
}
},
textureSlices: {
top: 1 / 3,
left: 1 / 3,
right: 1 / 3,
bottom: 1 / 3
top: 2,
left: 2,
right: 2,
bottom: 2
},
uvs: []
})
Expand Down
6 changes: 3 additions & 3 deletions test/snapshots/development-bundles/static-scene.test.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=452.9k bytes
SCENE_COMPILED_JS_SIZE_PROD=453.4k bytes
THE BUNDLE HAS SOURCEMAPS
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
Expand All @@ -11,7 +11,7 @@ EVAL test/snapshots/development-bundles/static-scene.test.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 54k
MALLOC_COUNT = 13672
MALLOC_COUNT = 13673
ALIVE_OBJS_DELTA ~= 2.70k
CALL onStart()
main.crdt: PUT_COMPONENT e=0x200 c=1 t=0 data={"position":{"x":5.880000114440918,"y":2.7916901111602783,"z":7.380000114440918},"rotation":{"x":0,"y":0,"z":0,"w":1},"scale":{"x":1,"y":1,"z":1},"parent":0}
Expand Down Expand Up @@ -56,4 +56,4 @@ CALL onUpdate(0.1)
OPCODES ~= 3k
MALLOC_COUNT = -5
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 1193.93k bytes
MEMORY_USAGE_COUNT ~= 1194.79k bytes
6 changes: 3 additions & 3 deletions test/snapshots/development-bundles/testing-fw.test.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=453.4k bytes
SCENE_COMPILED_JS_SIZE_PROD=454k bytes
THE BUNDLE HAS SOURCEMAPS
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
Expand All @@ -11,7 +11,7 @@ EVAL test/snapshots/development-bundles/testing-fw.test.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 63k
MALLOC_COUNT = 14193
MALLOC_COUNT = 14194
ALIVE_OBJS_DELTA ~= 2.85k
CALL onStart()
LOG: ["Adding one to position.y=0"]
Expand Down Expand Up @@ -64,4 +64,4 @@ CALL onUpdate(0.1)
OPCODES ~= 5k
MALLOC_COUNT = -40
ALIVE_OBJS_DELTA ~= -0.01k
MEMORY_USAGE_COUNT ~= 1202.54k bytes
MEMORY_USAGE_COUNT ~= 1203.40k bytes
6 changes: 3 additions & 3 deletions test/snapshots/development-bundles/two-way-crdt.test.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=453.4k bytes
SCENE_COMPILED_JS_SIZE_PROD=454k bytes
THE BUNDLE HAS SOURCEMAPS
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
Expand All @@ -11,7 +11,7 @@ EVAL test/snapshots/development-bundles/two-way-crdt.test.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 63k
MALLOC_COUNT = 14193
MALLOC_COUNT = 14194
ALIVE_OBJS_DELTA ~= 2.85k
CALL onStart()
LOG: ["Adding one to position.y=0"]
Expand Down Expand Up @@ -64,4 +64,4 @@ CALL onUpdate(0.1)
OPCODES ~= 5k
MALLOC_COUNT = -40
ALIVE_OBJS_DELTA ~= -0.01k
MEMORY_USAGE_COUNT ~= 1202.55k bytes
MEMORY_USAGE_COUNT ~= 1203.41k bytes
2 changes: 1 addition & 1 deletion test/snapshots/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test/snapshots/production-bundles/append-value-crdt.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=197.8k bytes
SCENE_COMPILED_JS_SIZE_PROD=198.1k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/append-value-crdt.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 65k
MALLOC_COUNT = 12721
MALLOC_COUNT = 12723
ALIVE_OBJS_DELTA ~= 2.84k
CALL onStart()
Renderer: APPEND_VALUE e=0x200 c=1063 t=0 data={"button":0,"hit":{"position":{"x":1,"y":2,"z":3},"globalOrigin":{"x":1,"y":2,"z":3},"direction":{"x":1,"y":2,"z":3},"normalHit":{"x":1,"y":2,"z":3},"length":10,"meshName":"mesh","entityId":512},"state":1,"timestamp":1,"analog":5,"tickNumber":0}
Expand Down Expand Up @@ -55,4 +55,4 @@ CALL onUpdate(0.1)
OPCODES ~= 14k
MALLOC_COUNT = 31
ALIVE_OBJS_DELTA ~= 0.01k
MEMORY_USAGE_COUNT ~= 899.15k bytes
MEMORY_USAGE_COUNT ~= 899.73k bytes
6 changes: 3 additions & 3 deletions test/snapshots/production-bundles/billboard.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=230.9k bytes
SCENE_COMPILED_JS_SIZE_PROD=231.2k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/billboard.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 66k
MALLOC_COUNT = 14834
MALLOC_COUNT = 14836
ALIVE_OBJS_DELTA ~= 3.24k
CALL onStart()
OPCODES ~= 0k
Expand Down Expand Up @@ -77,4 +77,4 @@ CALL onUpdate(0.1)
OPCODES ~= 9k
MALLOC_COUNT = 0
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 1041.51k bytes
MEMORY_USAGE_COUNT ~= 1042.09k bytes
Loading

0 comments on commit 2c002ca

Please sign in to comment.