Skip to content

Commit 09888b7

Browse files
committed
refactor(*): remove icon support (for now)
BREAKING CHANGE: `Control.icon` no longer exists.
1 parent 0ebc055 commit 09888b7

File tree

10 files changed

+5
-70
lines changed

10 files changed

+5
-70
lines changed

src/core/and.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ describe('The `and()` operator function', () => {
77

88
const controlA: Control<boolean> = {
99
label: '[A]',
10-
icons: ['a'],
1110
query: () => false,
1211
}
1312

1413
const controlB: Control<boolean> = {
1514
label: '[B]',
16-
icons: ['b'],
1715
query: () => true,
1816
}
1917

@@ -23,10 +21,6 @@ describe('The `and()` operator function', () => {
2321
expect(control.label).to.equal('[A] + [B]')
2422
})
2523

26-
it('correctly combines icons', () => {
27-
expect(control.icons).to.deep.equal(['a', 'plus', 'b'])
28-
})
29-
3024
it('makes the combined query work as expected', () => {
3125
expect(control.query()).to.equal(false)
3226
})

src/core/and.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export function and(...controls: Array<Control<boolean>>): Control<boolean> {
55

66
return {
77
label: controls.map(control => control.label).join(' + '),
8-
icons: [].concat(...controls.map(control => control.icons)).join('?plus?').split('?'),
98
query: () => {
109
for (const control of controls) {
1110
/* istanbul ignore else */

src/core/control.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ export interface Control<QueryType> {
22

33
label: string
44

5-
icons: string[]
6-
75
fromGamepad?: boolean
86

97
query(): QueryType

src/core/or.spec.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ describe('the `or()` operator function', () => {
88

99
const controlUndefined: Control<number> = {
1010
label: '',
11-
icons: [],
1211
query: () => undefined,
1312
}
1413

@@ -20,13 +19,11 @@ describe('the `or()` operator function', () => {
2019

2120
const controlTrue: Control<boolean> = {
2221
label: '',
23-
icons: [],
2422
query: () => true,
2523
}
2624

2725
const controlFalse: Control<boolean> = {
2826
label: '',
29-
icons: [],
3027
query: () => false,
3128
}
3229

@@ -48,13 +45,11 @@ describe('the `or()` operator function', () => {
4845

4946
const controlThree: Control<number> = {
5047
label: '',
51-
icons: [],
5248
query: () => 3,
5349
}
5450

5551
const controlFour: Control<number> = {
5652
label: '',
57-
icons: [],
5853
query: () => 4,
5954
}
6055

@@ -73,14 +68,12 @@ describe('the `or()` operator function', () => {
7368

7469
const controlGamepad: Control<number> = {
7570
label: 'gamepad',
76-
icons: ['gamepad'],
7771
query: null,
7872
fromGamepad: true,
7973
}
8074

8175
const controlNonGamepad: Control<number> = {
8276
label: 'non-gamepad',
83-
icons: ['non-gamepad'],
8477
query: null,
8578
}
8679

@@ -92,10 +85,6 @@ describe('the `or()` operator function', () => {
9285
expect(or(controlGamepad, controlNonGamepad).label).to.equal('non-gamepad')
9386
})
9487

95-
it('return the icons of the first non-gamepad control', () => {
96-
expect(or(controlGamepad, controlNonGamepad).icons[0]).to.equal('non-gamepad')
97-
})
98-
9988
})
10089

10190
describe('is `true`', () => {
@@ -106,28 +95,19 @@ describe('the `or()` operator function', () => {
10695
expect(or(controlGamepad, controlNonGamepad).label).to.equal('gamepad')
10796
})
10897

109-
it('return the icons of the first gamepad control', () => {
110-
expect(or(controlGamepad, controlNonGamepad).icons[0]).to.equal('gamepad')
111-
})
112-
11398
})
11499

115100
describe('is `true` or `false` and no gamepad control is passed in', () => {
116101

117102
const controlFirst: Control<number> = {
118103
label: 'first',
119-
icons: ['first'],
120104
query: null,
121105
}
122106

123107
it('return the label of the first control', () => {
124108
expect(or(controlFirst, controlNonGamepad).label).to.equal('first')
125109
})
126110

127-
it('return the icons of the first control', () => {
128-
expect(or(controlFirst, controlNonGamepad).label).to.equal('first')
129-
})
130-
131111
})
132112

133113
})

src/core/or.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,16 @@ import { store } from '../index'
22
import { Vector2 } from '../utils/math'
33
import { Control } from './control'
44

5-
const findPreferred = (controls: Array<Control<any>>, thing: string): any =>
6-
(controls.filter(control => control.fromGamepad).length === 0 ?
7-
controls[0]
8-
: store.preferGamepad ?
9-
controls.filter(control => control.fromGamepad === true)[0]
10-
: controls.filter(control => control.fromGamepad !== true)[0])[thing]
11-
125
export function or(...controls: Array<Control<any>>): Control<any> {
136
if (controls.length < 2) throw new Error('Less than two controls specified!')
147

158
return {
169
get label() {
17-
return findPreferred(controls, 'label')
18-
},
19-
get icons() {
20-
return findPreferred(controls, 'icons')
10+
return (controls.filter(control => control.fromGamepad).length === 0 ?
11+
controls[0]
12+
: store.preferGamepad ?
13+
controls.filter(control => control.fromGamepad === true)[0]
14+
: controls.filter(control => control.fromGamepad !== true)[0]).label
2115
},
2216
query: () => {
2317
let sampleQueryValue

src/inputs/gamepad.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export class Gamepad {
4949
public button(button: number, trigger = false): Control<boolean> {
5050
return {
5151
label: `(${button})`,
52-
icons: ['gamepad-button-' + button],
5352
fromGamepad: true,
5453
query: trigger ? () => {
5554
/* istanbul ignore else */

src/inputs/keyboard.spec.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ describe('The `Keyboard` class', () => {
3636
expect(keyboard.key('G').label).to.equal('G')
3737
})
3838

39-
it('returns the correct icon', () => {
40-
expect(keyboard.key('G').icons[0]).to.equal('keyboard-key-g')
41-
})
42-
4339
describe('when queried', () => {
4440

4541
it('returns `true` when the key is pressed', () => {
@@ -88,12 +84,6 @@ describe('The `Keyboard` class', () => {
8884
expect(keyboard.directionalKeys(['z', 'g', 'h', 'j']).label).to.equal('[ZGHJ]')
8985
})
9086

91-
it('returns the correct icon', () => {
92-
expect(keyboard.directionalKeys('wasd').icons[0]).to.equal('keyboard-directional-keys-wasd')
93-
expect(keyboard.directionalKeys('arrows').icons[0]).to.equal('keyboard-directional-keys-arrows')
94-
expect(keyboard.directionalKeys(['z', 'g', 'h', 'j']).icons[0]).to.equal('keyboard-directional-keys-zghj')
95-
})
96-
9787
it("throws an error when the passed in arrow key template doesn't exist", () => {
9888
expect(() => keyboard.directionalKeys('wsad').query()).to.throw(Error, 'Arrow key template "wsad" not found!')
9989
})

src/inputs/keyboard.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export class Keyboard {
4242
key = key.toLowerCase()
4343
return {
4444
label: key.toUpperCase(),
45-
icons: ['keyboard-key-' + key],
4645
query: () => {
4746
if (trigger) {
4847
if (this.queuedKeys.has(key)) {
@@ -73,7 +72,6 @@ export class Keyboard {
7372
const defaultLabel = `[${name.toUpperCase()}]`
7473
return {
7574
label: label || defaultLabel,
76-
icons: ['keyboard-directional-keys-' + name],
7775
query: () => {
7876
const vector = new Vector2()
7977
if (this.key(keys[0]).query()) vector.y -= 1

src/inputs/mouse.spec.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ describe('The `Mouse` class', () => {
7474
expect(mouse.button('right').label).to.equal('[RMB]')
7575
})
7676

77-
it('returns the correct icon for all three buttons', () => {
78-
expect(mouse.button('left').icons[0]).to.equal('left-mouse-button')
79-
expect(mouse.button('middle').icons[0]).to.equal('middle-mouse-button')
80-
expect(mouse.button('right').icons[0]).to.equal('right-mouse-button')
81-
})
82-
8377
it('when queried returns `true` the mouse button is pressed', () => {
8478
canvas.listeners.mousedown({ button: 0 })
8579
expect(mouse.button('left').query()).to.equal(true)
@@ -116,10 +110,6 @@ describe('The `Mouse` class', () => {
116110
expect(mouse.pointer().label).to.equal('Cursor')
117111
})
118112

119-
it('returns the correct icon', () => {
120-
expect(mouse.pointer().icons[0]).to.equal('mouse-pointer')
121-
})
122-
123113
describe('when queried', () => {
124114

125115
it('returns a (0, 0) vector if no movement occurred', () => {
@@ -151,10 +141,6 @@ describe('The `Mouse` class', () => {
151141
expect(mouse.wheel().label).to.equal('Mouse wheel')
152142
})
153143

154-
it('returns the correct icon', () => {
155-
expect(mouse.wheel().icons[0]).to.equal('mouse-wheel')
156-
})
157-
158144
describe('when queried', () => {
159145

160146
it('returns `0` if no scrolling occurred', () => {

src/inputs/mouse.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export class Mouse {
6868
button = this.parseButton(button)
6969
return {
7070
label: ['[LMB]', '[MMB]', '[RMB]'][button],
71-
icons: [['left-mouse-button', 'middle-mouse-button', 'right-mouse-button'][button]],
7271
query: () => {
7372
button = this.parseButton(button)
7473
if (trigger) {
@@ -87,7 +86,6 @@ export class Mouse {
8786
public pointer(): Control<Vector2> {
8887
return {
8988
label: 'Cursor',
90-
icons: ['mouse-pointer'],
9189
query: () => {
9290
const movement = this.pointerMovement
9391
this.pointerMovement = new Vector2(0, 0)
@@ -99,7 +97,6 @@ export class Mouse {
9997
public wheel() {
10098
return {
10199
label: 'Mouse wheel',
102-
icons: ['mouse-wheel'],
103100
query: () => {
104101
const distance = this.scrollDistance
105102
this.scrollDistance = 0

0 commit comments

Comments
 (0)