Commit c2e93616 authored by Master Q's avatar Master Q

添加配置项 + NewEventDispatcher

parent 27d4b17d
This diff is collapsed.
This diff is collapsed.
resource/skybox/nx1.jpg

147 KB | W: | H:

resource/skybox/nx1.jpg

44.3 KB | W: | H:

resource/skybox/nx1.jpg
resource/skybox/nx1.jpg
resource/skybox/nx1.jpg
resource/skybox/nx1.jpg
  • 2-up
  • Swipe
  • Onion skin
resource/skybox/ny1.jpg

233 KB | W: | H:

resource/skybox/ny1.jpg

80.3 KB | W: | H:

resource/skybox/ny1.jpg
resource/skybox/ny1.jpg
resource/skybox/ny1.jpg
resource/skybox/ny1.jpg
  • 2-up
  • Swipe
  • Onion skin
resource/skybox/nz1.jpg

126 KB | W: | H:

resource/skybox/nz1.jpg

37.6 KB | W: | H:

resource/skybox/nz1.jpg
resource/skybox/nz1.jpg
resource/skybox/nz1.jpg
resource/skybox/nz1.jpg
  • 2-up
  • Swipe
  • Onion skin
resource/skybox/px1.jpg

141 KB | W: | H:

resource/skybox/px1.jpg

44.5 KB | W: | H:

resource/skybox/px1.jpg
resource/skybox/px1.jpg
resource/skybox/px1.jpg
resource/skybox/px1.jpg
  • 2-up
  • Swipe
  • Onion skin
resource/skybox/py1.jpg

75.8 KB | W: | H:

resource/skybox/py1.jpg

22.1 KB | W: | H:

resource/skybox/py1.jpg
resource/skybox/py1.jpg
resource/skybox/py1.jpg
resource/skybox/py1.jpg
  • 2-up
  • Swipe
  • Onion skin
resource/skybox/pz1.jpg

144 KB | W: | H:

resource/skybox/pz1.jpg

44.5 KB | W: | H:

resource/skybox/pz1.jpg
resource/skybox/pz1.jpg
resource/skybox/pz1.jpg
resource/skybox/pz1.jpg
  • 2-up
  • Swipe
  • Onion skin
