Skip to content

Commit

Permalink
Add fullscreen system and update pointer system (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
jthomperoo authored Mar 4, 2020
1 parent 9147eb2 commit 90584d2
Show file tree
Hide file tree
Showing 16 changed files with 1,302 additions and 52 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Added `FullscreenSystem` to handle fullscreen events and pointer lock.
- `PointerSystem` supports pointer lock through the `FullscreenSystem`.
### Changed
- `KeyboardSystem` messages emitted use JS `KeyboardEvent.code` (physical keyboard) rather than `KeyboardEvent.key` (input character).
- `System` to store `SystemEntities` as a map rather than as an array, for easier random access.
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [FakeMessageBus](classes/fakemessagebus.md)
* [FakeScene](classes/fakescene.md)
* [FakeSubscriber](classes/fakesubscriber.md)
* [FullscreenSystem](classes/fullscreensystem.md)
* [GJKSimplex](classes/gjksimplex.md)
* [Game](classes/game.md)
* [ImageAsset](classes/imageasset.md)
Expand All @@ -45,6 +46,7 @@
* [Subscriber](classes/subscriber.md)
* [System](classes/system.md)
* [SystemEntity](classes/systementity.md)
* [TestFullscreenSystem](classes/testfullscreensystem.md)
* [TestGame](classes/testgame.md)
* [TestKeyboardSystem](classes/testkeyboardsystem.md)
* [TestPointerSystem](classes/testpointersystem.md)
Expand Down
247 changes: 247 additions & 0 deletions docs/reference/classes/fullscreensystem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@

# Class: FullscreenSystem

FullscreenSystem handles JS fullscreen change events, and provides a method for requesting
entering/existing fullscreen/pointer lock.

## Hierarchy

[System](system.md)

**FullscreenSystem**

[TestFullscreenSystem](testfullscreensystem.md)

## Implements

* [ISubscriber](../interfaces/isubscriber.md)

## Index

### Constructors

* [constructor](fullscreensystem.md#constructor)

### Properties

* [canvas](fullscreensystem.md#private-canvas)
* [document](fullscreensystem.md#private-document)
* [entities](fullscreensystem.md#protected-entities)
* [messageBus](fullscreensystem.md#protected-messagebus)
* [scene](fullscreensystem.md#protected-optional-scene)
* [subscriberID](fullscreensystem.md#subscriberid)
* [MESSAGE_DEREGISTER](fullscreensystem.md#static-message_deregister)
* [MESSAGE_ENTER_FULLSCREEN](fullscreensystem.md#static-message_enter_fullscreen)
* [MESSAGE_EXIT_FULLSCREEN](fullscreensystem.md#static-message_exit_fullscreen)
* [MESSAGE_REGISTER](fullscreensystem.md#static-message_register)
* [MESSAGE_REQUEST_ENTER_FULLSCREEN](fullscreensystem.md#static-message_request_enter_fullscreen)
* [MESSAGE_REQUEST_EXIT_FULLSCREEN](fullscreensystem.md#static-message_request_exit_fullscreen)
* [MESSAGE_UPDATE](fullscreensystem.md#static-message_update)

### Methods

* [Destroy](fullscreensystem.md#destroy)
* [OnDestroy](fullscreensystem.md#protected-ondestroy)
* [OnMessage](fullscreensystem.md#onmessage)
* [Update](fullscreensystem.md#protected-update)
* [onFullscreenChange](fullscreensystem.md#protected-onfullscreenchange)

## Constructors

### constructor

\+ **new FullscreenSystem**(`messageBus`: [IMessageBus](../interfaces/imessagebus.md), `canvas`: HTMLCanvasElement, `document`: HTMLDocument, `__namedParameters`: object): *[FullscreenSystem](fullscreensystem.md)*

*Overrides [System](system.md).[constructor](system.md#constructor)*

**Parameters:**

**messageBus**: *[IMessageBus](../interfaces/imessagebus.md)*

**canvas**: *HTMLCanvasElement*

**document**: *HTMLDocument*

`Default value` **__namedParameters**: *object*= { scene: undefined, entities: new Map(), subscriberID: undefined }

Name | Type |
------ | ------ |
`entities` | Map‹number, [SystemEntity](systementity.md)‹›› |
`scene` | undefined | [IScene](../interfaces/iscene.md) |
`subscriberID` | undefined | number |

**Returns:** *[FullscreenSystem](fullscreensystem.md)*

## Properties

### `Private` canvas

**canvas**: *HTMLCanvasElement*

___

### `Private` document

**document**: *HTMLDocument*

___

### `Protected` entities

**entities**: *Map‹number, [SystemEntity](systementity.md)*

*Inherited from [System](system.md).[entities](system.md#protected-entities)*

___

### `Protected` messageBus

**messageBus**: *[IMessageBus](../interfaces/imessagebus.md)*

*Inherited from [System](system.md).[messageBus](system.md#protected-messagebus)*

___

### `Protected` `Optional` scene

**scene**? : *[IScene](../interfaces/iscene.md)*

*Inherited from [System](system.md).[scene](system.md#protected-optional-scene)*

___

### subscriberID

**subscriberID**: *number*

*Implementation of [ISubscriber](../interfaces/isubscriber.md).[subscriberID](../interfaces/isubscriber.md#subscriberid)*

*Inherited from [Subscriber](subscriber.md).[subscriberID](subscriber.md#subscriberid)*

___

### `Static` MESSAGE_DEREGISTER

**MESSAGE_DEREGISTER**: *"system_deregister"* = "system_deregister"

*Inherited from [System](system.md).[MESSAGE_DEREGISTER](system.md#static-message_deregister)*

___

### `Static` MESSAGE_ENTER_FULLSCREEN

**MESSAGE_ENTER_FULLSCREEN**: *"message_enter_fullscreen"* = "message_enter_fullscreen"

___

### `Static` MESSAGE_EXIT_FULLSCREEN

**MESSAGE_EXIT_FULLSCREEN**: *"message_exit_fullscreen"* = "message_exit_fullscreen"

___

### `Static` MESSAGE_REGISTER

**MESSAGE_REGISTER**: *"system_register"* = "system_register"

*Inherited from [System](system.md).[MESSAGE_REGISTER](system.md#static-message_register)*

___

### `Static` MESSAGE_REQUEST_ENTER_FULLSCREEN

**MESSAGE_REQUEST_ENTER_FULLSCREEN**: *"message_request_enter_fullscreen"* = "message_request_enter_fullscreen"

___

### `Static` MESSAGE_REQUEST_EXIT_FULLSCREEN

**MESSAGE_REQUEST_EXIT_FULLSCREEN**: *"message_request_exit_fullscreen"* = "message_request_exit_fullscreen"

___

### `Static` MESSAGE_UPDATE

**MESSAGE_UPDATE**: *"system_update"* = "system_update"

*Inherited from [System](system.md).[MESSAGE_UPDATE](system.md#static-message_update)*

## Methods

### Destroy

**Destroy**(): *void*

*Inherited from [System](system.md).[Destroy](system.md#destroy)*

Destroy destroys the System and unsubscribes it from all messages.
The System should be garbage collected after this, unless a direct
reference to it exists somewhere. Therefore direct references to
systems are discouraged; communication should all be through the
message bus.

**Returns:** *void*

___

### `Protected` OnDestroy

**OnDestroy**(): *void*

*Inherited from [System](system.md).[OnDestroy](system.md#protected-ondestroy)*

Custom Destroy logic should go here to facilitate garbage collection, for example
removing listeners.

**Returns:** *void*

___

### OnMessage

**OnMessage**(`message`: [IMessage](../interfaces/imessage.md)): *void*

*Overrides [System](system.md).[OnMessage](system.md#onmessage)*

**Parameters:**

Name | Type |
------ | ------ |
`message` | [IMessage](../interfaces/imessage.md) |

**Returns:** *void*

___

### `Protected` Update

**Update**(`dt`: number): *void*

*Inherited from [System](system.md).[Update](system.md#protected-update)*

General update method, default empty. Override with custom logic.

**Parameters:**

Name | Type | Description |
------ | ------ | ------ |
`dt` | number | DeltaTime |

**Returns:** *void*

___

### `Protected` onFullscreenChange

**onFullscreenChange**(`event`: Event): *void*

When a fullsceenchange event occurs this method is called, handles forwarding the fullscreen events
into the JamJar ECS messaging system.

**Parameters:**

Name | Type | Description |
------ | ------ | ------ |
`event` | Event | The fullscreenchange event |

**Returns:** *void*
22 changes: 18 additions & 4 deletions docs/reference/classes/pointersystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ PointerSystem handles Pointer (mouse, touch etc.) input events, converting them

* [entities](pointersystem.md#protected-entities)
* [inputElement](pointersystem.md#private-inputelement)
* [isFullscreen](pointersystem.md#private-isfullscreen)
* [lockedPointerPosition](pointersystem.md#private-lockedpointerposition)
* [messageBus](pointersystem.md#protected-messagebus)
* [pointers](pointersystem.md#private-pointers)
* [scene](pointersystem.md#protected-optional-scene)
Expand Down Expand Up @@ -56,11 +58,13 @@ PointerSystem handles Pointer (mouse, touch etc.) input events, converting them

**inputElement**: *HTMLElement*

`Default value` **__namedParameters**: *object*= { scene: undefined, entities: new Map(), subscriberID: undefined, pointers: [] }
`Default value` **__namedParameters**: *object*= { scene: undefined, entities: new Map(), subscriberID: undefined, pointers: [], isFullscreen: false, lockedPointerPosition: undefined }

Name | Type |
------ | ------ |
`entities` | Map‹number, [SystemEntity](systementity.md)‹›› |
`isFullscreen` | boolean |
`lockedPointerPosition` | undefined | [Vector](vector.md)‹› |
`pointers` | [string, [Pointer](pointer.md)‹›][] |
`scene` | undefined | [IScene](../interfaces/iscene.md) |
`subscriberID` | undefined | number |
Expand All @@ -83,6 +87,18 @@ ___

___

### `Private` isFullscreen

**isFullscreen**: *boolean*

___

### `Private` lockedPointerPosition

**lockedPointerPosition**: *[Vector](vector.md) | undefined*

___

### `Protected` messageBus

**messageBus**: *[IMessageBus](../interfaces/imessagebus.md)*
Expand Down Expand Up @@ -172,9 +188,7 @@ ___

**OnMessage**(`message`: [IMessage](../interfaces/imessage.md)): *void*

*Inherited from [System](system.md).[OnMessage](system.md#onmessage)*

*Overrides [Subscriber](subscriber.md).[OnMessage](subscriber.md#abstract-onmessage)*
*Overrides [System](system.md).[OnMessage](system.md#onmessage)*

**Parameters:**

Expand Down
2 changes: 2 additions & 0 deletions docs/reference/classes/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ A system is for implementing logic, manipulating entities and their components.

[CollisionSystem](collisionsystem.md)

[FullscreenSystem](fullscreensystem.md)

[ImageSystem](imagesystem.md)

[InterpolationSystem](interpolationsystem.md)
Expand Down
Loading

0 comments on commit 90584d2

Please sign in to comment.