-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
341 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#loading { | ||
position: fixed; | ||
} | ||
|
||
#loading-text { | ||
margin-top: 20px; | ||
} | ||
|
||
#loading-text p { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
@property --progress { | ||
syntax: '<percentage>'; | ||
inherits: false; | ||
initial-value: 0%; | ||
} | ||
|
||
.g-progress { | ||
margin: auto; | ||
width: 240px; | ||
height: 5px; | ||
border-radius: 25px; | ||
background: linear-gradient( | ||
90deg, | ||
#fff, | ||
rgb(181, 233, 233) var(--progress), | ||
transparent 0 | ||
); | ||
border: 1px solid #eee; | ||
transition: 0.3s --progress; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
export type VisibleModeType = 'pc' | 'mobile'; | ||
export type allowKeyDownType = 'KeyW' | 'KeyS' | 'KeyA' | 'KeyD'; | ||
export default class ActionEvent extends EventDispatcher { | ||
mode: VisibleModeType = 'pc'; | ||
downDowning: { [key in allowKeyDownType]: boolean } = { | ||
KeyW: false, | ||
KeyA: false, | ||
KeyD: false, | ||
KeyS: false, | ||
}; | ||
private _allowKeyDown: allowKeyDownType[] = ['KeyW', 'KeyS', 'KeyA', 'KeyD']; | ||
constructor() { | ||
super(); | ||
this._bindEvent(); | ||
} | ||
|
||
private _bindEvent() { | ||
if ('ontouchstart' in window) { | ||
this.mode = 'mobile'; | ||
// .... | ||
} else { | ||
this.mode = 'pc'; | ||
window.addEventListener('keydown', this._keydown.bind(this)); | ||
window.addEventListener('keyup', this._keyup.bind(this)); | ||
} | ||
} | ||
private _keyup(event: KeyboardEvent) { | ||
const { code } = event; | ||
if (this._allowKeyDown.includes(code)) { | ||
this.downDowning[code as allowKeyDownType] = false; | ||
} | ||
} | ||
private _keydown(event: KeyboardEvent) { | ||
const { code } = event; | ||
if (this._allowKeyDown.includes(code)) { | ||
this.downDowning[code as allowKeyDownType] = true; | ||
} else { | ||
this._actionEvent(code); | ||
} | ||
} | ||
|
||
private _actionEvent(code: string) { | ||
this.dispatchEvent({ type: 'action', message: { code } }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,32 @@ | ||
export type VisibleModeType = 'pc' | 'mobile'; | ||
export type allowKeyDownType = 'KeyW' | 'KeyS' | 'KeyA' | 'KeyD'; | ||
export default class Events extends EventDispatcher { | ||
mode: VisibleModeType = 'pc'; | ||
downDowning: { [key in allowKeyDownType]: boolean } = { | ||
KeyW: false, | ||
KeyA: false, | ||
KeyD: false, | ||
KeyS: false, | ||
}; | ||
private _allowKeyDown: allowKeyDownType[] = ['KeyW', 'KeyS', 'KeyA', 'KeyD']; | ||
constructor() { | ||
super(); | ||
this._bindEvent(); | ||
} | ||
import type { EventDispatcher } from 'three'; | ||
import ActionEvent from './action'; | ||
import UIEvents from './ui'; | ||
export default class Events { | ||
private static _instance: Events; | ||
private _events: { [key: string]: EventDispatcher } = {}; | ||
|
||
private _bindEvent() { | ||
if ('ontouchstart' in window) { | ||
this.mode = 'mobile'; | ||
// .... | ||
public static getStance(): Events { | ||
if (Events._instance) { | ||
return Events._instance; | ||
} else { | ||
this.mode = 'pc'; | ||
window.addEventListener('keydown', this._keydown.bind(this)); | ||
window.addEventListener('keyup', this._keyup.bind(this)); | ||
Events._instance = new Events(); | ||
} | ||
return Events._instance; | ||
} | ||
private _keyup(event: KeyboardEvent) { | ||
const { code } = event; | ||
if (this._allowKeyDown.includes(code)) { | ||
this.downDowning[code as allowKeyDownType] = false; | ||
} | ||
|
||
init() { | ||
this._registerEvents(new ActionEvent()); | ||
this._registerEvents(new UIEvents()); | ||
} | ||
private _keydown(event: KeyboardEvent) { | ||
const { code } = event; | ||
if (this._allowKeyDown.includes(code)) { | ||
this.downDowning[code as allowKeyDownType] = true; | ||
} else { | ||
this._actionEvent(code); | ||
|
||
private _registerEvents(event: EventDispatcher) { | ||
if (this._events[event.constructor.name]) { | ||
return; | ||
} | ||
this._events[event.constructor.name] = event; | ||
} | ||
|
||
private _actionEvent(code: string) { | ||
this.dispatchEvent({ type: 'action', message: { code } }); | ||
getEvent(name: string) { | ||
return this._events[name]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default class UIEvents extends EventDispatcher { | ||
constructor() { | ||
super(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.