Merge pull request #880 from nonameShijian/PR-Branch

过时特性改为用trace提示, 默认参数额外加入判断,判断exe如果有启动参数则不自动打开默认浏览器,添加升级逻辑
This commit is contained in:
Spmario233 2024-01-30 22:39:00 +08:00 committed by GitHub
commit 98e8edbc74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 245 additions and 62 deletions

View File

@ -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 { 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"; import { userAgent } from "../noname/util/index.js";
const coreAndVersion = get.coreInfo(); const coreAndVersion = get.coreInfo();
@ -33,21 +14,123 @@ if (core === 'chrome' && !isNaN(version) && version < 77) {
} }
} }
boot().then(() => {
// 判断是否从file协议切换到http/s协议 // 判断是否从file协议切换到http/s协议
// if (canUseHttpProtocol()) { if (canUseHttpProtocol()) {
/* /*
升级方法: 升级方法:
1. 导出数据然后以http/s协议重启 1. 游戏启动后导出数据然后以http/s协议重启
2. 以http/s协议导入数据 2. 以http/s协议导入数据
3. 保存http/s协议的状态以后不再以file协议启动 3. 保存http/s协议的状态以后不再以file协议启动
升级方法二:
1. app默认以http/s协议启动发现没有数据后以file协议重启
2. 以file协议导出数据
3. 以http/s协议重启导入数据
*/ */
// 导出数据到根目录的noname.config.txt // 导出数据到根目录的noname.config.txt
// 成功导入后应删除noname.config.txt let data;
// } else { let export_data = function (data) {
boot().then(lib.other.ignore); 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;
});
}
}
}
});

View File

@ -86,6 +86,23 @@ new Promise(resolve => {
exit() exit()
} }
else { 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') const script = document.createElement('script')
script.type = "module"; script.type = "module";
script.src = `${assetURL}game/entry.js`; script.src = `${assetURL}game/entry.js`;

View File

@ -1386,6 +1386,11 @@ declare interface Skill {
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; [key: string]: any;
} }

Binary file not shown.

View File

@ -7860,7 +7860,7 @@ export class Game extends Uninstantable {
/** /**
* *
* @param { string } storeName * @param { string } storeName
* @param { string } [query] * @param { string | null } [query]
* @param { Function } [onSuccess] * @param { Function } [onSuccess]
* @param { Function } [onError] * @param { Function } [onError]
*/ */

View File

@ -92,4 +92,12 @@ export class GamePromises extends Uninstantable {
game.createDir(directory, resolve, reject); 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();
});
}));
}
} }

View File

