腾讯14周年庆典活动≠┃QQ中奖彩票是真是假假┃

私信发送成功
检测到您已登录开源中国,是否
Fork 该项目?
使用 fork 功能将在后台会为你创建一个与该项目内容一样的同名项目,你可以在这个新项目里自由的修改内容。
建议只在有意向参与改进该项目时使用 fork 功能。
!1 test-lcd-js 分辨率测试
条评论, 1 人参与
git checkout varres
git pull https://git.oschina.net/bgwp/baye-alpha.git s2
git push origin varres
后才可以发表评论
@@ -15,7 +15,21 @@
var s = document.getElementsByTagName(&script&)[0];
s.parentNode.insertBefore(hm, s);
&script src=&js/jquery.min.js&&&/script&
&script src=&js/lcd.js?ver=10&&&/script&
$(function(){ loadLibLists(&#list&); });
&script type=&text/html& id=&item_temp&&
&div class=&container& style=&margin-top:2px&&
&button class=&btn menu& style=&width:80%& type=&button& onclick=&chooseLib('{title}', '{libpath}', this)&&{title}&/button&
&button class=&btn menu detail& style=&width:20%;& type=&button& onclick=&loadDetail('#desc{descid}', '{descpath}')&&详情&/button&
&div id=&desc{descid}& style=&display:&&&/div&
@@ -30,18 +44,3 @@
-&script type=&text/html& id=&item_temp&&
&div class=&container& style=&margin-top:2px&&
&button class=&btn menu& style=&width:80%& type=&button& onclick=&chooseLib('{title}', '{libpath}', this)&&{title}&/button&
&button class=&btn menu detail& style=&width:20%;& type=&button& onclick=&loadDetail('#desc{descid}', '{descpath}')&&详情&/button&
&div id=&desc{descid}& style=&display:&&&/div&
-&/script&
-&script src=&/jquery/1.9.1/jquery.min.js&&&/script&
-&script src=&js/lcd.js&&&/script&
-loadLibLists(&#list&);
-&/script&
@@ -3,7 +3,7 @@
&meta charset=&UTF-8&&
&title&网址转换&/title&
&script src=&/jquery/1.9.1/jquery.min.js&&&/script&
&script src=&js/jquery.min.js&&&/script&
@@ -0,0 +1,32 @@
+&!DOCTYPE html&
+&html lang=&en&&
&meta charset=&UTF-8&&
&meta content=&width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no& id=&viewport& name=&viewport&&
&title&Debug&/title&
&script src=&js/jquery.min.js&&&/script&
&div class=&config-item&&
&select name=&& id=&debug-select&&
&option value=&0&&禁用&/option&
&option value=&1&&启用&/option&
$(function(){
function bind(id, key) {
$(id).val(window.localStorage[key] || '0');
$(id).change(function () {
window.localStorage[key] = $(this).val();
bind(&#debug-select&, &baye/debug&);
+&/script&
@@ -0,0 +1,24 @@
+&!DOCTYPE html&
+&html lang=&en&&
&meta charset=&UTF-8&&
&title&伏魔记&/title&
&link rel=&stylesheet& type=&text/css& href=&baye.css& /&
&link rel=&icon& href=&favicon.png&&
&meta content=&width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no& id=&viewport& name=&viewport&&
var _hmt = _hmt || [];
(function() {
var hm = document.createElement(&script&);
hm.src = &///hm.js?55cdc246d0c836cecfdf39ce0d5657f3&;
var s = document.getElementsByTagName(&script&)[0];
s.parentNode.insertBefore(hm, s);
[天际边工作室]正在考虑是否和我合作移植网页版伏魔记系列&br&
大家可以入群: 询问网页版.
\ No newline at end of file
@@ -2,7 +2,7 @@
&html lang=&en&&
&meta http-equiv=&Content-Type& content=&text/ charset=utf-8& /&
&title&分享存档&/title&
&title&传送存档&/title&
&link rel=&stylesheet& type=&text/css& href=&baye.css& /&
&link rel=&icon& href=&favicon.png&&
&meta content=&width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no& id=&viewport& name=&viewport&&
@@ -14,12 +14,36 @@
font-size: 30
&script src=&/jquery/1.9.1/jquery.min.js&&&/script&
&script src=&js/jquery.min.js&&&/script&
&script src=&js/lzma_worker-min.js&&&/script&
&script src=&js/base64.js&&&/script&
&script src=&js/lcd.js?ver=10&&&/script&
&script src=&js/spin.min.js&&&/script&
var opts = {
lines: 13 // The number of lines to draw
, length: 28 // The length of each line
, width: 14 // The line thickness
, radius: 42 // The radius of the inner circle
, scale: 1 // Scales overall size of the spinner
, corners: 1 // Corner roundness (0..1)
, color: '#000' // #rgb or #rrggbb or array of colors
, opacity: 0.25 // Opacity of the lines
, rotate: 0 // The rotation offset
, direction: 1 // 1: clockwise, -1: counterclockwise
, speed: 1 // Rounds per second
, trail: 60 // Afterglow percentage
, fps: 20 // Frames per second when using setTimeout() as a fallback for CSS
, zIndex: 2e9 // The z-index (defaults to )
, className: 'spinner' // The CSS class to assign to the spinner
, top: '50%' // Top position relative to parent
, left: '50%' // Left position relative to parent
, shadow: true // Whether to render a shadow
, hwaccel: true // Whether to use hardware acceleration
, position: 'absolute' // Element positioning
var spinner = new Spinner(opts);
function getfile(n) {
return localStorage[&baye//data//sango& + n + &.sav&];
@@ -30,49 +54,83 @@
function upload(n) {
var self = $(this);
var data = dump(n);
spinner.spin(document.body);
$(&#osize&).html('origin:' + data.length);
setTimeout(function(){
var data = dump(n);
if (data.length & 100) {
$(&#url-title&).html(&&);
$(&#url&).html(&该存档为空!&);
$(&#osize&).html('origin:' + data.length);
$(&#result&).html(&请求中...&);
var result = press(data, 9);
if (data.length & 100) {
$(&#url-title&).html(&&);
$(&#url&).html(&该存档为空!&);
spinner.stop();
var b64data = Base64.encode(result);
$(&#result&).html(&请求中...&);
var result = press(data, 9);
$(&#zsize&).html('result:' + result.length);
$(&#bsize&).html('b64data:' + b64data.length);
var b64data = Base64.encode(result);
var loadUrl = &http://bgwp.oschina.io/baye/load.html?sav=& + b64
$(&#zsize&).html('result:' + result.length);
$(&#bsize&).html('b64data:' + b64data.length);
url: &/urls/add.jsonp?url=& + loadUrl,
dataType: &jsonp&,
jsonp: &callback&,
jsonpCallback: &www_50r_cn_jsonp_callback&,
type: &GET&,
success: function(resp) {
$(&#url-title&).html(&已生成存档& + (n + 1) + &的链接:&);
$(&#url&).html('&a href=&' + resp.url + '&&' + resp.url + '&/a&');
error: function() {
$(&#url-title&).html(&&);
$(&#url&).html(&请求失败&);
var libName = getLibName();
var loadUrl = &http://bgwp.oschina.io/baye/load.html?sav=& + b64data + '&name=' + libN
function showLongUrl(url, n) {
$(&#url-title&).html(&已生成存档& + (n + 1) + &的长网址:&);
$(&#url&).html('&a href=&' + url + '&&' + &长按复制链接& + '&/a&');
if ($(&#use-short-url&).val() != '1')
spinner.stop();
showLongUrl(loadUrl, n);
url: &/urls/add.jsonp?url=& + encodeURIComponent(loadUrl),
dataType: &jsonp&,
jsonp: &callback&,
jsonpCallback: &www_50r_cn_jsonp_callback&,
type: &GET&,
success: function(resp) {
spinner.stop();
$(&#url-title&).html(&已生成存档& + (n + 1) + &的链接:&);
$(&#url&).html('&a href=&' + resp.url + '&&' + resp.url + '&/a&');
error: function() {
spinner.stop();
showLongUrl(loadUrl, n);
$(function(){
var libName = getLibName();
$(&#lib-name&).html(&当前版本: & + libName);
&button class=&btn menu& type=&button& onclick=&upload(0)&&导出存档1&/button&
&button class=&btn menu& type=&button& onclick=&upload(1)&&导出存档2&/button&
&button class=&btn menu& type=&button& onclick=&upload(2)&&导出存档3&/button&
&div id=&lib-name&&&/div&
&div class=&config-item&&
使用短网址:
&select name=&& id=&use-short-url&&
&option value=&0&&否&/option&
&option value=&1&&是&/option&
&div id=&url-title&&&/div&
&div id=&url&&&/div&
@@ -7,6 +7,9 @@
&link rel=&icon& href=&favicon.png&&
&meta content=&width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no& id=&viewport& name=&viewport&&
if (window.location.pathname == '/baye') {
window.location = '/baye/'
var _hmt = _hmt || [];
(function() {
var hm = document.createElement(&script&);
@@ -15,8 +18,8 @@
s.parentNode.insertBefore(hm, s);
&script src=&/jquery/1.9.1/jquery.min.js&&&/script&
&script src=&js/lcd.js?ver=1&&&/script&
&script src=&js/jquery.min.js&&&/script&
&script src=&js/lcd.js?ver=10&&&/script&
.index-tip {
@@ -24,6 +27,9 @@
font-size: 16
.config-item {
margin-top: 8
@@ -33,29 +39,49 @@
&div class=&container& style=&margin-top:2px&&
&button class=&btn menu& type=&button& onclick=&redirect()&&进入游戏&/button&
&div class=&container& style=&margin-top:2px&&
&button class=&btn menu& type=&button& onclick=&location='get-sav.html';&&导出存档&/button&
&button class=&btn menu& type=&button& onclick=&location='get-sav.html';&&传送存档&/button&
&select name=&& id=&mode-select&&
&option value=&0&&横屏&触控&/option&
&option value=&1&&竖屏&键盘&/option&
&div class=&config-item&&
&select name=&& id=&mode-select&&
&option value=&0&&横屏&触控&/option&
&option value=&1&&竖屏&键盘&/option&
&option value=&2&&横屏&手势&/option&
&div class=&config-item&&
&select name=&& id=&resolution-select&&
&option value=&0&&4988&/option&
&option value=&1&&加大&/option&
&div class=&config-item&&
&select name=&& id=&clear-select&&
&option value=&0&&禁用&/option&
&option value=&1&&启用&/option&
&div class=&config-item&&
交流QQ群: &br&
注意: Android QQ内置浏览器BUG会导致触控失灵.
$(function(){
$(&#mode-select&).val(window.localStorage[&baye/mpage&]);
$(&#mode-select&).change(function () {
window.localStorage[&baye/mpage&] = $(this).val();
console.log(&changed:& + window.localStorage[&baye/mpage&]);
function bind(id, key) {
$(id).val(window.localStorage[key] || '0');
$(id).change(function () {
window.localStorage[key] = $(this).val();
bind(&#mode-select&, &baye/mpage&);
bind(&#resolution-select&, &baye/resolution&);
bind(&#clear-select&, &baye/clearmode&);
+if (window._bayeRand === undefined) {
window._bayeRand = function() {
return 0.5;
+Math.random = function() {
return _bayeRand() % 65536 / 65536;
+if (!String.prototype.format) {
String.prototype.format = function() {
var args =
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
ValueTypeU8 = 0;
ValueTypeU16 = 1;
ValueTypeU32 = 2;
ValueTypeString = 3;
ValueTypeBinary = 4;
ValueTypeObject = 5;
ValueTypeObject = 4;
ValueTypeArray = 5;
ValueTypeMethod = 6;
ValueTypeGBKBuffer = 7;
-function baye_bridge_obj(obj) {
var jsObj = {};
var count = _object_get_field_count(obj);
+var gbkDecoder = new TextDecoder('GBK');
+var gbkEncoder = new TextEncoder('GBK', { NONSTANDARD_allowLegacyEncoding: true });
jsObj._bridged_obj =
+function BayeObject() {
for (var i = 0; i & i++) {
var field = _object_get_field_by_index(obj, i);
var cname = _object_get_field_name(field);
var name = UTF8ToString(cname);
var value = 0;
+BayeObject.prototype.toString = function() {
switch (this._type) {
case ValueTypeU8:
return 'U8(' + this.value + ')';
case ValueTypeU16:
return 'U16(' + this.value + ')';
case ValueTypeU32:
return 'U32(' + this.value + ')';
case ValueTypeString:
return 'String(&' + this.value + '&)';
case ValueTypeObject:
return 'Object';
case ValueTypeArray:
return 'Array[' + this.length + ']';
case ValueTypeGBKBuffer:
return 'GBKBuffer[' + this.length + ']';
case ValueTypeMethod:
return 'Method';
switch (_object_get_field_type(field)) {
case ValueTypeU8:
case ValueTypeU16:
case ValueTypeU32:
value = _object_get_field_value(field);
case ValueTypeString:
value = _object_get_field_value(field);
value = UTF8ToString(value);
case ValueTypeBinary:
value = _object_get_field_value(field);
var size = _object_get_field_size(field);
var data = [];
for (var n = 0; n & n++) {
data[n] = getValue(value + n, 'i8');
+function baye_bridge_value(value) {
return baye_bridge_valuedef(_Value_get_def(value), _Value_get_addr(value));
+function baye_bridge_description_for_value(jvalue, type) {
switch (type) {
case ValueTypeU8:
case ValueTypeU16:
case ValueTypeU32:
case ValueTypeString:
get: function() {
return jvalue.value.
set: function(value) {
jvalue.value.value =
case ValueTypeObject:
value = _object_get_field_value(field);
value = baye_bridge_obj(value);
case ValueTypeArray:
get: function() {
return jvalue.
set: function(value) {
var jv = jvalue.
var length = jv.
for(var i = 0; i & length && i & value. i++) {
jv[i] = value[i]
case ValueTypeGBKBuffer:
get: function() {
return gbkDecoder.decode(jvalue.value);
set: function(value) {
var jv = jvalue.
var arr = gbkEncoder.encode('' + value);
var length = Math.min(jv.length - 1, arr.length);
for(var i = 0; i & i++) {
jv[i] = arr[i]
jv[length] = 0;
case ValueTypeObject:
get: function() {
return jvalue.
+function defineProperty(obj, p, desc) {
Object.defineProperty(obj, p, desc);
+function defineProperties(obj, desc) {
Object.defineProperties(obj, desc);
+function baye_bridge_valuedef_lazy(def, addr) {
var obj = {
get value() {
if (this._value == undefined) {
this._value = baye_bridge_valuedef(def, addr);
return this._
jsObj[name] =
+function baye_bridge_valuedef(def, addr) {
var type = _ValueDef_get_type(def);
var jsObj = new BayeObject();
jsObj._def =
jsObj._addr =
jsObj._type =
switch (type) {
case ValueTypeU8:
defineProperty(jsObj, 'value', {
get: function() {
return _baye_get_u8_value(this._addr);
set: function(value) {
if (value & 0xff) value = 0
if (value & 0) value = 0;
return _baye_set_u8_value(this._addr, value);
case ValueTypeU16:
defineProperty(jsObj, 'value', {
get: function() {
return _baye_get_u16_value(this._addr);
set: function(value) {
if (value & 0xffff) value = 0
if (value & 0) value = 0;
return _baye_set_u16_value(this._addr, value);
case ValueTypeU32:
defineProperty(jsObj, 'value', {
get: function() {
return _baye_get_u32_value(this._addr);
set: function(value) {
return _baye_set_u32_value(this._addr, value);
case ValueTypeString:
defineProperty(jsObj, 'value', {
get: function() {
return this._
case ValueTypeObject:
return baye_bridge_obj(def, addr);
case ValueTypeArray:
case ValueTypeGBKBuffer:
var length = _ValueDef_get_array_length(def);
jsObj.length =
var subdef = _ValueDef_get_array_subdef(def);
var subsize = _ValueDef_get_size(subdef);
var properties = {};
for (var i = 0; i & i++) {
var item_value = baye_bridge_valuedef_lazy(subdef, addr + subsize * i);
var desc = baye_bridge_description_for_value(item_value, _ValueDef_get_type(subdef));
properties[i] =
defineProperties(jsObj, properties);
case ValueTypeMethod:
return function() {
return jsO
+function baye_bridge_obj(def, addr) {
var jsObj = {};
var properties = {};
-function baye_sync_obj(obj, jsObj) {
var count = _object_get_field_count(obj);
var count = _ValueDef_get_field_count(def);
jsObj._def =
jsObj._addr =
for (var i = 0; i & i++) {
var field = _object_get_field_by_index(obj, i);
var cname = _object_get_field_name(field);
var field = _ValueDef_get_field_by_index(def, i);
var cname = _Field_get_name(field);
var name = UTF8ToString(cname);
var value = jsObj[name];
var field_value_addr = _Field_get_value(field);
var value_def = _Value_get_def(field_value_addr);
var value_offset = _Value_get_addr(field_value_addr);
var field_value = baye_bridge_valuedef_lazy(value_def, addr + value_offset);
switch (_object_get_field_type(field)) {
case ValueTypeU8:
case ValueTypeU16:
case ValueTypeU32:
_object_set_field_value(field, value, 0);
case ValueTypeString:
case ValueTypeBinary:
var mem = _object_get_field_value(field);
var size = _object_get_field_size(field);
for (var n = 0; n & Math.min(size, value.length); n++) {
setValue(mem + n, value[n], 'i8');
case ValueTypeObject:
var cvalue = _object_get_field_value(field);
baye_sync_obj(cvalue, value);
jsObj[name] =
var desc = baye_bridge_description_for_value(field_value, _Field_get_type(field));
properties[name] =
defineProperties(jsObj, properties);
return jsO
+function bayeU8Array(caddr, length) {
return Module.HEAPU8.subarray(caddr, caddr+length);
-// 调试攻击范围
-function debugPrintAttackRange(data) {
var linesize = 15;
var text = &&;
for (var i = 0; i & i++) {
for (var j = 0; j & j++) {
text += data[i*linesize + j] ? &*& : &.&;
+function bayeWrapFunctionS(innerf) {
return function() {
var addr = innerf.apply(this, arguments);
if (addr != 0) {
return new TextDecoder('GBK').decode(bayeU8Array(addr, _bayeStrLen(addr)));
text += &\n&;
+function range(start, stop, step) {
if (typeof stop == 'undefined') {
// one param defined
start = 0;
if (typeof step == 'undefined') {
if ((step & 0 && start &= stop) || (step & 0 && start &= stop)) {
return [];
console.log(text);
var result = [];
for (var i = step & 0 ? i & stop : i & i += step) {
result.push(i);
+$(function(){
function truncate(s, n, pad) {
var l = 0;
var c = 0;
for (var i = 0; i & s. i++) {
var cs = s.charCodeAt(i) & 256 ? 2 : 1;
if (l + cs &= n) {
var rv = s.slice(0, c);
if (pad) {
while (l & n) {
rv += ' ';
if (window.baye === undefined) {
window.baye = {};
baye.debug = {};
baye.getPersonName = bayeWrapFunctionS(_bayeGetPersonName);
baye.getToolName = bayeWrapFunctionS(_bayeGetToolName);
baye.getSkillName = bayeWrapFunctionS(_bayeGetSkillName);
baye.getCityName = bayeWrapFunctionS(_bayeGetCityName);
baye.getCustomData = function() {
var cstr = _bayeGetCustomData();
if (cstr == 0)
return UTF8ToString(cstr);
baye.setCustomData = function(data) {
var length = lengthBytesUTF8(data) + 1;
var buffer = Module._malloc(length);
stringToUTF8(data, buffer, length);
_bayeSetCustomData(buffer);
Module._free(buffer);
baye.alert = function(msg, then){
baye.data.g_asyncActionID = 1;
baye.data.g_asyncActionParams[0] = 3;
baye.data.g_asyncActionStringParam =
baye.callback =
baye.say = function(personIndex, msg, then){
baye.data.g_asyncActionID = 2;
baye.data.g_asyncActionParams[0] = personI
baye.data.g_asyncActionStringParam =
baye.callback =
function setcb0(then) {
if (then) {
baye.callback = function() {
return then(baye.data.g_asyncActionParams[0]);
baye.callback =
baye.choose = function(x, y, w, h, items, init, then){
baye.data.g_asyncActionID = 3;
baye.data.g_asyncActionParams[0] =
baye.data.g_asyncActionParams[1] =
baye.data.g_asyncActionParams[2] =
baye.data.g_asyncActionParams[3] =
baye.data.g_asyncActionParams[4] =
var n = Math.floor(w / 6);
var s = &&;
for (var i = 0; i & items. i++) {
s += truncate(items[i], n, true);
baye.data.g_asyncActionStringParam =
setcb0(then);
baye.centerChoose = function(w, h, items, init, then) {
var x = (baye.data.g_screenWidth - w) / 2;
var y = (baye.data.g_screenHeight - h) / 2;
return baye.choose(x, y, w, h, items, init, then);
baye.choosePerson = function(items, init, then) {
baye.data.g_asyncActionID = 4;
baye.data.g_asyncActionParams[0] = items.
baye.data.g_asyncActionParams[1] =
for (var i = 0; i & items. i++) {
baye.data.g_asyncActionStringParamArray[i] = items[i];
setcb0(then);
baye.chooseTool = function(items, init, then) {
baye.data.g_asyncActionID = 5;
baye.data.g_asyncActionParams[0] = items.
baye.data.g_asyncActionParams[1] =
for (var i = 0; i & items. i++) {
baye.data.g_asyncActionStringParamArray[i] = items[i];
setcb0(then);
baye.chooseCity = function(then) {
baye.data.g_asyncActionID = 6;
setcb0(then);
baye.getPersonByName = function(name) {
var all = baye.data.g_P
for (var i = 0; i & all. i++) {
if (baye.getPersonName(i) == name) {
return all[i];
baye.getCityByName = function(name) {
var all = baye.data.g_C
for (var i = 0; i & all. i++) {
if (baye.getCityName(i) == name) {
return all[i];
baye.getFighterIndexByName = function(name) {
var all = baye.data.g_FgtParam.GenA
for (var i = 0; i & all. i++) {
var index = all[i] - 1;
if (index &= 0 && baye.getPersonName(index) == name) {
baye.getFighterPositionByName = function(name) {
var idx = baye.getFighterIndexByName(name);
return baye.data.g_GenPos[idx];
baye.getPersonNameByID = function(id) {
switch (id) {
return &-&;
case 0xff:
return &俘虏&;
return baye.getPersonName(id - 1);
baye.printCity = function(i) {
var city = baye.data.g_Cities[i];
var people = baye.data.g_P
var queue = baye.data.g_PersonsQ
var belong = baye.getPersonNameByID(city.Belong);
console.log(&--------& + baye.getCityName(i) + &--------&);
console.log(&id: & + i);
console.log(&归属: & + belong);
console.log(&-&);
for (var qi = 0; qi
& city.P qi++) {
var pind = queue[city.PersonQueue + qi];
var person = people[pind];
var name = baye.getPersonName(pind);
var belong = baye.getPersonNameByID(person.Belong);
console.log(sprintf(&%-10s 归属:%-10s&, name, belong));
console.log(&-&);
var queue = baye.data.g_GoodsQ
var tools = baye.data.g_T
for (var qi = 0; qi
& city.T qi++) {
var tindex = queue[city.ToolQueue + qi];
var tool = tools[pind];
var name = baye.getToolName(pind);
console.log(name);
baye.printPeople = function () {
for (var i = 0; i & 250; i++) {
var p = baye.data.g_Persons[i];
if (p.Level & 0) {
console.log(sprintf('index: %03d name: %-08s 归属:%-08s', i, baye.getPersonName(i), baye.getPersonNameByID(p.Belong)));
baye.printAllCities = function() {
var cities = baye.data.g_C
for (var i = 0; i & cities. i++) {
baye.printCity(i);
baye.getTerrainByGeneralIndex = function(index) {
return _bayeFgtGetGenTer(index);
baye.putPersonInCity = function(city, person) {
return _bayePutPersonInCity(city, person);
baye.putToolInCity = function(city, tool, hide) {
return _bayePutToolInCity(city, tool, hide ? 1 : 0);
baye.deletePersonInCity = function(city, person) {
return _bayeDeletePersonInCity(city, person);
baye.deleteToolInCity = function(city, tool) {
return _bayeDeleteToolInCity(city, tool);
baye.getPersonByGeneralIndex = function(gIndex) {
var pid = baye.data.g_FgtParam.GenArray[gIndex];
return baye.data.g_Persons[pid - 1];
baye.moveHere = function(name) {
var i = baye.getFighterIndexByName(name);
var pd = baye.data.g_GenPos[i];
pd.x = baye.data.g_FoucsX;
pd.y = baye.data.g_FoucsY;
baye.getArmType = function(pindex) {
return _bayeGetArmType(pindex);
@@ -0,0 +1,317 @@
+baye.hooks.battleBuildAttackAttriutes = function(context) {
脚本计算攻防示例
context.index: 计算结果存放位置序号
context.generalIndex: 战场将领序号
var result = baye.data.g_GenAtt[context.index];
var pIndex = baye.data.g_FgtParam.GenArray[context.generalIndex] - 1;
var person = baye.data.g_Persons[pIndex];
// 地形对兵种的影响
var terEffects = [
草地, 平原, 山地, 森林, 村庄, 城池, 营寨, 河流
[1, 1, 1, 1, 1, 1, 1, 1], // 骑兵
[1, 1, 1, 1, 1, 1, 1, 1], // 步兵
[1, 1, 1, 1, 1, 1, 1, 1], // 弓兵
[1, 1, 1, 1, 1, 1, 1, 1], // 水兵
[1, 1, 1, 1, 1, 1, 1, 1], // 极兵
[1, 1, 1, 1, 1, 1, 1, 1], // 玄兵
var AtkModulus = [1.0, 0.8, 0.9, 0.8, 1.3, 0.4]; /* 各兵种攻击系数 */
var DfModulus =
[0.7, 1.2, 1.0, 1.1, 1.2, 0.6]; /* 各兵种防御系数 */
var TerrDfModu = [1.0, 1.0, 1.3, 1.15, 1.1, 1.5, 1.2, 0.8]; /* 各种地形防御系数 */
// 武力/等级/攻击系数影响攻击力
var at = person.Force * (person.Level + 10) * AtkModulus[person.ArmsType];
// 智力/等级/防御系数影响防御力
var df = person.IQ * (person.Level + 10) * DfModulus[person.ArmsType];
// 叠加地形对攻防的影响
at = terEffects[person.ArmsType][result.ter] *
df = terEffects[person.ArmsType][result.ter] *
// 地形固有防御系数
df *= TerrDfModu[result.ter];
// 输出最终结果
result.at =
result.df =
+baye.hooks.battleDrivePersonState = function(context) {
var person = baye.getPersonByGeneralIndex(context.generalIndex);
if (person.Arms & 0) person.Arms -= 1;
+baye.hooks.countAttackHurt = function(context) {
计算伤害示例
查阅文档可知, 可以使用计算普通攻击伤害的钩子
http://bgwp.oschina.io/baye-doc/script/index.html#baye-hooks-countattackhurt
context.hurt: 计算结果存放位置序号
如下是引擎默认算法:
var KeZhiMatrix = [
[1.0, 1.2, 0.8, 1.0, 0.7, 1.3],
[0.8, 1.0, 1.2, 1.0, 0.6, 1.2],
[1.2, 0.8, 1.0, 1.0, 1.1, 1.2],
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
[1.1, 1.3, 0.9, 1.0, 1.0, 1.5],
[0.6, 0.6, 0.6, 0.6, 0.6, 0.6]
var p0 = baye.data.g_GenAtt[0]; //攻击方数据
var p1 = baye.data.g_GenAtt[1]; //防守方数据
var person = baye.getPersonByGeneralIndex(p0.generalIndex);
/* 基本伤害 hurt = (at / df) * arms / 8 */
var hurt = p0.at / p1.df * (person.Arms && 3);
/* 相克加层 hurt *= modu */
hurt *= KeZhiMatrix[p0.armsType][p1.armsType];
context.hurt =
+baye.hooks.countAttackHurt = function(context) {
计算伤害示例
查阅文档可知, 可以使用计算普通攻击伤害的钩子
http://bgwp.oschina.io/baye-doc/script/index.html#baye-hooks-countattackhurt
context.hurt: 计算结果存放位置序号
引入其它条件(如特殊道具)影响伤害输出:
var KeZhiMatrix = [
[1.0, 1.2, 0.8, 1.0, 0.7, 1.3],
[0.8, 1.0, 1.2, 1.0, 0.6, 1.2],
[1.2, 0.8, 1.0, 1.0, 1.1, 1.2],
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
[1.1, 1.3, 0.9, 1.0, 1.0, 1.5],
[0.6, 0.6, 0.6, 0.6, 0.6, 0.6]
var p0 = baye.data.g_GenAtt[0]; //攻击方数据
var p1 = baye.data.g_GenAtt[1]; //防守方数据
var person = baye.getPersonByGeneralIndex(p0.generalIndex);
/* 基本伤害 hurt = (at / df) * arms / 8 */
var hurt = p0.at / p1.df * (person.Arms && 3);
/* 相克加层 hurt *= modu */
hurt *= KeZhiMatrix[p0.armsType][p1.armsType];
// 查找攻击方是否携带有特殊道具
// baye.data.g_GenAtt里面有20个位置, 前十个为攻城方, 后十个为守城方
// 首先需要判断攻击者是攻城方还是守城放
var startIndex = p0.generalIndex & 10 ? 0 : 10;
var hasNewBeeTool =
var newBeeToolID = 5; //牛逼道具的ID
// 查找攻击方有没有牛逼道具
for (var ind = startI ind & startIndex + 10; ind++) {
if (baye.data.g_GenPos[ind].state != 8) { // 8死亡
var p = baye.getPersonByGeneralIndex(ind);
if (p.Tool1 == newBeeToolID || p.Tool2 == newBeeToolID) {
hasNewBeeTool = // 找到牛逼道具
if (hasNewBeeTool) {
// 攻击方团队有牛逼道具, 百倍伤害
hurt *= 100;
context.hurt =
+// 禁止年龄自动增长
+baye.data.g_engineConfig.disableAgeGrow = 1;
+// 定义数据表
+baye.TOOL_AGE_TAB = [10, 10, 0, 10 /* ... */ ];
+// 赏赐时加属性
+baye.hooks.giveTool = function(ctx) {
var up = baye.TOOL_AGE_TAB[ctx.toolIndex];
if (up & 0) {
var person = baye.data.g_Persons[ctx.personIndex];
person.Age +=
ctx.result = 1;
+// 没收时加属性
+baye.hooks.takeOffTool = function(ctx) {
var up = baye.TOOL_AGE_TAB[ctx.toolIndex];
if (up & 0) {
var person = baye.data.g_Persons[ctx.personIndex];
person.Age -=
ctx.result = 1;
+baye.hooks.takeOffTool = function(ctx) {
baye.say(ctx.personIndex, &你算哪根葱?\n& + baye.getToolName(ctx.toolIndex) + &岂是你想拿走就拿走?&, function() {
baye.alert(&没收失败!&);
ctx.result = 0;
+baye.hooks.willGiveTool = function(c) {
// 1号道具 + 2号道具 + 3000金钱 可合成 3号道具
if (baye.getPersonName(c.personIndex) != &马腾&) {
return -1;
var person = baye.data.g_Persons[c.personIndex];
var city = baye.data.g_Cities[c.cityIndex];
// 检查道具是否满足条件
if (person.Tool1 - 1 == 1 && c.toolIndex == 2) {
// 限制条件
if (city.Money & 10000) {
baye.say(c.personIndex, &城池不够富足,无法开工!&);
if (city.PeopleDevotion & 99) {
baye.say(c.personIndex, &城民们对你的治理不太满意,无法开工!&);
if (city.State != 0) {
baye.say(c.personIndex, &城池灾害,无法开工!&);
city.Money -= 3000; // 扣除3000钱
baye.deleteToolInCity(c.cityIndex, c.toolIndex); // 删除材料道具
baye.putToolInCity(c.cityIndex, 3); // 生产出新道具
baye.say(c.personIndex, &全新[& + baye.getToolName(3) + &]已打造成功!&);
return -1;
+// ==========================================
+baye.createCustomData = function() {
// 创建初始数据
switch (baye.data.g_PIdx) {
case 1: //时期1
case 2: //时期2
case 3: //时期2
case 4: //时期4
personNames: [],
+baye.hooks.didOpenNewGame = function() {
// 新开局时初始化自定义数据
baye.data.customData = baye.createCustomData();
+baye.hooks.didLoadGame = function() {
// 读档后需要从存档读取自定义数据
var dat = JSON.parse(baye.getCustomData());
baye.data.customData = dat ? dat : baye.createCustomData();
+baye.hooks.willSaveGame = function() {
// 存档后前需要保存自定义数据
var data = JSON.stringify(baye.data.customData);
baye.setCustomData(data);
+// ==========================================
+baye.hooks.cityMakeCommand = function() {
var items = ['继续', '取消'];
baye.choose(4, 5, 40, 30, items, 1, function(ind) {
console.log(&Choosing: & + ind);
return ind == 0 ? -1 : 0;
+baye.hooks.cityMakeCommand = function() {
var items = range(20);
baye.choosePerson(items, 0, function(ind) {
console.log(&Choosing: & + baye.getPersonName(ind));
+baye.hooks.cityMakeCommand = function() {
var items = range(20);
baye.chooseTool(items, 0, function(ind) {
console.log(&Choosing: & + baye.getToolName(ind));
+// ==========================================
+// 配置道具表格列数量
+baye.data.g_uiCfg.toolPropertyCount = 6;
+// 配置表格列宽度
+baye.data.g_uiCfg.toolPropertiesDisplayWitdh = [4, 6, 6, 6, 6, 6];
+// 定义道具表格表头
+var baye_tool_heads = [&类型&, &加武力&, &加智力&, &加统率&, &加移动&, &变兵种&];
+// 填写表头的钩子
+baye.hooks.getToolPropertyTitle = function(c) {
c.title = baye_tool_heads[c.propertyIndex];
+// 填写单元格的钩子
+baye.hooks.getToolPropertyValue = function(c) {
var tool = baye.data.g_Tools[c.toolIndex];
switch (baye_tool_heads[c.propertyIndex]) {
case &类型&:
c.value = [&装备&, &使用&][tool.useflag];
case &加武力&:
c.value = tool. // 转成字符串
case &加智力&:
c.value = tool. // 转成字符串
case &加统率&:
c.value = baye.TOOL_AGE_TAB[c.toolIndex];
case &加移动&:
c.value = '' + tool. // 转成字符串
case &变兵种&:
c.value = ['无', '水', '玄', '极', &骑兵&, &步兵&, &弓兵&, &水兵&, &极兵&, &玄兵&][tool.arm];
@@ -0,0 +1,8 @@
+(function(global) {
'use strict';
global[&encoding-indexes&] =
&gb18030&:[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,3,711,168,,,16,21,,,,,,,,177,215,247,44,46,59,41,57,01,65,14,05,56,6,51,504,,167,33,78,33,50,92,307,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,62,65,68,,,,,55,58,61,64,67,70,33,36,39,42,45,48,51,14,17,20,245,,,,,,,46,49,52,55,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,931,932,933,934,935,936,937,,,,,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,963,964,965,966,967,968,969,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,42,45,47,50,53,56,59,62,65,68,71,,,,,,,,,75,05,80,83,86,89,92,95,98,01,311,,,,,,,714,715,729,29,57,00,35,06,52,55,58,61,64,67,70,73,76,79,82,85,01,04,07,10,13,19,60,99,37,,,,,,,,5,462,224,275,233,283,232,299,237,464,236,333,243,466,242,363,250,468,249,470,472,474,476,252,234,593,,505,609,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,75,78,81,84,87,90,93,96,99,02,05,08,11,14,17,20,23,26,29,32,35,38,41,44,47,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,58565],
&gb18030-ranges&:[[0,128],[36,165],[38,169],[45,178],[50,184],[81,216],[89,226],[95,235],[96,238],[100,244],[103,248],[104,251],[105,253],[109,258],[126,276],[133,284],[148,300],[172,325],[175,329],[179,334],[208,364],[306,463],[307,465],[308,467],[309,469],[310,471],[311,473],[312,475],[313,477],[341,506],[428,594],[443,610],[544,712],[545,716],[558,730],[741,930],[742,938],[749,962],[750,970],[805,1026],[819,1104],[820,1106],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[36]],
+;}(this));
@@ -0,0 +1,3307 @@
+// This is free and unencumbered software released into the public domain.
+// See LICENSE.md for more information.
+// If we're in node require encoding-indexes and attach it to the global.
+ * @fileoverview Global |this| required for resolving indexes in node.
+ * @suppress {globalThis}
+if (typeof module !== &undefined& && module.exports &&
!this[&encoding-indexes&]) {
require(&./encoding-indexes.js&);
+(function(global) {
'use strict';
// Utilities
* @param {number} a The number to test.
* @param {number} min The minimum value in the range, inclusive.
* @param {number} max The maximum value in the range, inclusive.
* @return {boolean} True if a &= min and a &= max.
function inRange(a, min, max) {
return min &= a && a &=
* @param {!Array.&*&} array The array to check.
* @param {*} item The item to look for in the array.
* @return {boolean} True if the item appears in the array.
function includes(array, item) {
return array.indexOf(item) !== -1;
var floor = Math.
* @param {*} o
* @return {Object}
function ToDictionary(o) {
if (o === undefined) return {};
if (o === Object(o))
throw TypeError('Could not convert argument to dictionary');
* @param {string} string Input string of UTF-16 code units.
* @return {!Array.&number&} Code points.
function stringToCodePoints(string) {
// https://heycam.github.io/webidl/#dfn-obtain-unicode
// 1. Let S be the DOMString value.
var s = String(string);
// 2. Let n be the length of S.
var n = s.
// 3. Initialize i to 0.
var i = 0;
// 4. Initialize U to be an empty sequence of Unicode characters.
var u = [];
// 5. While i & n:
while (i & n) {
// 1. Let c be the code unit in S at index i.
var c = s.charCodeAt(i);
// 2. Depending on the value of c:
// c & 0xD800 or c & 0xDFFF
if (c & 0xD800 || c & 0xDFFF) {
// Append to U the Unicode character with code point c.
u.push(c);
// 0xDC00 ≤ c ≤ 0xDFFF
else if (0xDC00 &= c && c &= 0xDFFF) {
// Append to U a U+FFFD REPLACEMENT CHARACTER.
u.push(0xFFFD);
// 0xD800 ≤ c ≤ 0xDBFF
else if (0xD800 &= c && c &= 0xDBFF) {
// 1. If i = n-1, then append to U a U+FFFD REPLACEMENT
// CHARACTER.
if (i === n - 1) {
u.push(0xFFFD);
// 2. Otherwise, i & n-1:
// 1. Let d be the code unit in S at index i+1.
var d = s.charCodeAt(i + 1);
// 2. If 0xDC00 ≤ d ≤ 0xDFFF, then:
if (0xDC00 &= d && d &= 0xDFFF) {
// 1. Let a be c & 0x3FF.
var a = c & 0x3FF;
// 2. Let b be d & 0x3FF.
var b = d & 0x3FF;
// 3. Append to U the Unicode character with code point
// 2^16+2^10*a+b.
u.push(0x10000 + (a && 10) + b);
// 4. Set i to i+1.
// 3. Otherwise, d & 0xDC00 or d & 0xDFFF. Append to U a
// U+FFFD REPLACEMENT CHARACTER.
u.push(0xFFFD);
// 3. Set i to i+1.
// 6. Return U.
* @param {!Array.&number&} code_points Array of code points.
* @return {string} string String of UTF-16 code units.
function codePointsToString(code_points) {
var s = '';
for (var i = 0; i & code_points. ++i) {
var cp = code_points[i];
if (cp &= 0xFFFF) {
s += String.fromCharCode(cp);
cp -= 0x10000;
s += String.fromCharCode((cp && 10) + 0xD800,
(cp & 0x3FF) + 0xDC00);
// Implementation of Encoding specification
// https://encoding.spec.whatwg.org/
// 4. Terminology
* An ASCII byte is a byte in the range 0x00 to 0x7F, inclusive.
* @param {number} a The number to test.
* @return {boolean} True if a is in the range 0x00 to 0x7F, inclusive.
function isASCIIByte(a) {
return 0x00 &= a && a &= 0x7F;
* An ASCII code point is a code point in the range U+0000 to
* U+007F, inclusive.
var isASCIICodePoint = isASCIIB
* End-of-stream is a special token that signifies no more tokens
* are in the stream.
*/ var end_of_stream = -1;
* A stream represents an ordered sequence of tokens.
* @constructor
* @param {!(Array.&number&|Uint8Array)} tokens Array of tokens that provide
* the stream.
function Stream(tokens) {
/** @type {!Array.&number&} */
this.tokens = [].slice.call(tokens);
// Reversed as push/pop is more efficient than shift/unshift.
this.tokens.reverse();
Stream.prototype = {
* @return {boolean} True if end-of-stream has been hit.
endOfStream: function() {
return !this.tokens.
* When a token is read from a stream, the first token in the
* stream must be returned and subsequently removed, and
* end-of-stream must be returned otherwise.
* @return {number} Get the next token from the stream, or
* end_of_stream.
read: function() {
if (!this.tokens.length)
return end_of_
return this.tokens.pop();
* When one or more tokens are prepended to a stream, those tokens
* must be inserted, in given order, before the first token in the
* @param {(number|!Array.&number&)} token The token(s) to prepend to the
prepend: function(token) {
if (Array.isArray(token)) {
var tokens = /**@type {!Array.&number&}*/(token);
while (tokens.length)
this.tokens.push(tokens.pop());
this.tokens.push(token);
* When one or more tokens are pushed to a stream, those tokens
* must be inserted, in given order, after the last token in the
* @param {(number|!Array.&number&)} token The tokens(s) to push to the
push: function(token) {
if (Array.isArray(token)) {
var tokens = /**@type {!Array.&number&}*/(token);
while (tokens.length)
this.tokens.unshift(tokens.shift());
this.tokens.unshift(token);
// 5. Encodings
// 5.1 Encoders and decoders
/** @const */
var finished = -1;
* @param {boolean} fatal If true, decoding errors raise an exception.
* @param {number=} opt_code_point Override the standard fallback code point.
* @return {number} The code point to insert on a decoding error.
function decoderError(fatal, opt_code_point) {
if (fatal)
throw TypeError('Decoder error');
return opt_code_point || 0xFFFD;
* @param {number} code_point The code point that could not be encoded.
* @return {number} Always throws, no value is actually returned.
function encoderError(code_point) {
throw TypeError('The code point ' + code_point + ' could not be encoded.');
/** @interface */
function Decoder() {}
Decoder.prototype = {
* @param {Stream} stream The stream of bytes being decoded.
* @param {number} bite The next byte read from the stream.
* @return {?(number|!Array.&number&)} The next code point(s)
decoded, or null if not enough data exists in the input
stream to decode a complete code point, or |finished|.
handler: function(stream, bite) {}
/** @interface */
function Encoder() {}
Encoder.prototype = {
* @param {Stream} stream The stream of code points being encoded.
* @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.&number&)} Byte(s) to emit, or |finished|.
handler: function(stream, code_point) {}
// 5.2 Names and labels
// TODO: Define @typedef for Encoding: {name:string,labels:Array.&string&}
// /google/closure-compiler/issues/247
* @param {string} label The encoding label.
* @return {?{name:string,labels:Array.&string&}}
function getEncoding(label) {
// 1. Remove any leading and trailing ASCII whitespace from label.
label = String(label).trim().toLowerCase();
// 2. If label is an ASCII case-insensitive match for any of the
// labels listed in the table below, return the corresponding
// encoding, and failure otherwise.
if (Object.prototype.hasOwnProperty.call(label_to_encoding, label)) {
return label_to_encoding[label];
* Encodings table: https://encoding.spec.whatwg.org/encodings.json
* @type {!Array.&{
heading: string,
encodings: Array.&{name:string,labels:Array.&string&}&
var encodings = [
&encodings&: [
&labels&: [
&unicode-1-1-utf-8&,
&name&: &UTF-8&
&heading&: &The Encoding&
&encodings&: [
&labels&: [
&csibm866&,
&name&: &IBM866&
&labels&: [
&csisolatin2&,
&iso-8859-2&,
&iso-ir-101&,
&iso8859-2&,
&iso88592&,
&iso_8859-2&,
&name&: &ISO-8859-2&
&labels&: [
&csisolatin3&,
&iso-8859-3&,
&iso-ir-109&,
&iso8859-3&,
&iso88593&,
&iso_8859-3&,
&name&: &ISO-8859-3&
&labels&: [
&csisolatin4&,
&iso-8859-4&,
&iso-ir-110&,
&iso8859-4&,
&iso88594&,
&iso_8859-4&,
&name&: &ISO-8859-4&
&labels&: [
&csisolatincyrillic&,
&cyrillic&,
&iso-8859-5&,
&iso-ir-144&,
&iso8859-5&,
&iso88595&,
&iso_8859-5&,
&name&: &ISO-8859-5&
&labels&: [
&asmo-708&,
&csiso88596e&,
&csiso88596i&,
&csisolatinarabic&,
&ecma-114&,
&iso-8859-6&,
&iso-8859-6-e&,
&iso-8859-6-i&,
&iso-ir-127&,
&iso8859-6&,
&iso88596&,
&iso_8859-6&,
&name&: &ISO-8859-6&
&labels&: [
&csisolatingreek&,
&ecma-118&,
&elot_928&,
&iso-8859-7&,
&iso-ir-126&,
&iso8859-7&,
&iso88597&,
&iso_8859-7&,
&sun_eu_greek&
&name&: &ISO-8859-7&
&labels&: [
&csiso88598e&,
&csisolatinhebrew&,
&iso-8859-8&,
&iso-8859-8-e&,
&iso-ir-138&,
&iso8859-8&,
&iso88598&,
&iso_8859-8&,
&name&: &ISO-8859-8&
&labels&: [
&csiso88598i&,
&iso-8859-8-i&,
&name&: &ISO-8859-8-I&
&labels&: [
&csisolatin6&,
&iso-8859-10&,
&iso-ir-157&,
&iso8859-10&,
&iso885910&,
&name&: &ISO-8859-10&
&labels&: [
&iso-8859-13&,
&iso8859-13&,
&iso885913&
&name&: &ISO-8859-13&
&labels&: [
&iso-8859-14&,
&iso8859-14&,
&iso885914&
&name&: &ISO-8859-14&
&labels&: [
&csisolatin9&,
&iso-8859-15&,
&iso8859-15&,
&iso885915&,
&iso_8859-15&,
&name&: &ISO-8859-15&
&labels&: [
&iso-8859-16&
&name&: &ISO-8859-16&
&labels&: [
&cskoi8r&,
&name&: &KOI8-R&
&labels&: [
&koi8-ru&,
&name&: &KOI8-U&
&labels&: [
&csmacintosh&,
&macintosh&,
&x-mac-roman&
&name&: &macintosh&
&labels&: [
&dos-874&,
&iso-8859-11&,
&iso8859-11&,
&iso885911&,
&tis-620&,
&windows-874&
&name&: &windows-874&
&labels&: [
&windows-1250&,
&x-cp1250&
&name&: &windows-1250&
&labels&: [
&windows-1251&,
&x-cp1251&
&name&: &windows-1251&
&labels&: [
&ansi_x3.4-1968&,
&csisolatin1&,
&iso-8859-1&,
&iso-ir-100&,
&iso8859-1&,
&iso88591&,
&iso_8859-1&,
&us-ascii&,
&windows-1252&,
&x-cp1252&
&name&: &windows-1252&
&labels&: [
&windows-1253&,
&x-cp1253&
&name&: &windows-1253&
&labels&: [
&csisolatin5&,
&iso-8859-9&,
&iso-ir-148&,
&iso8859-9&,
&iso88599&,
&iso_8859-9&,
&windows-1254&,
&x-cp1254&
&name&: &windows-1254&
&labels&: [
&windows-1255&,
&x-cp1255&
&name&: &windows-1255&
&labels&: [
&windows-1256&,
&x-cp1256&
&name&: &windows-1256&
&labels&: [
&windows-1257&,
&x-cp1257&
&name&: &windows-1257&
&labels&: [
&windows-1258&,
&x-cp1258&
&name&: &windows-1258&
&labels&: [
&x-mac-cyrillic&,
&x-mac-ukrainian&
&name&: &x-mac-cyrillic&
&heading&: &Legacy single-byte encodings&
&encodings&: [
&labels&: [
&chinese&,
&csgb2312&,
&csiso58gb231280&,
&gb_2312&,
&gb_2312-80&,
&iso-ir-58&,
&name&: &GBK&
&labels&: [
&name&: &gb18030&
&heading&: &Legacy multi-byte Chinese (simplified) encodings&
&encodings&: [
&labels&: [
&big5-hkscs&,
&cn-big5&,
&x-x-big5&
&name&: &Big5&
&heading&: &Legacy multi-byte Chinese (traditional) encodings&
&encodings&: [
&labels&: [
&cseucpkdfmtjapanese&,
&x-euc-jp&
&name&: &EUC-JP&
&labels&: [
&csiso2022jp&,
&iso-2022-jp&
&name&: &ISO-2022-JP&
&labels&: [
&csshiftjis&,
&ms_kanji&,
&shift-jis&,
&shift_jis&,
&windows-31j&,
&name&: &Shift_JIS&
&heading&: &Legacy multi-byte Japanese encodings&
&encodings&: [
&labels&: [
&cseuckr&,
&iso-ir-149&,
&ksc5601&,
&ksc_5601&,
&windows-949&
&name&: &EUC-KR&
&heading&: &Legacy multi-byte Korean encodings&
&encodings&: [
&labels&: [
&csiso2022kr&,
&hz-gb-2312&,
&iso-2022-cn&,
&iso-2022-cn-ext&,
&iso-2022-kr&
&name&: &replacement&
&labels&: [
&utf-16be&
&name&: &UTF-16BE&
&labels&: [
&utf-16le&
&name&: &UTF-16LE&
&labels&: [
&x-user-defined&
&name&: &x-user-defined&
&heading&: &Legacy miscellaneous encodings&
// Label to encoding registry.
/** @type {Object.&string,{name:string,labels:Array.&string&}&} */
var label_to_encoding = {};
encodings.forEach(function(category) {
category.encodings.forEach(function(encoding) {
encoding.labels.forEach(function(label) {
label_to_encoding[label] =
// Registry of of encoder/decoder factories, by encoding name.
/** @type {Object.&string, function({fatal:boolean}): Encoder&} */
var encoders = {};
/** @type {Object.&string, function({fatal:boolean}): Decoder&} */
var decoders = {};
// 6. Indexes
* @param {number} pointer The |pointer| to search for.
* @param {(!Array.&?number&|undefined)} index The |index| to search within.
* @return {?number} The code point corresponding to |pointer| in |index|,
or null if |code point| is not in |index|.
function indexCodePointFor(pointer, index) {
if (!index)
return index[pointer] ||
* @param {number} code_point The |code point| to search for.
* @param {!Array.&?number&} index The |index| to search within.
* @return {?number} The first pointer corresponding to |code point| in
|index|, or null if |code point| is not in |index|.
function indexPointerFor(code_point, index) {
var pointer = index.indexOf(code_point);
return pointer === -1 ? null :
* @param {string} name Name of the index.
* @return {(!Array.&number&|!Array.&Array.&number&&)}
function index(name) {
if (!('encoding-indexes' in global)) {
throw Error(&Indexes missing.& +
& Did you forget to include encoding-indexes.js first?&);
return global['encoding-indexes'][name];
* @param {number} pointer The |pointer| to search for in the gb18030 index.
* @return {?number} The code point corresponding to |pointer| in |index|,
or null if |code point| is not in the gb18030 index.
function indexGB18030RangesCodePointFor(pointer) {
// 1. If pointer is greater than 39419 and less than 189000, or
// pointer is greater than 1237575, return null.
if ((pointer & 39419 && pointer & 189000) || (pointer & 1237575))
// 2. If pointer is 7457, return code point U+E7C7.
if (pointer === 7457) return 0xE7C7;
// 3. Let offset be the last pointer in index gb18030 ranges that
// is equal to or less than pointer and let code point offset be
// its corresponding code point.
var offset = 0;
var code_point_offset = 0;
var idx = index('gb18030-ranges');
for (i = 0; i & idx. ++i) {
/** @type {!Array.&number&} */
var entry = idx[i];
if (entry[0] &= pointer) {
offset = entry[0];
code_point_offset = entry[1];
// 4. Return a code point whose value is code point offset +
// pointer - offset.
return code_point_offset + pointer -
* @param {number} code_point The |code point| to locate in the gb18030 index.
* @return {number} The first pointer corresponding to |code point| in the
gb18030 index.
function indexGB18030RangesPointerFor(code_point) {
// 1. If code point is U+E7C7, return pointer 7457.
if (code_point === 0xE7C7) return 7457;
// 2. Let offset be the last code point in index gb18030 ranges
// that is equal to or less than code point and let pointer offset
// be its corresponding pointer.
var offset = 0;
var pointer_offset = 0;
var idx = index('gb18030-ranges');
for (i = 0; i & idx. ++i) {
/** @type {!Array.&number&} */
var entry = idx[i];
if (entry[1] &= code_point) {
offset = entry[1];
pointer_offset = entry[0];
// 3. Return a pointer whose value is pointer offset + code point
// - offset.
return pointer_offset + code_point -
* @param {number} code_point The |code_point| to search for in the Shift_JIS
* @return {?number} The code point corresponding to |pointer| in |index|,
or null if |code point| is not in the Shift_JIS index.
function indexShiftJISPointerFor(code_point) {
// 1. Let index be index jis0208 excluding all entries whose
// pointer is in the range 8272 to 8835, inclusive.
shift_jis_index = shift_jis_index ||
index('jis0208').map(function(code_point, pointer) {
return inRange(pointer, ) ? null : code_
var index_ = shift_jis_
// 2. Return the index pointer for code point in index.
return index_.indexOf(code_point);
var shift_jis_
* @param {number} code_point The |code_point| to search for in the big5
* @return {?number} The code point corresponding to |pointer| in |index|,
or null if |code point| is not in the big5 index.
function indexBig5PointerFor(code_point) {
// 1. Let index be index Big5 excluding all entries whose pointer
big5_index_no_hkscs = big5_index_no_hkscs ||
index('big5').map(function(code_point, pointer) {
return (pointer & (0xA1 - 0x81) * 157) ? null : code_
var index_ = big5_index_no_
// 2. If code point is U+2550, U+255E, U+2561, U+256A, U+5341, or
// U+5345, return the last pointer corresponding to code point in
if (code_point === 0x2550 || code_point === 0x255E ||
code_point === 0x2561 || code_point === 0x256A ||
code_point === 0x5341 || code_point === 0x5345) {
return index_.lastIndexOf(code_point);
// 3. Return the index pointer for code point in index.
return indexPointerFor(code_point, index_);
var big5_index_no_
/** @const */ var DEFAULT_ENCODING = 'utf-8';
// 8.1 Interface TextDecoder
* @constructor
* @param {string=} label The l
defaults to 'utf-8'.
* @param {Object=} options
function TextDecoder(label, options) {
// Web IDL conventions
if (!(this instanceof TextDecoder))
throw TypeError('Called as a function. Did you forget \'new\'?');
label = label !== undefined ? String(label) : DEFAULT_ENCODING;
options = ToDictionary(options);
// A TextDecoder object has an associated encoding, decoder,
// stream, ignore BOM flag (initially unset), BOM seen flag
// (initially unset), error mode (initially replacement), and do
// not flush flag (initially unset).
/** @private */
this._encoding =
/** @private @type {?Decoder} */
this._decoder =
/** @private @type {boolean} */
this._ignoreBOM =
/** @private @type {boolean} */
this._BOMseen =
/** @private @type {string} */
this._error_mode = 'replacement';
/** @private @type {boolean} */
this._do_not_flush =
// 1. Let encoding be the result of getting an encoding from
var encoding = getEncoding(label);
// 2. If encoding is failure or replacement, throw a RangeError.
if (encoding === null || encoding.name === 'replacement')
throw RangeError('Unknown encoding: ' + label);
if (!decoders[encoding.name]) {
throw Error('Decoder not present.' +
' Did you forget to include encoding-indexes.js first?');
// 3. Let dec be a new TextDecoder object.
// 4. Set dec's encoding to encoding.
dec._encoding =
// 5. If options's fatal member is true, set dec's error mode to
if (Boolean(options['fatal']))
dec._error_mode = 'fatal';
// 6. If options's ignoreBOM member is true, set dec's ignore BOM
if (Boolean(options['ignoreBOM']))
dec._ignoreBOM =
// For pre-ES5 runtimes:
if (!Object.defineProperty) {
this.encoding = dec._encoding.name.toLowerCase();
this.fatal = dec._error_mode === 'fatal';
this.ignoreBOM = dec._ignoreBOM;
// 7. Return dec.
if (Object.defineProperty) {
// The encoding attribute's getter must return encoding's name.
Object.defineProperty(TextDecoder.prototype, 'encoding', {
/** @this {TextDecoder} */
get: function() { return this._encoding.name.toLowerCase(); }
// The fatal attribute's getter must return true if error mode
// is fatal, and false otherwise.
Object.defineProperty(TextDecoder.prototype, 'fatal', {
/** @this {TextDecoder} */
get: function() { return this._error_mode === 'fatal'; }
// The ignoreBOM attribute's getter must return true if ignore
// BOM flag is set, and false otherwise.
Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', {
/** @this {TextDecoder} */
get: function() { return this._ignoreBOM; }
* @param {BufferSource=} input The buffer of bytes to decode.
* @param {Object=} options
* @return {string} The decoded string.
TextDecoder.prototype.decode = function decode(input, options) {
if (typeof input === 'object' && input instanceof ArrayBuffer) {
bytes = new Uint8Array(input);
} else if (typeof input === 'object' && 'buffer' in input &&
input.buffer instanceof ArrayBuffer) {
bytes = new Uint8Array(input.buffer,
input.byteOffset,
input.byteLength);
bytes = new Uint8Array(0);
options = ToDictionary(options);
// 1. If the do not flush flag is unset, set decoder to a new
// encoding's decoder, set stream to a new stream, and unset the
// BOM seen flag.
if (!this._do_not_flush) {
this._decoder = decoders[this._encoding.name]({
fatal: this._error_mode === 'fatal'});
this._BOMseen =
// 2. If options's stream is true, set the do not flush flag, and
// unset the do not flush flag otherwise.
this._do_not_flush = Boolean(options['stream']);
// 3. If input is given, push a copy of input to stream.
// TODO: Align with spec algorithm - maintain stream on instance.
var input_stream = new Stream(bytes);
// 4. Let output be a new stream.
var output = [];
/** @type {?(number|!Array.&number&)} */
// 5. While true:
while (true) {
// 1. Let token be the result of reading from stream.
var token = input_stream.read();
// 2. If token is end-of-stream and the do not flush flag is
// set, return output, serialized.
// TODO: Align with spec algorithm.
if (token === end_of_stream)
// 3. Otherwise, run these subsubsteps:
// 1. Let result be the result of processing token for decoder,
// stream, output, and error mode.
result = this._decoder.handler(input_stream, token);
// 2. If result is finished, return output, serialized.
if (result === finished)
if (result !== null) {
if (Array.isArray(result))
output.push.apply(output, /**@type {!Array.&number&}*/(result));
output.push(result);
// 3. Otherwise, if result is error, throw a TypeError.
// (Thrown in handler)
// 4. Otherwise, do nothing.
// TODO: Align with spec algorithm.
if (!this._do_not_flush) {
result = this._decoder.handler(input_stream, input_stream.read());
if (result === finished)
if (result === null)
if (Array.isArray(result))
output.push.apply(output, /**@type {!Array.&number&}*/(result));
output.push(result);
} while (!input_stream.endOfStream());
this._decoder =
// A TextDecoder object also has an associated serialize stream
// algorithm...
* @param {!Array.&number&} stream
* @return {string}
* @this {TextDecoder}
function serializeStream(stream) {
// 1. Let token be the result of reading from stream.
// (Done in-place on array, rather than as a stream)
// 2. If encoding is UTF-8, UTF-16BE, or UTF-16LE, and ignore
// BOM flag and BOM seen flag are unset, run these subsubsteps:
if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) &&
!this._ignoreBOM && !this._BOMseen) {
if (stream.length & 0 && stream[0] === 0xFEFF) {
// 1. If token is U+FEFF, set BOM seen flag.
this._BOMseen =
stream.shift();
} else if (stream.length & 0) {
// 2. Otherwise, if token is not end-of-stream, set BOM seen
// flag and append token to stream.
this._BOMseen =
// 3. Otherwise, if token is not end-of-stream, append token
// to output.
// (no-op)
// 4. Otherwise, return output.
return codePointsToString(stream);
return serializeStream.call(this, output);
// 8.2 Interface TextEncoder
* @constructor
* @param {string=} label The label of the encoding. NONSTANDARD.
* @param {Object=} options NONSTANDARD.
function TextEncoder(label, options) {
// Web IDL conventions
if (!(this instanceof TextEncoder))
throw TypeError('Called as a function. Did you forget \'new\'?');
options = ToDictionary(options);
// A TextEncoder object has an associated encoding and encoder.
/** @private */
this._encoding =
/** @private @type {?Encoder} */
this._encoder =
// Non-standard
/** @private @type {boolean} */
this._do_not_flush =
/** @private @type {string} */
this._fatal = Boolean(options['fatal']) ? 'fatal' : 'replacement';
// 1. Let enc be a new TextEncoder object.
// 2. Set enc's encoding to UTF-8's encoder.
if (Boolean(options['NONSTANDARD_allowLegacyEncoding'])) {
// NONSTANDARD behavior.
label = label !== undefined ? String(label) : DEFAULT_ENCODING;
var encoding = getEncoding(label);
if (encoding === null || encoding.name === 'replacement')
throw RangeError('Unknown encoding: ' + label);
if (!encoders[encoding.name]) {
throw Error('Encoder not present.' +
' Did you forget to include encoding-indexes.js first?');
enc._encoding =
// Standard behavior.
enc._encoding = getEncoding('utf-8');
if (label !== undefined && 'console' in global) {
console.warn('TextEncoder constructor called with encoding label, '
+ 'which is ignored.');
// For pre-ES5 runtimes:
if (!Object.defineProperty)
this.encoding = enc._encoding.name.toLowerCase();
// 3. Return enc.
if (Object.defineProperty) {
// The encoding attribute's getter must return

我要回帖

更多关于 21160 的文章

 

随机推荐