Files
erqiwang_youle/server/games/erqiwang/class.config.js
T
joywayerandClaude Opus 4.8 60271175d6 二七王:逻辑文件补双运行时守卫,解锁 Node 单测
按 dev-guide 01 §1「一套代码,两个运行时」补齐 erqiwang 缺失的守卫(此前只支持友乐全局加载模型):
- 顶部:跨模块依赖走 `if (typeof require!=='undefined') var X=require('./class.X.js')`
  (config/pai/arith 无跨模块依赖;paiju 依赖 arith/config/pai;desk 依赖 paiju;export 依赖 arith/config/desk)
- 底部:`if (typeof module!=='undefined') module.exports = cls_X`
- export/import 的平台接线 `youle_erqiwang.X=...` 加 `typeof youle_erqiwang` 守卫,Node 无此全局时跳过

纯增量:友乐无 require(浏览器模型),守卫全部跳过、全局名仍无条件暴露,线上行为不变;
仅在 Node 下额外启用 require/module.exports,从而可用 node 直接单测。min_*/youle_erqiwang 等平台全局仍按全局名引用(Node 侧由测试 shim 提供)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-04 23:51:12 +08:00

53 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
///////////////////////////////////////////////////
////// cls_youle_erqiwang_config: 房间配置解析 //////
///////////////////////////////////////////////////
//
// roomtype 采用定长数字位串(字符串),每一位对应一个开关,'0'/'1',方便前端逐项勾选:
// 位0 局数: '0'→6局 '1'→12局
// 位1 扣卡方式: '0'→房主扣卡 '1'→AA每人扣卡
// 位2 傍王: '0'→关 '1'→开
// 位3 爬坡: '0'→常规算子 '1'→爬坡
// 位4 查牌: '0'→可查牌 '1'→不查牌
// 示例 "10100" = 12局 / 房主扣卡 / 傍王开 / 常规算子 / 可查牌
// 缺省 "00000" = 6局 / 房主扣卡 / 无傍王 / 常规算子 / 可查牌(对齐 design 缺省)
//
// 本模块是 roomtype 位串格式的唯一解析入口(SSOT);游戏逻辑一律经 parse() 读取,
// 不得在别处按下标硬解析。
//
var cls_youle_erqiwang_config = cls_youle_erqiwang_config || {
//位索引常量
IDX_ASET: 0, //局数
IDX_DEDUCT: 1, //扣卡方式
IDX_BANGWANG:2, //傍王
IDX_CLIMB: 3, //爬坡
IDX_NOCHECK: 4, //查牌
//取第 idx 位是否为 '1';roomtype 缺失/过短一律按 '0'(缺省)处理
bit: function(roomtype, idx){
if (!roomtype || typeof roomtype != "string"){
return false;
}
if (idx < 0 || idx >= roomtype.length){
return false;
}
return roomtype.charAt(idx) == "1";
},
//解析 roomtype 位串为具名配置对象
parse: function(roomtype){
var cfg = {};
cfg.aset12 = cls_youle_erqiwang_config.bit(roomtype, cls_youle_erqiwang_config.IDX_ASET); //true=12局 false=6局
cfg.deductAA = cls_youle_erqiwang_config.bit(roomtype, cls_youle_erqiwang_config.IDX_DEDUCT); //true=AA每人 false=房主
cfg.bangwang = cls_youle_erqiwang_config.bit(roomtype, cls_youle_erqiwang_config.IDX_BANGWANG);//true=开傍王
cfg.climb = cls_youle_erqiwang_config.bit(roomtype, cls_youle_erqiwang_config.IDX_CLIMB); //true=爬坡
cfg.nocheck = cls_youle_erqiwang_config.bit(roomtype, cls_youle_erqiwang_config.IDX_NOCHECK); //true=不查牌
return cfg;
}
}
//Node(本地/单元测试)导出;友乐/浏览器无 module 时跳过,按全局名引用(dev-guide 01 §1)
if (typeof module !== "undefined"){
module.exports = cls_youle_erqiwang_config;
}