Skip to content

Commit 78ceba7

Browse files
committed
renamed entities -> ENTITIES. fixed StateHandler.
1 parent 7819a28 commit 78ceba7

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

taptapir.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ function set_orientation(value) {
9696
if (value == 'horizontal') {
9797
ASPECT_RATIO = 16/9
9898
}
99+
if (value == 'auto') {
100+
var width = window.innerWidth
101+
var height = window.innerHeight
102+
ASPECT_RATIO = width / height
103+
}
99104
set_aspect_ratio(ASPECT_RATIO)
100105
}
101106

@@ -304,7 +309,7 @@ curves = {
304309

305310
ASSETS_FOLDER = ''
306311
TAPTAPIR_TEXTURES = {}
307-
entities = []
312+
ENTITIES = []
308313
AUTOPARENT_TO_SCENE = true
309314
LAST_SCENE = null
310315
DEFAULT_FONT = null
@@ -321,7 +326,7 @@ class Entity {
321326
}
322327
if (!this.add_to_scene) {
323328
this.el = document.createElement(options['type'])
324-
entities.push(this)
329+
ENTITIES.push(this)
325330
for (const [key, value] of Object.entries(options)) {
326331
this[key] = value
327332
}
@@ -343,13 +348,13 @@ class Entity {
343348
this.el.style.backgroundColor = 'rgba(0,0,0,0)'
344349
// this.el.style.pointerEvents = 'none'
345350
this.model = document.createElement(options['type'])
346-
this.model.entity_index = entities.length
351+
this.model.entity_index = ENTITIES.length
347352
this.model.id = 'model'
348353
this.el.appendChild(this.model)
349354

350355
this.model.className = options['type']
351356
this.model.style.opacity = 1
352-
entities.push(this)
357+
ENTITIES.push(this)
353358

354359
this.setTimeout_calls = {}
355360
if (!('render' in options) || options['render']) {
@@ -1096,13 +1101,14 @@ class StateHandler {
10961101
else {
10971102
this.hard_state = value
10981103
}
1104+
this._state = value
10991105
}
11001106
set hard_state(value) { // set the state without fading
11011107
// print('set state to:', value)
11021108
if (this._state === value) {
11031109
return
11041110
}
1105-
for (let entity of this.states) {
1111+
for (let entity of this.states.values()) {
11061112
if (value === entity || value === entity.name) {
11071113
entity.enabled = true
11081114
if (entity.on_enter) {
@@ -1279,7 +1285,7 @@ time_of_press = 0
12791285
function _handle_mouse_click(e) {
12801286
// mouse.left = true
12811287
element_hit = document.elementFromPoint(e.pageX - window.pageXOffset, e.pageY - window.pageYOffset);
1282-
entity = entities[element_hit.entity_index]
1288+
entity = ENTITIES[element_hit.entity_index]
12831289
// print(element_hit, entity.on_click)
12841290
if (!element_hit || entity === undefined || entity.on_click === undefined) {
12851291
mouse.swipe_start_position = mouse.position
@@ -1368,14 +1374,14 @@ function _onmousemove(pageX, pageY, clientX, clientY, pressure, target) {
13681374
// print(mouse.point)
13691375
}
13701376
element_hit = document.elementFromPoint(pageX - window.scrollX, pageY - window.scrollY);
1371-
_entity = entities[element_hit.entity_index]
1377+
_entity = ENTITIES[element_hit.entity_index]
13721378
if (_entity) {
13731379
mouse.hovered_entity = _entity
13741380
}
13751381
else {
13761382
mouse.hovered_entity = null
13771383
}
1378-
for (var e of entities) {
1384+
for (var e of ENTITIES) {
13791385
if (e.dragging) {
13801386
if (!e.lock_x) {
13811387
// print(mouse.x, e.start_offset[0])
@@ -1616,7 +1622,7 @@ function _step(_timestamp) {
16161622
update()
16171623
}
16181624

1619-
for (var e of entities) {
1625+
for (var e of ENTITIES) {
16201626
if (e.update && e.enabled) {
16211627
e.update()
16221628
}
@@ -1671,7 +1677,7 @@ function _input(event) {
16711677

16721678
if (key == 'left mouse up') {
16731679
// drop draggables
1674-
for (var e of entities) {
1680+
for (var e of ENTITIES) {
16751681
if (e.dragging) {
16761682
e.dragging = false
16771683
if (e.drop) {
@@ -1681,7 +1687,7 @@ function _input(event) {
16811687
}
16821688
}
16831689

1684-
for (var e of entities) {
1690+
for (var e of ENTITIES) {
16851691
if (e.input && e.enabled) {
16861692
e.input(key)
16871693
}

0 commit comments

Comments
 (0)