Merge pull request #880 from nonameShijian/PR-Branch
过时特性改为用trace提示, 默认参数额外加入判断,判断exe如果有启动参数则不自动打开默认浏览器,添加升级逻辑
This commit is contained in:
commit
98e8edbc74
157
game/entry.js
157
game/entry.js
|
@ -1,24 +1,5 @@
|
|||
/*
|
||||
const module = import('../noname.js');
|
||||
|
||||
module.then(({ ai, game, get, lib, _status, ui, boot }) => {
|
||||
const coreAndVersion = get.coreInfo();
|
||||
const core = coreAndVersion[0], version = coreAndVersion[1];
|
||||
if (core === 'chrome' && !isNaN(version) && version < 77) {
|
||||
const tip = '检测到您的浏览器内核版本小于77,请及时升级浏览器或手机webview内核!';
|
||||
console.warn(tip);
|
||||
game.print(tip);
|
||||
const redirect_tip = '您使用的浏览器或无名杀客户端内核版本过低,将在未来的版本被废弃!\n点击“确认”以前往GitHub下载最新版无名杀客户端(可能需要科学上网)。';
|
||||
if (confirm(redirect_tip)) {
|
||||
window.open('https://github.com/libccy/noname/releases/tag/chromium77-client');
|
||||
}
|
||||
}
|
||||
boot().then(lib.other.ignore);
|
||||
});
|
||||
*/
|
||||
|
||||
import { game, get, lib, boot } from "../noname.js";
|
||||
// import { canUseHttpProtocol } from "../noname/init/index.js";
|
||||
import { canUseHttpProtocol, sendUpdate } from "../noname/init/index.js";
|
||||
import { userAgent } from "../noname/util/index.js";
|
||||
|
||||
const coreAndVersion = get.coreInfo();
|
||||
|
@ -33,21 +14,123 @@ if (core === 'chrome' && !isNaN(version) && version < 77) {
|
|||
}
|
||||
}
|
||||
|
||||
// 判断是否从file协议切换到http/s协议
|
||||
// if (canUseHttpProtocol()) {
|
||||
/*
|
||||
升级方法一:
|
||||
1. 导出数据,然后以http/s协议重启
|
||||
2. 以http/s协议导入数据
|
||||
3. 保存http/s协议的状态,以后不再以file协议启动
|
||||
升级方法二:
|
||||
1. app默认以http/s协议启动,发现没有数据后,以file协议重启
|
||||
2. 以file协议导出数据
|
||||
3. 以http/s协议重启,导入数据
|
||||
*/
|
||||
// 导出数据到根目录的noname.config.txt
|
||||
// 成功导入后应删除noname.config.txt
|
||||
// } else {
|
||||
boot().then(lib.other.ignore);
|
||||
// }
|
||||
boot().then(() => {
|
||||
// 判断是否从file协议切换到http/s协议
|
||||
if (canUseHttpProtocol()) {
|
||||
/*
|
||||
升级方法:
|
||||
1. 游戏启动后导出数据,然后以http/s协议重启
|
||||
2. 以http/s协议导入数据
|
||||
3. 保存http/s协议的状态,以后不再以file协议启动
|
||||
*/
|
||||
// 导出数据到根目录的noname.config.txt
|
||||
let data;
|
||||
let export_data = function (data) {
|
||||
game.promises.writeFile(lib.init.encode(JSON.stringify(data)), './', 'noname.config.txt')
|
||||
.then(saveProtocol)
|
||||
.catch(e => {
|
||||
console.error('升级失败:', e);
|
||||
});
|
||||
};
|
||||
// @ts-ignore
|
||||
if (!lib.db) {
|
||||
data = {};
|
||||
for (let i in localStorage) {
|
||||
if (i.startsWith(lib.configprefix)) {
|
||||
data[i] = localStorage[i];
|
||||
}
|
||||
}
|
||||
export_data(data);
|
||||
}
|
||||
else {
|
||||
game.getDB('config', null, function (data1) {
|
||||
game.getDB('data', null, function (data2) {
|
||||
export_data({
|
||||
config: data1,
|
||||
data: data2
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
// 保存协议的切换状态
|
||||
function saveProtocol() {
|
||||
const url = sendUpdate();
|
||||
if (typeof url == 'string') {
|
||||
if (typeof window.require == 'function' && typeof window.process == 'object') {
|
||||
// @ts-ignore
|
||||
const remote = require('@electron/remote');
|
||||
const thisWindow = remote.getCurrentWindow();
|
||||
thisWindow.loadURL(url);
|
||||
} else {
|
||||
location.href = url;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 成功导入后删除noname.config.txt
|
||||
let searchParams = new URLSearchParams(location.search);
|
||||
for (let [key, value] of searchParams) {
|
||||
if (key === 'sendUpdate' && value === 'true') {
|
||||
game.promises.readFileAsText('noname.config.txt').then(data => {
|
||||
return /** @type {Promise<void>} */(new Promise(async (resolve, reject) => {
|
||||
if (!data) return reject('!data');
|
||||
try {
|
||||
data = JSON.parse(lib.init.decode(data));
|
||||
if (!data || typeof data != 'object') {
|
||||
throw ('err');
|
||||
}
|
||||
// @ts-ignore
|
||||
if (lib.db && (!data.config || !data.data)) {
|
||||
throw ('err');
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
if (e == 'err') {
|
||||
alert('导入文件格式不正确');
|
||||
reject('导入文件格式不正确');
|
||||
} else {
|
||||
alert('导入失败: ' + e.message);
|
||||
reject('导入失败: ' + e.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
alert('导入成功, 即将自动重启');
|
||||
// @ts-ignore
|
||||
if (!lib.db) {
|
||||
const noname_inited = localStorage.getItem('noname_inited');
|
||||
const onlineKey = localStorage.getItem(lib.configprefix + 'key');
|
||||
localStorage.clear();
|
||||
if (noname_inited) {
|
||||
localStorage.setItem('noname_inited', noname_inited);
|
||||
}
|
||||
if (onlineKey) {
|
||||
localStorage.setItem(lib.configprefix + 'key', onlineKey);
|
||||
}
|
||||
for (let i in data) {
|
||||
localStorage.setItem(i, data[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let i in data.config) {
|
||||
await game.putDB('config', i, data.config[i]);
|
||||
lib.config[i] = data.config[i];
|
||||
}
|
||||
for (let i in data.data) {
|
||||
await game.putDB('data', i, data.data[i]);
|
||||
}
|
||||
}
|
||||
lib.init.background();
|
||||
resolve();
|
||||
}));
|
||||
}).then(() => {
|
||||
return game.promises.removeFile('noname.config.txt');
|
||||
}).then(() => {
|
||||
const url = new URL(location.href);
|
||||
location.href = url.origin + url.pathname;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
17
game/game.js
17
game/game.js
|
@ -86,6 +86,23 @@ new Promise(resolve => {
|
|||
exit()
|
||||
}
|
||||
else {
|
||||
// 在http环境下修改__dirname
|
||||
if (location.protocol.startsWith('http') &&
|
||||
typeof window.require == 'function' &&
|
||||
typeof window.process == 'object' &&
|
||||
typeof window.__dirname == 'string' &&
|
||||
window.__dirname.endsWith('electron.asar\\renderer')) {
|
||||
const path = require('path');
|
||||
window.__dirname = path.join(path.resolve(), 'resources/app');
|
||||
// @ts-ignore
|
||||
window.require = function (moduleId) {
|
||||
try {
|
||||
return module.require(moduleId);
|
||||
} catch {
|
||||
return module.require(path.join(window.__dirname, moduleId));
|
||||
}
|
||||
};
|
||||
}
|
||||
const script = document.createElement('script')
|
||||
script.type = "module";
|
||||
script.src = `${assetURL}game/entry.js`;
|
||||
|
|
|
@ -1384,7 +1384,12 @@ declare interface Skill {
|
|||
/** 规则技能 */
|
||||
ruleSkill?: boolean;
|
||||
|
||||
zhuanhuanji?: 'number' | boolean | ((player: Player, skill: string) => any);
|
||||
zhuanhuanji?: 'number' | boolean | ((player: Player, skill: string) => any);
|
||||
|
||||
/**
|
||||
* 手动设置技能的标签
|
||||
*/
|
||||
categories?: (skill: string, player: Player) => string[];
|
||||
|
||||
//日后还有很多属性要添加的
|
||||
[key: string]: any;
|
||||
|
|
Binary file not shown.
|
@ -7860,7 +7860,7 @@ export class Game extends Uninstantable {
|
|||
/**
|
||||
*
|
||||
* @param { string } storeName
|
||||
* @param { string } [query]
|
||||
* @param { string | null } [query]
|
||||
* @param { Function } [onSuccess]
|
||||
* @param { Function } [onError]
|
||||
*/
|
||||
|
|
|
@ -92,4 +92,12 @@ export class GamePromises extends Uninstantable {
|
|||
game.createDir(directory, resolve, reject);
|
||||
});
|
||||
}
|
||||
static removeFile(filename) {
|
||||
return /** @type {Promise<void>} */(new Promise((resolve, reject) => {
|
||||
game.removeFile(filename, err => {
|
||||
if (err) reject(err);
|
||||
else resolve();
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -265,8 +265,13 @@ export class Get extends Uninstantable {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param { string } skill
|
||||
* @param { Player } player
|
||||
* @returns { string[] }
|
||||
*/
|
||||
static skillCategoriesOf(skill, player) {
|
||||
var list = [], info = get.info(skill);
|
||||
const list = [], info = get.info(skill);
|
||||
if (!info) return list;
|
||||
if (get.is.locked(skill, player)) list.add('锁定技');
|
||||
if (info.zhuSkill) list.add('主公技');
|
||||
|
|
|
@ -22,19 +22,22 @@ export function canUseHttpProtocol() {
|
|||
// 手机端
|
||||
if (window.cordova) {
|
||||
// 直接确定包名
|
||||
if (nonameInitialized.includes('com.noname.shijian')) {
|
||||
if (nonameInitialized.endsWith('com.noname.shijian/')) {
|
||||
// 每个app自定义能升级的渠道,比如判断版本
|
||||
// @ts-ignore
|
||||
window.noname_shijianInterfaces.getApkVersion() >= 16000;
|
||||
return window.noname_shijianInterfaces.getApkVersion() >= 16000;
|
||||
}
|
||||
}
|
||||
// 电脑端
|
||||
else if (typeof window.require == 'function' && typeof window.process == 'object') {
|
||||
try {
|
||||
require('express');
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
// 从json判断版本号
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
if (fs.existsSync(path.join(__dirname, 'package.json'))) {
|
||||
// @ts-ignore
|
||||
const json = require('./package.json');
|
||||
// 诗笺电脑版的判断
|
||||
return json && Number(json.installerVersion) >= 1.7;
|
||||
}
|
||||
}
|
||||
// 浏览器端
|
||||
|
@ -45,6 +48,44 @@ export function canUseHttpProtocol() {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 传递升级完成的信息
|
||||
* @returns { string | void } 返回一个网址
|
||||
*/
|
||||
export function sendUpdate() {
|
||||
// 手机端
|
||||
if (window.cordova) {
|
||||
// 直接确定包名
|
||||
if (nonameInitialized && nonameInitialized.includes('com.noname.shijian')) {
|
||||
// 给诗笺版apk的java层传递升级完成的信息
|
||||
// @ts-ignore
|
||||
return window.noname_shijianInterfaces.sendUpdate() + '?sendUpdate=true';
|
||||
}
|
||||
}
|
||||
// 电脑端
|
||||
else if (typeof window.require == 'function' && typeof window.process == 'object') {
|
||||
// 从json判断版本号
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
if (fs.existsSync(path.join(__dirname, 'package.json'))) {
|
||||
// @ts-ignore
|
||||
const json = require('./package.json');
|
||||
// 诗笺电脑版的判断
|
||||
if (json && Number(json.installerVersion) >= 1.7) {
|
||||
fs.writeFileSync(path.join(__dirname, 'Home', 'saveProtocol.txt'), '');
|
||||
// 启动http
|
||||
const cp = require('child_process');
|
||||
cp.exec(`start /min ${__dirname}\\noname-server.exe -platform=electron`, (err, stdout, stderr) => { });
|
||||
return `http://localhost:8089/app.html?sendUpdate=true`;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 浏览器端
|
||||
else {
|
||||
return location.href;
|
||||
}
|
||||
}
|
||||
|
||||
// 无名杀,启动!
|
||||
export async function boot() {
|
||||
// 不想看,反正别动
|
||||
|
|
|
@ -9,7 +9,7 @@ import { UI as ui } from '../ui/index.js';
|
|||
// 改为HTMLDivElement.prototype.addTempClass
|
||||
HTMLDivElement.prototype.animate = function (keyframes, options) {
|
||||
if (typeof keyframes == 'string') {
|
||||
console.warn(this, '无名杀开发者修改的animate方法已废弃,请改为使用addTempClass方法');
|
||||
console.trace(this, '无名杀开发者修改的animate方法已废弃,请改为使用addTempClass方法');
|
||||
return HTMLDivElement.prototype.addTempClass.call(this, keyframes, options);
|
||||
}
|
||||
else return HTMLElement.prototype.animate.call(this, keyframes, options);
|
||||
|
@ -255,7 +255,7 @@ HTMLTableElement.prototype.get = function (row, col) {
|
|||
};
|
||||
/*处理lib.nature等从array改为map的兼容性问题*/
|
||||
const mapHasFunc = function (item) {
|
||||
console.warn(this, '已经从array改为map,请改为使用has方法');
|
||||
console.trace(this, '已经从array改为map,请改为使用has方法');
|
||||
return this.has(item);
|
||||
}
|
||||
Object.defineProperty(Map.prototype, "contains", {
|
||||
|
@ -271,7 +271,7 @@ Object.defineProperty(Map.prototype, "includes", {
|
|||
value: mapHasFunc
|
||||
});
|
||||
const mapAddFunc = function (item) {
|
||||
console.warn(this, '已经从array改为map,请改为使用set方法');
|
||||
console.trace(this, '已经从array改为map,请改为使用set方法');
|
||||
this.set(item, 0);
|
||||
return this;
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ Object.defineProperty(Map.prototype, "remove", {
|
|||
enumerable: false,
|
||||
writable: true,
|
||||
value: function (item) {
|
||||
console.warn(this, '已经从array改为map,请改为使用delete方法');
|
||||
console.trace(this, '已经从array改为map,请改为使用delete方法');
|
||||
this.delete(item);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -654,7 +654,14 @@ export class Player extends HTMLDivElement {
|
|||
* @param { (card: Card) => boolean } [filter]
|
||||
*/
|
||||
getKnownCards(other = _status.event.player, filter = card => true) {
|
||||
if (!other) other = this;
|
||||
if (!other) {
|
||||
if (other === null) console.trace(`getKnownCards的other参数不应传入null,可以用void 0或undefined占位`);
|
||||
other = _status.event.player || this;
|
||||
}
|
||||
if (!filter) {
|
||||
if (other === null) console.trace(`getKnownCards的filter参数不应传入null,可以用void 0或undefined占位`);
|
||||
filter = card => true;
|
||||
}
|
||||
return this.getCards('h', card => {
|
||||
return card.isKnownBy(other) && filter(card);
|
||||
});
|
||||
|
@ -664,6 +671,10 @@ export class Player extends HTMLDivElement {
|
|||
* @param { Player } [other]
|
||||
*/
|
||||
isAllCardsKnown(other = _status.event.player) {
|
||||
if (!other) {
|
||||
if (other === null) console.trace(`isAllCardsKnown的other参数不应传入null,可以用void 0或undefined占位`);
|
||||
other = _status.event.player || this;
|
||||
}
|
||||
if (!other) other = this;
|
||||
return this.countCards('h', card => {
|
||||
return !card.isKnownBy(other);
|
||||
|
@ -675,7 +686,14 @@ export class Player extends HTMLDivElement {
|
|||
* @param { (card: Card) => boolean } [filter]
|
||||
*/
|
||||
hasKnownCards(other = _status.event.player, filter = card => true) {
|
||||
if (!other) other = this;
|
||||
if (!other) {
|
||||
if (other === null) console.trace(`hasKnownCards的other参数不应传入null,可以用void 0或undefined占位`);
|
||||
other = _status.event.player || this;
|
||||
}
|
||||
if (!filter) {
|
||||
if (other === null) console.trace(`hasKnownCards的filter参数不应传入null,可以用void 0或undefined占位`);
|
||||
filter = card => true;
|
||||
}
|
||||
return this.countCards('h', card => {
|
||||
return card.isKnownBy(other) && filter(card);
|
||||
}) > 0;
|
||||
|
@ -808,10 +826,16 @@ export class Player extends HTMLDivElement {
|
|||
if (cards && !isArray) recast.cards = [cards];
|
||||
else if (isArray && cards.length) recast.cards = cards;
|
||||
else _status.event.next.remove(recast);
|
||||
if (typeof recastingLose != 'function') recastingLose = (player, cards) => player.loseToDiscardpile(cards).log = false;
|
||||
if (typeof recastingLose != 'function') {
|
||||
if (recastingLose === null) console.trace(`recast的recastingLose参数不应传入null,可以用void 0或undefined占位`);
|
||||
recastingLose = (player, cards) => player.loseToDiscardpile(cards).log = false;
|
||||
}
|
||||
recast.recastingLose = recastingLose;
|
||||
recast.recastingLosingEvents = [];
|
||||
if (typeof recastingGain != 'function') recastingGain = (player, cards) => player.draw(cards.length).log = false;
|
||||
if (typeof recastingGain != 'function') {
|
||||
if (recastingLose === null) console.trace(`recast的recastingGain参数不应传入null,可以用void 0或undefined占位`);
|
||||
recastingGain = (player, cards) => player.draw(cards.length).log = false;
|
||||
}
|
||||
recast.recastingGain = recastingGain;
|
||||
recast.recastingGainingEvents = [];
|
||||
recast.setContent('recast');
|
||||
|
|
|
@ -9669,7 +9669,10 @@ export class Library extends Uninstantable {
|
|||
* @param { boolean } [strict]
|
||||
*/
|
||||
cardRecastable: (card, player = get.owner(card), source, strict) => {
|
||||
// if (typeof player == 'undefined') player = get.owner(card);
|
||||
if (!player) {
|
||||
if (player === null) console.trace(`cardRecastable的player参数不应传入null,可以用void 0或undefined占位`);
|
||||
player = get.owner(card);
|
||||
}
|
||||
const mod = game.checkMod(card, player, source, 'unchanged', 'cardRecastable', player);
|
||||
if (!mod) return false;
|
||||
if (strict && mod == 'unchanged') {
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
export const nonameInitialized = localStorage.getItem('noname_inited');
|
||||
export const assetURL = location.protocol.startsWith('http') || typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized;
|
||||
export const GeneratorFunction = (function* () { }).constructor;
|
||||
export const AsyncFunction = (async function () { }).constructor;
|
||||
export const GeneratorFunction = (function* () {}).constructor;
|
||||
export const AsyncFunction = (async function () {}).constructor;
|
||||
export const userAgent = navigator.userAgent.toLowerCase();
|
||||
export { Mutex } from './mutex.js';
|
||||
export const characterDefaultPicturePath = "image/character/default_silhouette_";
|
||||
|
||||
// 我靠循环引用问题在这?
|
||||
// export * as config from './config.js'
|
||||
|
||||
/**
|
||||
* 不能被new的类
|
||||
*/
|
||||
|
@ -19,7 +16,7 @@ export class Uninstantable {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 暂停x毫秒
|
||||
* @param { number } ms
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue