Skip to content

Commit 1a8fb64

Browse files
authored
Merge branch 'main' into feat/abgen-preview
2 parents 83b2601 + bf777ec commit 1a8fb64

31 files changed

Lines changed: 543 additions & 82 deletions

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"bugs": "https://github.com/decentraland/js-sdk-toolchain/issues",
77
"dependencies": {
88
"@actions/core": "^1.10.0",
9-
"@dcl/protocol": "1.0.0-29286492043.commit-0010e70",
9+
"@dcl/protocol": "1.0.0-30373157983.commit-2c475cb",
1010
"@dcl/quickjs-emscripten": "^0.21.0-3680274614.commit-1808aa1",
1111
"@dcl/ts-proto": "1.153.0",
1212
"@types/fs-extra": "^9.0.12",
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { Entity, IEngine, LastWriteWinElementSetComponentDefinition } from '../../engine'
2+
import { TouchScreenControls, PBTouchScreenControls, PBTouchScreenControls_TouchInput } from '../generated/index.gen'
3+
import { InputAction } from '../generated/pb/decentraland/sdk/components/common/input_action.gen'
4+
5+
const ROOT_ENTITY = 0 as Entity
6+
7+
// Every on-screen gamepad action button.
8+
const ALL_BUTTONS: InputAction[] = [
9+
InputAction.IA_POINTER,
10+
InputAction.IA_PRIMARY,
11+
InputAction.IA_SECONDARY,
12+
InputAction.IA_JUMP,
13+
InputAction.IA_ACTION_3,
14+
InputAction.IA_ACTION_4,
15+
InputAction.IA_ACTION_5,
16+
InputAction.IA_ACTION_6
17+
]
18+
19+
/**
20+
* @public
21+
* TouchScreenControls with convenience helpers. All helpers write the component onto the
22+
* RootEntity (where the client reads it) and merge with the current value.
23+
*/
24+
export interface TouchScreenControlsComponentDefinitionExtended
25+
extends LastWriteWinElementSetComponentDefinition<PBTouchScreenControls> {
26+
/** Hide every on-screen gamepad button. */
27+
hideAll(): void
28+
/**
29+
* Show every on-screen gamepad button (clears the button hide list).
30+
* Does NOT change the joystick/crosshair — use `showJoystick()` / `showCrosshair()` for those.
31+
*/
32+
showAll(): void
33+
/** Hide the given on-screen buttons (merged into the current config). */
34+
hide(actions: InputAction[]): void
35+
/** Set which action the large central button triggers. */
36+
setMainAction(action: InputAction): void
37+
/** Hide the native virtual joystick. */
38+
hideJoystick(): void
39+
/** Show the native virtual joystick. */
40+
showJoystick(): void
41+
/** Hide the on-screen crosshair / reticle. */
42+
hideCrosshair(): void
43+
/** Show the on-screen crosshair / reticle. */
44+
showCrosshair(): void
45+
}
46+
47+
export function defineTouchScreenControlsComponent(
48+
engine: Pick<IEngine, 'defineComponentFromSchema'>
49+
): TouchScreenControlsComponentDefinitionExtended {
50+
const theComponent = TouchScreenControls(engine)
51+
52+
// A mutable copy of the current RootEntity value (or a fresh default).
53+
function current(): PBTouchScreenControls {
54+
const value = theComponent.getOrNull(ROOT_ENTITY)
55+
return {
56+
touchInputs: value?.touchInputs
57+
? value.touchInputs.map((t) => ({ ...t, icon: t.icon ? { ...t.icon } : t.icon }))
58+
: [],
59+
mainAction: value?.mainAction,
60+
hideJoystick: value?.hideJoystick ?? false,
61+
hideCrosshair: value?.hideCrosshair ?? false
62+
}
63+
}
64+
65+
function setHidden(actions: InputAction[]): void {
66+
const value = current()
67+
const byAction = new Map<InputAction, PBTouchScreenControls_TouchInput>()
68+
for (const input of value.touchInputs) byAction.set(input.inputAction, input)
69+
for (const action of actions) byAction.set(action, { ...byAction.get(action), inputAction: action, hide: true })
70+
value.touchInputs = [...byAction.values()]
71+
theComponent.createOrReplace(ROOT_ENTITY, value)
72+
}
73+
74+
return {
75+
...theComponent,
76+
hideAll(): void {
77+
setHidden(ALL_BUTTONS)
78+
},
79+
showAll(): void {
80+
const value = current()
81+
value.touchInputs = []
82+
theComponent.createOrReplace(ROOT_ENTITY, value)
83+
},
84+
hide(actions: InputAction[]): void {
85+
setHidden(actions)
86+
},
87+
setMainAction(action: InputAction): void {
88+
const value = current()
89+
value.mainAction = action
90+
theComponent.createOrReplace(ROOT_ENTITY, value)
91+
},
92+
hideJoystick(): void {
93+
const value = current()
94+
value.hideJoystick = true
95+
theComponent.createOrReplace(ROOT_ENTITY, value)
96+
},
97+
showJoystick(): void {
98+
const value = current()
99+
value.hideJoystick = false
100+
theComponent.createOrReplace(ROOT_ENTITY, value)
101+
},
102+
hideCrosshair(): void {
103+
const value = current()
104+
value.hideCrosshair = true
105+
theComponent.createOrReplace(ROOT_ENTITY, value)
106+
},
107+
showCrosshair(): void {
108+
const value = current()
109+
value.hideCrosshair = false
110+
theComponent.createOrReplace(ROOT_ENTITY, value)
111+
}
112+
}
113+
}

packages/@dcl/ecs/src/components/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import { defineInputModifierComponent, InputModifierComponentDefinitionExtended
2121
import { defineLightSourceComponent, LightSourceComponentDefinitionExtended } from './extended/LightSource'
2222
import { defineTriggerAreaComponent, TriggerAreaComponentDefinitionExtended } from './extended/TriggerArea'
2323
import { defineParticleSystemComponent, ParticleSystemComponentDefinitionExtended } from './extended/ParticleSystem'
24+
import {
25+
defineTouchScreenControlsComponent,
26+
TouchScreenControlsComponentDefinitionExtended
27+
} from './extended/TouchScreenControls'
2428
import defineTagsComponent, { TagsComponentDefinitionExtended } from './manual/Tags'
2529

2630
export * from './generated/index.gen'
@@ -87,6 +91,10 @@ export const TriggerArea: LwwComponentGetter<TriggerAreaComponentDefinitionExten
8791
export const ParticleSystem: LwwComponentGetter<ParticleSystemComponentDefinitionExtended> = (engine) =>
8892
defineParticleSystemComponent(engine)
8993

94+
/* @__PURE__ */
95+
export const TouchScreenControls: LwwComponentGetter<TouchScreenControlsComponentDefinitionExtended> = (engine) =>
96+
defineTouchScreenControlsComponent(engine)
97+
9098
/**
9199
* @alpha
92100
*/

packages/@dcl/ecs/src/components/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type { INetowrkParent, INetowrkParentType } from './manual/NetworkParent'
2828
export type { InputModifierHelper, InputModifierComponentDefinitionExtended } from './extended/InputModifier'
2929
export type { LightSourceHelper, LightSourceComponentDefinitionExtended } from './extended/LightSource'
3030
export type { TriggerAreaComponentDefinitionExtended } from './extended/TriggerArea'
31+
export type { TouchScreenControlsComponentDefinitionExtended } from './extended/TouchScreenControls'
3132
export type {
3233
ParticleSystemHelper,
3334
ParticleSystemComponentDefinitionExtended,

packages/@dcl/ecs/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import {
4141
InputModifierComponentDefinitionExtended,
4242
LightSourceComponentDefinitionExtended,
4343
TriggerAreaComponentDefinitionExtended,
44-
ParticleSystemComponentDefinitionExtended
44+
ParticleSystemComponentDefinitionExtended,
45+
TouchScreenControlsComponentDefinitionExtended
4546
} from './components/types'
4647
import { NameComponent } from './components/manual/Name'
4748
import { TagsComponentDefinitionExtended } from './components/manual/Tags'
@@ -64,6 +65,8 @@ export const LightSource: LightSourceComponentDefinitionExtended = /* @__PURE__*
6465
export const TriggerArea: TriggerAreaComponentDefinitionExtended = /* @__PURE__*/ components.TriggerArea(engine)
6566
export const ParticleSystem: ParticleSystemComponentDefinitionExtended =
6667
/* @__PURE__*/ components.ParticleSystem(engine)
68+
export const TouchScreenControls: TouchScreenControlsComponentDefinitionExtended =
69+
/* @__PURE__*/ components.TouchScreenControls(engine)
6770

6871
/**
6972
* @alpha

packages/@dcl/playground-assets/etc/playground-assets.api.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ export const componentDefinitionByName: {
732732
"core::RealmInfo": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBRealmInfo>>;
733733
"core::SkyboxTime": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBSkyboxTime>>;
734734
"core::TextShape": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBTextShape>>;
735+
"core::TouchScreenControls": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBTouchScreenControls>>;
735736
"core::TriggerArea": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBTriggerArea>>;
736737
"core::TriggerAreaResult": GSetComponentGetter<GrowOnlyValueSetComponentDefinition<PBTriggerAreaResult>>;
737738
"core::Tween": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBTween>>;
@@ -742,6 +743,7 @@ export const componentDefinitionByName: {
742743
"core::UiDropdown": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBUiDropdown>>;
743744
"core::UiDropdownResult": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBUiDropdownResult>>;
744745
"core::UiInput": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBUiInput>>;
746+
"core::UiInputBinding": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBUiInputBinding>>;
745747
"core::UiInputResult": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBUiInputResult>>;
746748
"core::UiText": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBUiText>>;
747749
"core::UiTransform": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBUiTransform>>;
@@ -1185,6 +1187,7 @@ export type EntityComponents = {
11851187
uiBackground: PBUiBackground;
11861188
uiInput: PBUiInput;
11871189
uiDropdown: PBUiDropdown;
1190+
uiInputBinding: PBUiInputBinding;
11881191
onMouseDown: Callback;
11891192
onMouseUp: Callback;
11901193
onMouseEnter: Callback;
@@ -1205,6 +1208,7 @@ export enum EntityMappingMode {
12051208
export interface EntityPropTypes extends Listeners {
12061209
key?: Key;
12071210
uiBackground?: UiBackgroundProps;
1211+
uiInputBinding?: PBUiInputBinding;
12081212
uiTransform?: UiTransformProps;
12091213
}
12101214

@@ -3604,6 +3608,38 @@ export namespace PBTextShape {
36043608
export function encode(message: PBTextShape, writer?: _m0.Writer): _m0.Writer;
36053609
}
36063610

3611+
// @public (undocumented)
3612+
export interface PBTouchScreenControls {
3613+
hideCrosshair: boolean;
3614+
hideJoystick: boolean;
3615+
mainAction?: InputAction | undefined;
3616+
// (undocumented)
3617+
touchInputs: PBTouchScreenControls_TouchInput[];
3618+
}
3619+
3620+
// @public (undocumented)
3621+
export namespace PBTouchScreenControls {
3622+
// (undocumented)
3623+
export function decode(input: _m0.Reader | Uint8Array, length?: number): PBTouchScreenControls;
3624+
// (undocumented)
3625+
export function encode(message: PBTouchScreenControls, writer?: _m0.Writer): _m0.Writer;
3626+
}
3627+
3628+
// @public (undocumented)
3629+
export interface PBTouchScreenControls_TouchInput {
3630+
hide: boolean;
3631+
icon?: TextureUnion | undefined;
3632+
inputAction: InputAction;
3633+
}
3634+
3635+
// @public (undocumented)
3636+
export namespace PBTouchScreenControls_TouchInput {
3637+
// (undocumented)
3638+
export function decode(input: _m0.Reader | Uint8Array, length?: number): PBTouchScreenControls_TouchInput;
3639+
// (undocumented)
3640+
export function encode(message: PBTouchScreenControls_TouchInput, writer?: _m0.Writer): _m0.Writer;
3641+
}
3642+
36073643
// @public (undocumented)
36083644
export interface PBTriggerArea {
36093645
collisionMask?: number | undefined;
@@ -3826,6 +3862,19 @@ export namespace PBUiInput {
38263862
export function encode(message: PBUiInput, writer?: _m0.Writer): _m0.Writer;
38273863
}
38283864

3865+
// @public (undocumented)
3866+
export interface PBUiInputBinding {
3867+
actions: InputAction[];
3868+
}
3869+
3870+
// @public (undocumented)
3871+
export namespace PBUiInputBinding {
3872+
// (undocumented)
3873+
export function decode(input: _m0.Reader | Uint8Array, length?: number): PBUiInputBinding;
3874+
// (undocumented)
3875+
export function encode(message: PBUiInputBinding, writer?: _m0.Writer): _m0.Writer;
3876+
}
3877+
38293878
// @public (undocumented)
38303879
export interface PBUiInputResult {
38313880
isSubmit?: boolean | undefined;
@@ -4057,6 +4106,7 @@ export namespace PBVideoPlayer {
40574106
export interface PBVirtualCamera {
40584107
// (undocumented)
40594108
defaultTransition?: CameraTransition | undefined;
4109+
fov?: number | undefined;
40604110
// (undocumented)
40614111
lookAtEntity?: number | undefined;
40624112
}
@@ -5055,6 +5105,23 @@ export const ToLinearSpace = 2.2;
50555105
// @public (undocumented)
50565106
export type ToOptional<T> = OnlyOptionalUndefinedTypes<T> & OnlyNonUndefinedTypes<T>;
50575107

5108+
// Warning: (ae-missing-release-tag) "TouchScreenControls" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
5109+
//
5110+
// @public (undocumented)
5111+
export const TouchScreenControls: TouchScreenControlsComponentDefinitionExtended;
5112+
5113+
// @public
5114+
export interface TouchScreenControlsComponentDefinitionExtended extends LastWriteWinElementSetComponentDefinition<PBTouchScreenControls> {
5115+
hide(actions: InputAction[]): void;
5116+
hideAll(): void;
5117+
hideCrosshair(): void;
5118+
hideJoystick(): void;
5119+
setMainAction(action: InputAction): void;
5120+
showAll(): void;
5121+
showCrosshair(): void;
5122+
showJoystick(): void;
5123+
}
5124+
50585125
// Warning: (ae-missing-release-tag) "Transform" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
50595126
//
50605127
// @public (undocumented)
@@ -5300,6 +5367,9 @@ export type UiFontType = 'sans-serif' | 'serif' | 'monospace';
53005367
// @public (undocumented)
53015368
export const UiInput: LastWriteWinElementSetComponentDefinition<PBUiInput>;
53025369

5370+
// @public (undocumented)
5371+
export const UiInputBinding: LastWriteWinElementSetComponentDefinition<PBUiInputBinding>;
5372+
53035373
// @public (undocumented)
53045374
export interface UiInputProps extends Omit<PBUiInput, 'font' | 'textAlign' | 'fontSize'> {
53055375
// (undocumented)

packages/@dcl/react-ecs/src/components/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PBUiInputBinding } from '@dcl/ecs'
12
import { ReactEcs } from '../react-ecs'
23
import { Listeners } from './listeners/types'
34
import { UiBackgroundProps } from './uiBackground/types'
@@ -12,6 +13,8 @@ export interface EntityPropTypes extends Listeners {
1213
uiTransform?: UiTransformProps
1314
/** To define a background color or image */
1415
uiBackground?: UiBackgroundProps
16+
/** Bind input actions to this element, held down while it's pressed (touch or pointer) */
17+
uiInputBinding?: PBUiInputBinding
1518
/** Uinique key to identiy elments when iterating arrays */
1619
key?: Key
1720
}

packages/@dcl/react-ecs/src/react-ecs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-empty-interface */
2-
import { PBUiBackground, PBUiText, PBUiTransform, PBUiInput, PBUiDropdown } from '@dcl/ecs'
2+
import { PBUiBackground, PBUiText, PBUiTransform, PBUiInput, PBUiDropdown, PBUiInputBinding } from '@dcl/ecs'
33
import React from 'react'
44
import { Callback, Key } from './components'
55

@@ -19,6 +19,7 @@ export type EntityComponents = {
1919
uiBackground: PBUiBackground
2020
uiInput: PBUiInput
2121
uiDropdown: PBUiDropdown
22+
uiInputBinding: PBUiInputBinding
2223
onMouseDown: Callback
2324
onMouseUp: Callback
2425
onMouseEnter: Callback

packages/@dcl/react-ecs/src/reconciler/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export function createReconciler(
7171
const UiInputResult = components.UiInputResult(engine)
7272
const UiDropdown = components.UiDropdown(engine)
7373
const UiDropdownResult = components.UiDropdownResult(engine)
74+
const UiInputBinding = components.UiInputBinding(engine)
7475

7576
// Component ID Helper
7677
const getComponentId: {
@@ -80,7 +81,8 @@ export function createReconciler(
8081
uiText: UiText.componentId,
8182
uiBackground: UiBackground.componentId,
8283
uiInput: UiInput.componentId,
83-
uiDropdown: UiDropdown.componentId
84+
uiDropdown: UiDropdown.componentId,
85+
uiInputBinding: UiInputBinding.componentId
8486
}
8587

8688
function pointerEventCallback(entity: Entity, pointerEvent: PointerEventType) {

0 commit comments

Comments
 (0)