@ -265,8 +265,13 @@ export class Get extends Uninstantable {
} }
return null; return null;
} }
/**
* @param { string } skill
* @param { Player } player
* @returns { string[] }
*/
static skillCategoriesOf(skill, player) { static skillCategoriesOf(skill, player) {
var list = [], info = get.info(skill); const list = [], info = get.info(skill);
if (!info) return list; if (!info) return list;
if (get.is.locked(skill, player)) list.add('锁定技'); if (get.is.locked(skill, player)) list.add('锁定技');
if (info.zhuSkill) list.add('主公技'); if (info.zhuSkill) list.add('主公技');

View File

@ -22,19 +22,22 @@ export function canUseHttpProtocol() {
// 手机端 // 手机端
if (window.cordova) { if (window.cordova) {
// 直接确定包名 // 直接确定包名
if (nonameInitialized.includes('com.noname.shijian')) { if (nonameInitialized.endsWith('com.noname.shijian/')) {
// 每个app自定义能升级的渠道比如判断版本 // 每个app自定义能升级的渠道比如判断版本
// @ts-ignore // @ts-ignore
window.noname_shijianInterfaces.getApkVersion() >= 16000; return window.noname_shijianInterfaces.getApkVersion() >= 16000;
} }
} }
// 电脑端 // 电脑端
else if (typeof window.require == 'function' && typeof window.process == 'object') { else if (typeof window.require == 'function' && typeof window.process == 'object') {
try { // 从json判断版本号
require('express'); const fs = require('fs');
return true; const path = require('path');
} catch { if (fs.existsSync(path.join(__dirname, 'package.json'))) {
return false; // @ts-ignore
const json = require('./package.json');
// 诗笺电脑版的判断
return json && Number(json.installerVersion) >= 1.7;
} }
} }
// 浏览器端 // 浏览器端
@ -45,6 +48,44 @@ export function canUseHttpProtocol() {
return false; 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() { export async function boot() {
// 不想看,反正别动 // 不想看,反正别动

View File

@ -9,7 +9,7 @@ import { UI as ui } from '../ui/index.js';
// 改为HTMLDivElement.prototype.addTempClass // 改为HTMLDivElement.prototype.addTempClass
HTMLDivElement.prototype.animate = function (keyframes, options) { HTMLDivElement.prototype.animate = function (keyframes, options) {
if (typeof keyframes == 'string') { if (typeof keyframes == 'string') {
console.warn(this, '无名杀开发者修改的animate方法已废弃请改为使用addTempClass方法'); console.trace(this, '无名杀开发者修改的animate方法已废弃请改为使用addTempClass方法');
return HTMLDivElement.prototype.addTempClass.call(this, keyframes, options); return HTMLDivElement.prototype.addTempClass.call(this, keyframes, options);
} }
else return HTMLElement.prototype.animate.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的兼容性问题*/ /*处理lib.nature等从array改为map的兼容性问题*/
const mapHasFunc = function (item) { const mapHasFunc = function (item) {
console.warn(this, '已经从array改为map请改为使用has方法'); console.trace(this, '已经从array改为map请改为使用has方法');
return this.has(item); return this.has(item);
} }
Object.defineProperty(Map.prototype, "contains", { Object.defineProperty(Map.prototype, "contains", {
@ -271,7 +271,7 @@ Object.defineProperty(Map.prototype, "includes", {
value: mapHasFunc value: mapHasFunc
}); });
const mapAddFunc = function (item) { const mapAddFunc = function (item) {
console.warn(this, '已经从array改为map请改为使用set方法'); console.trace(this, '已经从array改为map请改为使用set方法');
this.set(item, 0); this.set(item, 0);
return this; return this;
} }
@ -303,7 +303,7 @@ Object.defineProperty(Map.prototype, "remove", {
enumerable: false, enumerable: false,
writable: true, writable: true,
value: function (item) { value: function (item) {
console.warn(this, '已经从array改为map请改为使用delete方法'); console.trace(this, '已经从array改为map请改为使用delete方法');
this.delete(item); this.delete(item);
return this; return this;
} }

View File

@ -654,7 +654,14 @@ export class Player extends HTMLDivElement {
* @param { (card: Card) => boolean } [filter] * @param { (card: Card) => boolean } [filter]
*/ */
getKnownCards(other = _status.event.player, filter = card => true) { 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 this.getCards('h', card => {
return card.isKnownBy(other) && filter(card); return card.isKnownBy(other) && filter(card);
}); });
@ -664,6 +671,10 @@ export class Player extends HTMLDivElement {
* @param { Player } [other] * @param { Player } [other]
*/ */
isAllCardsKnown(other = _status.event.player) { 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; if (!other) other = this;
return this.countCards('h', card => { return this.countCards('h', card => {
return !card.isKnownBy(other); return !card.isKnownBy(other);
@ -675,7 +686,14 @@ export class Player extends HTMLDivElement {
* @param { (card: Card) => boolean } [filter] * @param { (card: Card) => boolean } [filter]
*/ */
hasKnownCards(other = _status.event.player, filter = card => true) { 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 this.countCards('h', card => {
return card.isKnownBy(other) && filter(card); return card.isKnownBy(other) && filter(card);
}) > 0; }) > 0;
@ -808,10 +826,16 @@ export class Player extends HTMLDivElement {
if (cards && !isArray) recast.cards = [cards]; if (cards && !isArray) recast.cards = [cards];
else if (isArray && cards.length) recast.cards = cards; else if (isArray && cards.length) recast.cards = cards;
else _status.event.next.remove(recast); 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.recastingLose = recastingLose;
recast.recastingLosingEvents = []; 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.recastingGain = recastingGain;
recast.recastingGainingEvents = []; recast.recastingGainingEvents = [];
recast.setContent('recast'); recast.setContent('recast');

View File

@ -9669,7 +9669,10 @@ export class Library extends Uninstantable {
* @param { boolean } [strict] * @param { boolean } [strict]
*/ */
cardRecastable: (card, player = get.owner(card), source, 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); const mod = game.checkMod(card, player, source, 'unchanged', 'cardRecastable', player);
if (!mod) return false; if (!mod) return false;
if (strict && mod == 'unchanged') { if (strict && mod == 'unchanged') {

View File

@ -6,9 +6,6 @@ export const userAgent = navigator.userAgent.toLowerCase();
export { Mutex } from './mutex.js'; export { Mutex } from './mutex.js';
export const characterDefaultPicturePath = "image/character/default_silhouette_"; export const characterDefaultPicturePath = "image/character/default_silhouette_";
// 我靠循环引用问题在这?
// export * as config from './config.js'
/** /**
* 不能被new的类 * 不能被new的类
*/ */
@ -19,7 +16,7 @@ export class Uninstantable {
} }
/** /**
* * 暂停x毫秒
* @param { number } ms * @param { number } ms
* @returns { Promise<void> } * @returns { Promise<void> }
*/ */