......@@ -11,5 +11,6 @@ fs.writeFileSync(endPath + "output.js",
// 'import * as FYGE from "fyge-tbmini";\n' +
// 'import * as FYGE from "fyge";\n' +//以后改成这个
// 'import * as SvgaParser from "svga-parser";\n' +
'/* eslint-disable */\n' +
fs.readFileSync("./output.js"));
console.log("js生成")
......@@ -6,6 +6,7 @@ export const GameConfig = {
helperDebuger: false,
collisionDebuger: false,
initVehiclePos: new THREE.Vector3(0, 3, 0),
maxSpeed: 80,
CameraPosConfig: (function() {
let posList = [
0, 8, -20,
......
......@@ -13,7 +13,7 @@ import { RES } from "../module/RES";
import { GameConfig } from "./GameConfig";
import { Dom } from "./dom";
import { ResJson } from "../ResJson";
import { GDispather } from "..";
import { GDispather } from "../message";
function gradTexture(color: [number[], string[]]) {
var c = document.createElement("canvas");
......@@ -324,10 +324,13 @@ export class CarScene extends PerspectiveScene {
},
styles: {
backgroundImage: `url(${ResJson.path}UI/left-icon.png)`,
backgroundSize: '100% 100%',
backgroundSize: 'contain',
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat',
width: `${70 * remScale}px`,
height: `${126 * remScale}px`,
marginLeft: '40px'
marginLeft: '60px',
padding: '0 20px'
},
events: {
touchstart: {
......@@ -349,10 +352,13 @@ export class CarScene extends PerspectiveScene {
},
styles: {
backgroundImage: `url(${ResJson.path}UI/right-icon.png)`,
backgroundSize: '100% 100%',
backgroundSize: 'contain',
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat',
width: `${70 * remScale}px`,
height: `${126 * remScale}px`,
marginLeft: '40px'
marginLeft: '40px',
padding: '0 20px'
},
events: {
touchstart: {
......@@ -386,7 +392,9 @@ export class CarScene extends PerspectiveScene {
},
styles: {
backgroundImage: `url(${ResJson.path}UI/brake-icon.png)`,
backgroundSize: '100% 100%',
backgroundSize: 'contain',
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat',
width: `${102 * remScale}px`,
height: `${150 * remScale}px`,
},
......@@ -820,6 +828,9 @@ export class CarScene extends PerspectiveScene {
set currDistance(v: number) {
this._currDistance = v
GDispather.dispatchEvent('distanceUpdateSync', {
distance: v
})
}
onEnterFrame(e: any) {
......@@ -872,6 +883,9 @@ export class CarScene extends PerspectiveScene {
onGameSubmit(n: number) {
console.log('当前分数:', Math.abs(n))
GDispather.dispatchEvent('distanceUpdate', {
distance: Math.abs(n)
})
if (this.UICtn.querySelector('.tips')) {
this.UICtn.querySelector('.tips').textContent = '当前提交分数:' + Math.abs(n).toFixed(2)
}
......
......@@ -4,6 +4,7 @@ import { EventDispatcher } from "../module/EventDispatcher";
import { GLTFLoader } from '../module/loaders/GLTFLoader';
import { PreloadGroup } from '../module/UI/PreloadGroup/PreloadGroup';
import { RES } from '../module/RES';
import { GameConfig } from './GameConfig';
const materialDynamic = new THREE.MeshPhongMaterial( { color:0xfca400 } );
const materialStatic = new THREE.MeshPhongMaterial( { color:0x999999 } );
......@@ -287,7 +288,7 @@ export class Vehicle extends PreloadGroup{
// }
// 最大速度
if (speed < 80) {
if (speed < GameConfig.maxSpeed) {
if (isAccelerating) {
stopFlag = false
if (speed < -1) {
......
......@@ -2,10 +2,15 @@ import { CarScene } from "./CarScene"
import * as THREE from 'three'
import { RES } from "./module/RES"
import { ResJson } from "./ResJson"
import { EventDispatcher } from "./module/EventDispatcher"
window['THREE'] = THREE
export const loadAllGroup = function() {
RES.loadConfig(ResJson)
return RES.loadAllGroup()
}
export * from './message'
export class StageScene {
renderDom: HTMLCanvasElement
stage: CarScene
......@@ -34,11 +39,3 @@ export class StageScene {
this.stage.destroy()
}
}
\ No newline at end of file
type GDType = {
'orientationChange': {
isPortrait: boolean // 是否是竖屏
}
}
export const GDispather = new EventDispatcher<keyof GDType>()
\ No newline at end of file
import { NewEventDispatcher } from "./module/NewEventDispatcher"
type GDType = {
'orientationChange': {
isPortrait: boolean // 是否是竖屏
},
'distanceUpdate': {
distance: number
},
'resetVehicle': any,
'changeCameraPos': any,
'distanceUpdateSync': {
distance: number
}
}
export const GDispather = new NewEventDispatcher<GDType>()
\ No newline at end of file
// type BaseEventMap = {
// [eventName: string]: any
// }
type BaseEventMap = {
[eventName: string]: any
}
type EventCall<T extends any, S extends any = any, U extends any = any> = (this: S, e?: {
type: T,
data: U
}) => any
// type BaseEvent = {
// type: string
......@@ -8,14 +13,99 @@
// type AddRecordArgs2<T extends Record<string, any>, E extends >
// /**
// * Event object.
// */
/**
* Event object.
*/
// export interface Event extends BaseEvent {
// target?: any;
// [attachment: string]: any;
// }
// export class NewEventDispatcher<E extends BaseEventMap> {
export class NewEventDispatcher<E extends BaseEventMap> {
private listeners: {
[key in keyof E]?: {
listener: EventCall<key>,
context: any
}[]
}
constructor() {
this.listeners = Object.create(null)
}
addEventListener<T extends keyof E, S extends any>(type: T, listener: EventCall<T, S, E[T]>, context?: S) {
if (!this.listeners[type]) {
this.listeners[type] = []
}
this.listeners[type]!.push({
listener,
context
})
}
removeEventListener<T extends keyof E, S extends any>(type: T, listener: EventCall<T, S, E[T]>, context?: S) {
if (!this.listeners[type]) {
return
}
const cbs = this.listeners[type]!
let i = cbs.length - 1
while (i >= 0) {
const cb = cbs[i]
if (cb.listener === listener && cb.context === context) {
cbs.splice(i, 1)
}
i --
}
}
removeAllEventListener() {
this.listeners = Object.create(null)
}
onceEventListener<T extends keyof E, S extends any>(type: T, listener: EventCall<T, S, E[T]>, context?: S) {
const once = (e: any) => {
listener.call(context, e)
this.removeEventListener(type, once)
}
this.addEventListener(type, once, this)
}
dispatchEvent<T extends keyof E>(type: T, args: E[T]) {
if (!this.listeners[type]) {
return
}
const array = this.listeners[type].slice(0)
array.forEach(item => {
const {
listener,
context
} = item
listener.call(context, {
type,
data: args
})
})
}
}
// type t1 = {
// 'test1': {
// t: boolean
// },
// 'test2': boolean
// }
// type EnumType = keyof t1
// const tt = new NewEventDispatcher<t1>()
// tt.onceEventListener('test1', function (e) {
// this.a = 2
// e.data = 1
// }, {
// a: 2
// })
// tt.dispatchEvent('test1', {
// t: false
// })
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment