完善配置的加载
This commit is contained in:
parent
576f22786a
commit
eb085651d0
@ -6,10 +6,18 @@ export class SystemCardCfg implements Cfg {
|
|||||||
public count: number;
|
public count: number;
|
||||||
public point: number;
|
public point: number;
|
||||||
public weight: string;
|
public weight: string;
|
||||||
|
public weightArr: [];
|
||||||
public decode(data: any) {
|
public decode(data: any) {
|
||||||
this.id = data.id;
|
this.id = data.id;
|
||||||
this.typeId = data.type_id;
|
this.typeId = data.type_id;
|
||||||
this.point = data.point;
|
this.point = data.point;
|
||||||
this.weight = data.weight;
|
this.weight = data.weight;
|
||||||
|
let arr = this.weight.split('|');
|
||||||
|
this.weightArr = [];
|
||||||
|
for (let str of arr) {
|
||||||
|
let subArr = str.split(':');
|
||||||
|
// @ts-ignore
|
||||||
|
this.weightArr.push([parseInt(subArr[0]), parseInt(subArr[1])]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import {GameEnv} from "../cfg/GameEnv";
|
|||||||
import {BaseConst} from "../constants/BaseConst";
|
import {BaseConst} from "../constants/BaseConst";
|
||||||
|
|
||||||
const $cfg = new Map();
|
const $cfg = new Map();
|
||||||
|
const jsonPath = 'configs';
|
||||||
export var DataParser = (function (){
|
export var DataParser = (function (){
|
||||||
const parsers: { [index: string]: ConfigDataParser } = {};
|
const parsers: { [index: string]: ConfigDataParser } = {};
|
||||||
|
|
||||||
@ -13,13 +13,21 @@ export var DataParser = (function (){
|
|||||||
regCommonParser(key: string, CfgCreator: { new (): Cfg }, idkey = "id") {
|
regCommonParser(key: string, CfgCreator: { new (): Cfg }, idkey = "id") {
|
||||||
regParser(key, (data: any[]): any => {
|
regParser(key, (data: any[]): any => {
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
let dict = {};
|
let dict = new Map();
|
||||||
|
for (let i = 0, len = data.length; i < len; i++) {
|
||||||
|
let obj = data[i];
|
||||||
|
let to = new CfgCreator();
|
||||||
|
to.decode(obj);
|
||||||
|
if (dict.has(to.id)) {
|
||||||
|
console.error(`配置${key}的数据有误,唯一标识 id 有重复值:${to.id}`)
|
||||||
|
process.abort();
|
||||||
|
}
|
||||||
|
dict.set(to.id, to);
|
||||||
|
}
|
||||||
return dict;
|
return dict;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
loadAll() {
|
loadAll() {
|
||||||
let jsonPath = `configs`;
|
|
||||||
let fileArr = jetpack.list(jsonPath);
|
let fileArr = jetpack.list(jsonPath);
|
||||||
for (let f of fileArr) {
|
for (let f of fileArr) {
|
||||||
let key = f.replace('_tbl.json', '');
|
let key = f.replace('_tbl.json', '');
|
||||||
@ -27,11 +35,10 @@ export var DataParser = (function (){
|
|||||||
let json = jetpack.read(`${jsonPath}/${f}`, 'json');
|
let json = jetpack.read(`${jsonPath}/${f}`, 'json');
|
||||||
if (parser && json){
|
if (parser && json){
|
||||||
if (Array.isArray(json)) {
|
if (Array.isArray(json)) {
|
||||||
let map = new Map();
|
let data = parser(json);
|
||||||
for (let d of json) {
|
if (data) { // 支持一些void的情况
|
||||||
map.set(d.id, d);
|
$cfg.set(key, data);
|
||||||
}
|
}
|
||||||
$cfg.set(key, map);
|
|
||||||
} else {
|
} else {
|
||||||
$cfg.set(key, json);
|
$cfg.set(key, json);
|
||||||
}
|
}
|
||||||
@ -41,7 +48,7 @@ export var DataParser = (function (){
|
|||||||
Object.assign(global, {
|
Object.assign(global, {
|
||||||
$cfg: $cfg
|
$cfg: $cfg
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 注册配置解析
|
* 注册配置解析
|
||||||
@ -68,4 +75,5 @@ export interface Cfg
|
|||||||
* @param {*} [local] 没有接口,但是需要本地赋值的数据
|
* @param {*} [local] 没有接口,但是需要本地赋值的数据
|
||||||
*/
|
*/
|
||||||
decode?: { (local?: any):void };
|
decode?: { (local?: any):void };
|
||||||
|
id?: number;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import {Schema, type, filter} from "@colyseus/schema";
|
|||||||
|
|
||||||
export class Card extends Schema {
|
export class Card extends Schema {
|
||||||
|
|
||||||
constructor(number: number, type: string, id: number) {
|
constructor(number: number, type: number, id: number, effect: number) {
|
||||||
super();
|
super();
|
||||||
this.number = number;
|
this.number = number;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -30,8 +30,16 @@ export class Card extends Schema {
|
|||||||
@type("boolean")
|
@type("boolean")
|
||||||
played: boolean = false;
|
played: boolean = false;
|
||||||
/**
|
/**
|
||||||
* 种类
|
* 类型
|
||||||
|
* 1: 普通牌
|
||||||
|
* 2: 效果强化卡
|
||||||
|
* 3: 点数加倍卡
|
||||||
*/
|
*/
|
||||||
@type("string")
|
@type("number")
|
||||||
type: string;
|
type: number;
|
||||||
|
/**
|
||||||
|
* 对应的效果强化牌id
|
||||||
|
*/
|
||||||
|
@type("number")
|
||||||
|
effect: number;
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,23 @@ import arrUtil from "./array.util";
|
|||||||
import {Player} from "../rooms/schema/Player";
|
import {Player} from "../rooms/schema/Player";
|
||||||
import {singleton} from "../common/Singleton";
|
import {singleton} from "../common/Singleton";
|
||||||
import {GameEnv} from "../cfg/GameEnv";
|
import {GameEnv} from "../cfg/GameEnv";
|
||||||
|
import {BaseConst} from "../constants/BaseConst";
|
||||||
|
import {SystemCardCfg} from "../cfg/parsers/SystemCardCfg";
|
||||||
|
|
||||||
let gameUtil = {
|
let gameUtil = {
|
||||||
// TODO: 根据配表生成牌组
|
// TODO: 根据配表生成牌组
|
||||||
initCardQue() {
|
initCardQue() {
|
||||||
let cards: Array<Card> = [];
|
let cards: Array<Card> = [];
|
||||||
|
let numCfgMap: Map<number, SystemCardCfg> = global.$cfg.get(BaseConst.SYSTEMCARD);
|
||||||
|
let effCfgMap = global.$cfg.get(BaseConst.EFFECTCARD);
|
||||||
let nums: Array<number> = [];
|
let nums: Array<number> = [];
|
||||||
let types : Array<number> = [];
|
let types : Array<number> = [];
|
||||||
for (let i = 0; i < 12; i ++) {
|
for (let [id, cfg] of numCfgMap) {
|
||||||
for (let j = 0; j < 16; j ++) {
|
for (let i = 0; i < cfg.count; i++) {
|
||||||
nums.push(i);
|
nums.push(cfg.point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
arrUtil.randomSort(nums);
|
arrUtil.randomSort(nums);
|
||||||
for (let i = 0; i < 8; i ++) {
|
for (let i = 0; i < 8; i ++) {
|
||||||
for (let j = 0; j < 24; j ++) {
|
for (let j = 0; j < 24; j ++) {
|
||||||
@ -24,7 +29,7 @@ let gameUtil = {
|
|||||||
}
|
}
|
||||||
arrUtil.randomSort(types);
|
arrUtil.randomSort(types);
|
||||||
for (let i = 0; i < nums.length; i++) {
|
for (let i = 0; i < nums.length; i++) {
|
||||||
cards.push(new Card(nums[i] + 1, types[i] + '', i));
|
cards.push(new Card(nums[i] + 1, types[i], i, i));
|
||||||
}
|
}
|
||||||
arrUtil.randomSort(cards);
|
arrUtil.randomSort(cards);
|
||||||
return cards;
|
return cards;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user