revert gameManager

This commit is contained in:
k8w 2021-12-28 23:26:15 +08:00
parent 5a6ae0b679
commit 5818604b4d
28 changed files with 93 additions and 127 deletions

View File

@ -12,7 +12,6 @@
"devDependencies": {
"@types/mocha": "^8.2.3",
"@types/node": "^15.14.9",
"@types/seedrandom": "^3.0.1",
"mocha": "^9.1.3",
"onchange": "^7.1.0",
"ts-node": "^10.4.0",
@ -20,7 +19,6 @@
"typescript": "^4.5.4"
},
"dependencies": {
"seedrandom": "^3.0.5",
"tsrpc": "^3.1.4"
}
}

View File

@ -1,9 +1,9 @@
import { ApiCallWs } from "tsrpc";
import { ApiCall } from "tsrpc";
import { ReqLogin, ResLogin } from "../shared/protocols/PtlLogin";
let nextPlayerId = 1;
export async function ApiLogin(call: ApiCallWs<ReqLogin, ResLogin>) {
export async function ApiLogin(call: ApiCall<ReqLogin, ResLogin>) {
let playerId = nextPlayerId++;
call.conn.currentUser = {

View File

@ -1,7 +1,9 @@
import 'k8w-extend-native';
import * as path from "path";
import { WsServer } from "tsrpc";
import { Room } from './models/Room';
import { serviceProto } from './shared/protocols/serviceProto';
import { CurrentUser } from './shared/types/CurrentUser';
// Create the Server
export const server = new WsServer(serviceProto, {
@ -24,3 +26,11 @@ async function main() {
await server.start();
}
main();
// 扩展 Connection 字段
declare module 'tsrpc' {
export interface BaseConnection {
currentUser: CurrentUser,
room?: Room,
}
}

View File

@ -1,4 +1,3 @@
import seedrandom from "seedrandom";
import { MsgCallWs, uint, WsConnection } from "tsrpc";
import { server } from "..";
import { gameConfig } from "../shared/game/gameConfig";
@ -6,7 +5,6 @@ import { GameSystemInput } from "../shared/game/GameSystemInput";
import { GameSystemState } from "../shared/game/GameSystemState";
import { MsgGameInput } from "../shared/protocols/game/client/MsgGameInput";
import { ServiceType } from "../shared/protocols/serviceProto";
import { CurrentUser } from "../shared/types/CurrentUser";
import { RoomState } from "../shared/types/RoomState";
const MAX_ROOM_USER = 2;
@ -111,8 +109,6 @@ export class Room {
this._syncRoomState();
// 生成游戏初始状态
let seed = '' + Math.random();
let prng = seedrandom(seed, { state: true });
let initGameState: GameSystemState = {
now: 0,
players: this.conns.map(v => ({
@ -137,13 +133,7 @@ export class Room {
},
// 上次创建敌机的时间
lastCreateEnemyTime: 3000,
// 伪随机数发生器状态
random: {
seed: '' + Math.random(),
state: prng.state()
}
lastCreateEnemyTime: 3000
};
this._lastSn = {};
this._lastSyncTime = Date.now();
@ -196,10 +186,3 @@ export class Room {
// #endregion
}
declare module 'tsrpc' {
export interface BaseConnection {
currentUser: CurrentUser,
room?: Room,
}
}

View File

@ -1,4 +1,3 @@
import seedrandom from "seedrandom";
import { gameConfig } from "./gameConfig";
import { GameSystemEvent } from "./GameSystemEvent";
import { GameSystemInput } from "./GameSystemInput";
@ -16,12 +15,8 @@ export class GameSystem {
}
set state(state: GameSystemState) {
this._state = state;
this._seedRandom = seedrandom(state.random.seed, state.random.state);
}
// 伪随机数发生器
private _seedRandom!: ReturnType<seedrandom>;
constructor(state: GameSystemState) {
this.state = state;
}
@ -135,11 +130,11 @@ export class GameSystem {
}
let time = this.state.now - (this.state.now % gameConfig.enemy.bornGapTime);
let pos = { x: this._random() * 750 - 375, y: gameConfig.enemy.bornY };
let pos = { x: 0, y: gameConfig.enemy.bornY };
let enemy: EnemyState = {
id: this.state.nextId.enemy++,
// 敌机类型
type: this._random() > 0.5 ? EnemyType.E1 : EnemyType.E2,
type: EnemyType.E1,
pos: { ...pos },
init: {
time: time,
@ -156,12 +151,6 @@ export class GameSystem {
this.state.enemies.push(enemy);
}
private _random(): number {
let rand = this._seedRandom();
this.state.random.state = this._seedRandom.state();
return rand;
}
// 简易的事件侦听器
private _eventHandlers: { [key: string]: Function[] } = {};
on<T extends keyof GameSystemEvent>(eventName: T, handler: (e: GameSystemEvent[T]) => void): (e: GameSystemEvent[T]) => void {

View File

@ -1,4 +1,4 @@
import { uint } from "tsrpc";
import { uint } from "tsrpc-proto";
export interface GameSystemEvent {
playerDie: {

View File

@ -1,4 +1,4 @@
import { uint } from "tsrpc";
import { uint } from "tsrpc-proto";
// 坐标系X-Y 原点在中间下方
/*
@ -26,12 +26,6 @@ export interface GameSystemState {
// 上次创建敌机的时间
lastCreateEnemyTime: number,
// 伪随机数发生器状态
random: {
seed: string,
state: object
}
}

View File

@ -1,4 +1,4 @@
import { uint } from "tsrpc";
import { uint } from "tsrpc-proto";
import { GameSystemState } from "../../../game/GameSystemState";
export interface MsgGameStart {

View File

@ -1,4 +1,4 @@
import { uint } from "tsrpc";
import { uint } from "tsrpc-proto";
import { GameSystemInput } from "../../../game/GameSystemInput";
/**

View File

@ -43,7 +43,7 @@ export interface ServiceType {
}
export const serviceProto: ServiceProto<ServiceType> = {
"version": 3,
"version": 4,
"services": [
{
"id": 11,
@ -701,29 +701,6 @@ export const serviceProto: ServiceProto<ServiceType> = {
"type": {
"type": "Number"
}
},
{
"id": 6,
"name": "random",
"type": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "seed",
"type": {
"type": "String"
}
},
{
"id": 1,
"name": "state",
"type": {
"type": "Object"
}
}
]
}
}
]
},

View File

@ -1,4 +1,4 @@
import { uint } from "tsrpc";
import { uint } from "tsrpc-proto";
export interface CurrentUser {
id: uint,

View File

@ -16,7 +16,7 @@ const tsrpcConf: TsrpcConfig = {
sync: [
{
from: 'src/shared',
to: '../frontend/assets/scripts/shared',
to: '../frontend/assets/script/shared',
type: 'symlink' // Change this to 'copy' if your environment not support symlink
}
],

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "462c5922-0190-42df-a20e-963ccd552d2f",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -1,12 +1,12 @@
import { WsClient } from "tsrpc-browser";
import { GameSystem } from "../scripts/shared/game/GameSystem";
import { GameSystemState } from "../scripts/shared/game/GameSystemState";
import { ClientInput, MsgGameInput } from "../scripts/shared/protocols/game/client/MsgGameInput";
import { MsgGameStart } from "../scripts/shared/protocols/game/server/MsgGameStart";
import { MsgServerFrame } from "../scripts/shared/protocols/game/server/MsgServerFrame";
import { serviceProto, ServiceType } from "../scripts/shared/protocols/serviceProto";
import { CurrentUser } from "../scripts/shared/types/CurrentUser";
import { RoomState } from "../scripts/shared/types/RoomState";
import { GameSystem } from "../script/shared/game/GameSystem";
import { GameSystemState } from "../script/shared/game/GameSystemState";
import { ClientInput, MsgGameInput } from "../script/shared/protocols/game/client/MsgGameInput";
import { MsgGameStart } from "../script/shared/protocols/game/server/MsgGameStart";
import { MsgServerFrame } from "../script/shared/protocols/game/server/MsgServerFrame";
import { serviceProto, ServiceType } from "../script/shared/protocols/serviceProto";
import { CurrentUser } from "../script/shared/types/CurrentUser";
import { RoomState } from "../script/shared/types/RoomState";
/**
*

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "3a083653-ef15-4e15-a5a4-12b96b55a050",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -1,7 +1,7 @@
import { _decorator, Component, Node, Collider, find, ITriggerEvent, Script } from 'cc';
import { Collider, Component, ITriggerEvent, _decorator } from 'cc';
import { Constant } from '../framework/constant';
import { GameManager } from '../GameController';
import { GameManager } from '../gameManager';
const { ccclass, property } = _decorator;

View File

@ -1,7 +1,7 @@
import { _decorator, Component, Node, Collider, ITriggerEvent } from 'cc';
import { Collider, Component, ITriggerEvent, _decorator } from 'cc';
import { Constant } from '../framework/constant';
import { GameManager } from '../GameController';
import { GameManager } from '../gameManager';
const { ccclass, property } = _decorator;

View File

@ -1,4 +1,4 @@
import { _decorator, sys, log } from "cc";
import { log, sys, _decorator } from "cc";
import { Util } from './util';
const { ccclass, property } = _decorator;
@ -49,7 +49,7 @@ export class StorageManager {
if (content && content.length) {
if (content.startsWith('@')) {
content = content.substring(1);
content = util.decrypt(content);
content = Util.decrypt(content);
}
try {
@ -201,6 +201,7 @@ export class StorageManager {
var valueObj: any = {};
valueObj[this.KEY_CONFIG] = zipStr;
// @ts-ignore
jsb.fileUtils.writeToFile(valueObj, this._path);
// jsb.fileUtils.writeToFile(valueObj);
}

View File

@ -761,11 +761,11 @@ export class Util {
*
*/
public static checkIsLowPhone(): Boolean {
if (window.wx) {
if ((window as any).wx) {
//微信性能数值参考:https://developers.weixin.qq.com/minigame/dev/guide/performance/perf-benchmarkLevel.html
let nowBenchmarkLevel: number = -1; //nowBenchmarkLevel = -1性能未知
const sys = window.wx.getSystemInfoSync();
const sys = (window as any).wx.getSystemInfoSync();
const isIOS = sys.system.indexOf('iOS') >= 0;
if (isIOS) {
//微信不支持IO性能等级

View File

@ -16,8 +16,8 @@ let _temp_quat = new Quat;
@ccclass('GameController')
export class GameController extends Component {
@ccclass('GameManager')
export class GameManager extends Component {
@property(Node)
public playerPlane: Node = null; //玩家飞机节点

View File

@ -1,8 +1,7 @@
import { _decorator, Component, Node, Collider, ITriggerEvent, physics, PhysicsSystem, find, Game, Prefab, NodePool, instantiate, Vec2, Vec3, AudioSource } from 'cc';
import { bulletManager } from '../bullet/bulletManager';
import { AudioSource, Collider, Component, ITriggerEvent, Node, Vec3, _decorator } from 'cc';
import { Constant } from '../framework/constant';
import { GameManager } from '../GameController';
import { GameManager } from '../gameManager';
const { ccclass, property } = _decorator;

View File

@ -1,7 +1,7 @@
import { _decorator, Component, Node, Collider, ITriggerEvent } from 'cc';
import { Constant } from '../framework/constant';
import { GameManager } from '../GameController';
import { GameManager } from '../gameManager';
const { ccclass, property } = _decorator;

View File

@ -2,7 +2,7 @@
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "5fd42ea5-0316-4e48-86e1-1bcdba894b1c",
"uuid": "f2949899-5bbd-4e1e-b02a-f763b5978ef9",
"files": [],
"subMetas": {},
"userData": {

View File

@ -1,6 +1,6 @@
import { _decorator, Component, Node, UITransform, Vec2, Vec3, find, Script, game, Label, CameraComponent, Camera, EventTouch, v3 } from 'cc';
import { GameManager } from '../GameController';
import { GameManager } from '../gameManager';
import { MovingSceneBg } from './common/movingSceneBg';
import { Tips } from './common/tips';

View File

@ -7,10 +7,6 @@
"uuid": "c794458c-05f6-4c9f-909b-20d54897d219",
"version": "3.4.0",
"dependencies": {
"seedrandom": "^3.0.5",
"tsrpc-browser": "^3.1.4"
},
"devDependencies": {
"@types/seedrandom": "^3.0.1"
}
}

View File

@ -4,6 +4,7 @@
/* Add your custom configuration here. */
"compilerOptions": {
"strict": false,
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
}
}