Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions web/src/engine/src/osk/views/activator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export abstract class Activator<ExtraEvents = void> extends EventEmitter<EventMa
/**
* When `true`, indicates that the listener should activate / become visible.
*/
abstract get activate(): boolean;
abstract get canActivate(): boolean;

/**
* When `true` and `activate` is `false`, indicates that changing the value of `enabled`
* When `true` and `canActivate` is `false`, indicates that changing the value of `enabled`
* will result in activation.
*/
abstract get conditionsMet(): boolean;
Expand All @@ -41,7 +41,7 @@ export class StaticActivator extends Activator {
// does nothing; it's static.
}

get activate(): boolean {
get canActivate(): boolean {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion web/src/engine/src/osk/views/floatingOskView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export class FloatingOSKView extends OSKView {

Ls.position='absolute';
// Keep it hidden if not currently displayed.
if(this.activationModel.activate) {
if(this.activationModel.canActivate) {
Ls.display='block'; //Ls.visibility='visible';
}
Ls.left='0px';
Expand Down
2 changes: 1 addition & 1 deletion web/src/engine/src/osk/views/oskView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ export abstract class OSKView
* they rely on this function to manage presentation (showing / hiding) of the OSK.
*/
private commonCheckAndDisplay() {
if(this.activationModel.activate && this.activeKeyboard) {
if(this.activationModel.canActivate && this.activeKeyboard) {
this.present();
} else {
this.startHide(false);
Expand Down
6 changes: 3 additions & 3 deletions web/src/engine/src/osk/views/simpleActivator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export class SimpleActivator extends Activator {

set enabled(value: boolean) {
// Enabled + activated are the same thing for this class.
this.activate = value;
this.canActivate = value;
}

get activate(): boolean {
get canActivate(): boolean {
return this.flag;
}

set activate(value: boolean) {
set canActivate(value: boolean) {
if(this.flag != value) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why the internal property is named flag and not _canActivate? (Avoid adding unnecessarily different identifiers)

this.flag = value;
this.emit('activate', value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This emit value seems like it still misleading?

Expand Down
10 changes: 5 additions & 5 deletions web/src/engine/src/osk/views/twoStateActivator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export class TwoStateActivator<Type> extends Activator<TriggerEventMap<Type>> {
private _enabled: boolean = true;
private actValue: Type = null;

get activate(): boolean {
get canActivate(): boolean {
return this._enabled && !!this.actValue;
}

private checkState(oldValue: boolean) {
if(this.activate != oldValue) {
this.emit('activate', this.activate);
if(this.canActivate != oldValue) {
this.emit('activate', this.canActivate);
}
}

Expand All @@ -26,7 +26,7 @@ export class TwoStateActivator<Type> extends Activator<TriggerEventMap<Type>> {
}

set enabled(flag: boolean) {
const oldState = this.activate;
const oldState = this.canActivate;
this._enabled = flag; // may change this.value!

this.checkState(oldState);
Expand All @@ -37,7 +37,7 @@ export class TwoStateActivator<Type> extends Activator<TriggerEventMap<Type>> {
}

set activationTrigger(value: Type) {
const oldState = this.activate;
const oldState = this.canActivate;
const oldValue = this.actValue;
this.actValue = value; // may change this.value!

Expand Down
16 changes: 8 additions & 8 deletions web/src/test/auto/headless/engine/osk/activation.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Activators", () => {

assert.isTrue(activator.enabled);
assert.isTrue(activator.conditionsMet);
assert.isTrue(activator.activate);
assert.isTrue(activator.canActivate);
});

it("set to 'off'", () => {
Expand All @@ -21,19 +21,19 @@ describe("Activators", () => {

assert.isFalse(activator.enabled);
assert.isTrue(activator.conditionsMet);
assert.isFalse(activator.activate);
assert.isFalse(activator.canActivate);
});

it('activate and enabled act as aliases', () => {
const activator = new SimpleActivator();

assert.isTrue(activator.enabled);
assert.isTrue(activator.activate);
assert.isTrue(activator.canActivate);

activator.enabled = false;
assert.isFalse(activator.activate);
assert.isFalse(activator.canActivate);

activator.activate = true;
activator.canActivate = true;
assert.isTrue(activator.enabled);
});

Expand Down Expand Up @@ -86,7 +86,7 @@ describe("Activators", () => {

assert.isTrue(activator.enabled);
assert.isFalse(activator.conditionsMet);
assert.isFalse(activator.activate);
assert.isFalse(activator.canActivate);
assert.isNotOk(activator.activationTrigger);
});

Expand All @@ -101,7 +101,7 @@ describe("Activators", () => {

assert.isTrue(activator.enabled);
assert.isTrue(activator.conditionsMet);
assert.isTrue(activator.activate);
assert.isTrue(activator.canActivate);
assert.isOk(activator.activationTrigger);

assert.isTrue(activateStub.called);
Expand Down Expand Up @@ -230,4 +230,4 @@ describe("Activators", () => {
assert.deepStrictEqual(stub.firstCall.args[0], object);
});
});
});
});