Start modularization.

This commit is contained in:
Tipx-L 2023-12-05 00:14:34 -08:00
parent 909d62982e
commit 611658114f
48 changed files with 519 additions and 18 deletions

View File

@ -2,16 +2,19 @@
"extends": "eslint:recommended", "extends": "eslint:recommended",
"env": { "env": {
"browser": true, "browser": true,
"node": true,
"es6": true, "es6": true,
"node": true,
"serviceworker": true,
"worker": true "worker": true
}, },
"rules": { "rules": {
"no-console": 0, "no-console": 0,
"no-unused-vars": 0, "no-constant-condition": [
"no-undef": 0, "error",
"no-redeclare": 0, {
"require-yield": 0, "checkLoops": false
}
],
"no-irregular-whitespace": [ "no-irregular-whitespace": [
"error", "error",
{ {
@ -19,13 +22,13 @@
"skipTemplates": true "skipTemplates": true
} }
], ],
"no-constant-condition": [ "no-redeclare": 0,
"error", "no-undef": 0,
{ "no-unused-vars": 0,
"checkLoops": false "require-yield": 0
} },
] /* , "parserOptions": {
"comma-dangle": ["error", "only-multiline"], "ecmaVersion": 13,
"complexity": ["error",100] */ "sourceType": "module"
} }
} }

25
.gitignore vendored
View File

@ -1,10 +1,25 @@
!extension/boss
!extension/cardpile
!extension/coin
!extension/wuxing
!node_modules/options
!node_modules/ultron
!node_modules/ws
._*
.DS_Store .DS_Store
.DS_Store? .DS_Store?
._* .idea
.Spotlight-V100 .Spotlight-V100
.Trashes .Trashes
ehthumbs.db
Thumbs.db
localStorage.json
.vscode .vscode
.idea app
app.html
ehthumbs.db
extension
jsconfig.json
localStorage.json
main.js
node_modules
noname.ico
package.json
Thumbs.db

4
noname.js Normal file
View File

@ -0,0 +1,4 @@
export * from "./noname/ai.js";
export * from "./noname/status.js";
export * from "./noname/library.js";
export * from "./noname/get.js";

7
noname/ai.js Normal file
View File

@ -0,0 +1,7 @@
import { Get } from "../noname.js";
import { BasicAI } from "./ai/basic.js";
export const ai = {
basic: BasicAI,
get: Get
};

180
noname/ai/basic.js Normal file
View File

@ -0,0 +1,180 @@
import { status as _status } from "../../noname.js";
export class BasicAI {
static chooseButton(check) {
var event = _status.event;
var i, j, range, buttons, buttons2;
var ok = false, forced = event.forced;
var iwhile = 100;
while (iwhile--) {
range = get.select(event.selectButton);
if (ui.selected.buttons.length >= range[0]) {
ok = true;
}
if (range[1] <= -1) {
j = 0;
for (i = 0; i < ui.selected.buttons.length; i++) {
j += check(ui.selected.buttons[i]);
}
return (j > 0);
}
buttons = get.selectableButtons();
if (buttons.length == 0) {
return ok;
}
buttons2 = buttons.slice(0);
var ix = 0;
var checkix = check(buttons[0], buttons2);
for (i = 1; i < buttons.length; i++) {
var checkixtmp = check(buttons[i], buttons2);
if (checkixtmp > checkix) {
ix = i;
checkix = checkixtmp;
}
}
// buttons.sort(function(a,b){
// return check(b,buttons2)-check(a,buttons2);
// });
if (check(buttons[ix]) <= 0) {
if (!forced || ok) {
return ok;
}
}
buttons[ix].classList.add('selected');
ui.selected.buttons.add(buttons[ix]);
game.check();
if (ui.selected.buttons.length >= range[0]) {
ok = true;
}
if (ui.selected.buttons.length == range[1]) {
return true;
}
}
}
static chooseCard(check) {
var event = _status.event;
if (event.filterCard == undefined) return (check() > 0);
var i, j, range, cards, cards2, skills, check, effect;
var ok = false, forced = event.forced;
var iwhile = 100;
while (iwhile--) {
range = get.select(event.selectCard);
if (ui.selected.cards.length >= range[0]) {
ok = true;
}
if (range[1] <= -1) {
if (ui.selected.cards.length == 0) return true;
j = 0;
for (i = 0; i < ui.selected.cards.length; i++) {
effect = check(ui.selected.cards[i]);
if (effect < 0) j -= Math.sqrt(-effect);
else j += Math.sqrt(effect);
}
return (j > 0);
}
cards = get.selectableCards();
if (!_status.event.player._noSkill) {
cards = cards.concat(get.skills());
}
if (cards.length == 0) {
return ok;
}
cards2 = cards.slice(0);
// cards.sort(function(a,b){
// return (check(b,cards2)-check(a,cards2));
// });
var ix = 0;
var checkix = check(cards[0], cards2);
for (i = 1; i < cards.length; i++) {
var checkixtmp = check(cards[i], cards2);
if (checkixtmp > checkix) {
ix = i;
checkix = checkixtmp;
}
}
if (check(cards[ix]) <= 0) {
if (!forced || ok) {
return ok;
}
}
if (typeof cards[ix] == 'string') {
ui.click.skill(cards[ix]);
var info = get.info(event.skill);
if (info.filterCard) {
check = info.check || get.unuseful2;
return (ai.basic.chooseCard(check));
}
else {
return true;
}
}
else {
cards[ix].classList.add('selected');
ui.selected.cards.add(cards[ix]);
game.check();
if (ui.selected.cards.length >= range[0]) {
ok = true;
}
if (ui.selected.cards.length == range[1]) {
return true;
}
}
}
}
static chooseTarget(check) {
var event = _status.event;
if (event.filterTarget == undefined) return (check() > 0);
var i, j, range, targets, targets2, effect;
var ok = false, forced = event.forced;
var iwhile = 100;
while (iwhile--) {
range = get.select(event.selectTarget);
if (ui.selected.targets.length >= range[0]) {
ok = true;
}
if (range[1] <= -1) {
j = 0;
for (i = 0; i < ui.selected.targets.length; i++) {
effect = check(ui.selected.targets[i]);
if (effect < 0) j -= Math.sqrt(-effect);
else j += Math.sqrt(effect);
}
return (j > 0);
}
else if (range[1] == 0) {
return check() > 0
}
targets = get.selectableTargets();
if (targets.length == 0) {
return range[0] == 0 || ok;
}
targets2 = targets.slice(0);
// targets.sort(function(a,b){
// return check(b)-check(a);
// });
var ix = 0;
var checkix = check(targets[0], targets2);
for (i = 1; i < targets.length; i++) {
var checkixtmp = check(targets[i], targets2);
if (checkixtmp > checkix) {
ix = i;
checkix = checkixtmp;
}
}
if (check(targets[ix]) <= 0) {
if (!forced || ok) {
return ok;
}
}
targets[ix].classList.add('selected');
ui.selected.targets.add(targets[ix]);
game.check();
if (ui.selected.targets.length >= range[0]) {
ok = true;
}
if (ui.selected.targets.length == range[1]) {
return true;
}
}
}
}

17
noname/get.js Normal file
View File

@ -0,0 +1,17 @@
import { Library as lib, status as _status } from "../noname.js";
export class Get {
/**
* @template T
* @overload
* @param {T} key
* @returns {typeof _status.event[T]}
*/
/**
* @overload
* @returns {typeof _status.event}
*/
static event(key) {
return key ? _status.event[key] : _status.event;
}
}

69
noname/library.js Normal file
View File

@ -0,0 +1,69 @@
import { animate } from "./library/animate.js";
import { cardPack } from "./library/card-pack.js";
import { cardType } from "./library/card-type.js";
import { characterFilter } from "./library/character-filter.js";
import { characterIntro } from "./library/character-intro.js";
import { characterPack } from "./library/character-pack.js";
import { characterReplace } from "./library/character-replace.js";
import { characterSort } from "./library/character-sort.js";
import { characterTitle } from "./library/character-title.js";
import { dynamicTranslate } from "./library/dynamic-translate.js";
import { element } from "./library/element.js";
import { emotionList } from "./library/emotion-list.js";
import { extensionPack } from "./library/extension-pack.js";
import { skin } from "./library/skin.js";
import { updateURLs } from "./library/update-urls.js";
const nonameInitialized = localStorage.getItem('noname_inited');
export class Library {
static configprefix = "noname_0.9_";
static versionOL = 27;
static updateURLS = updateURLs;
static updateURL = updateURLs.github;
static mirrorURL = updateURLs.coding;
static hallURL = "47.99.105.222";
static assetURL = typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized;
static userAgent = navigator.userAgent.toLowerCase();
static compatibleEdition = Boolean(typeof nonameInitialized == 'string' && nonameInitialized.match(/\/(?:com\.widget|yuri\.nakamura)\.noname\//));
static changeLog = [];
static updates = [];
static canvasUpdates = [];
static video = [];
static skilllist = [];
static connectBanned = [];
static characterIntro = characterIntro;
static characterTitle = characterTitle;
static characterPack = characterPack;
static characterFilter = characterFilter;
static characterSort = characterSort;
static characterReplace = characterReplace;
static characterGuozhanFilter = ["mode_guozhan"];
static dynamicTranslate = dynamicTranslate;
static cardPack = cardPack;
static skin = skin;
static onresize = [];
static onphase = [];
static onwash = [];
static onover = [];
static ondb = [];
static ondb2 = [];
static chatHistory = [];
static emotionList = emotionList;
static animate = animate;
static onload = [];
static onload2 = [];
static onprepare = [];
static arenaReady = [];
static onfree = [];
static inpile = [];
static inpile_nature = [];
static extensions = [];
static extensionPack = extensionPack;
static cardType = cardType;
static element = element;
constructor() {
throw new TypeError(`${new.target.name} is not a constructor`);
}
}

View File

@ -0,0 +1,7 @@
import { animateCard } from "./animate/card.js";
import { animateSkill } from "./animate/skill.js";
export const animate = {
skill: animateSkill,
card: animateCard
};

3
noname/library/animate/card.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface AnimateCard extends Record<string, Function> { }
export const animateCard: AnimateCard;

View File

@ -0,0 +1 @@
export const animateCard = {};

3
noname/library/animate/skill.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface AnimateSkill extends Record<string, Function> { }
export const animateSkill: AnimateSkill;

View File

@ -0,0 +1 @@
export const animateSkill = {};

3
noname/library/card-pack.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface CardPack extends Record<string, string[]> { }
export const cardPack: CardPack;

View File

@ -0,0 +1 @@
export const cardPack = {};

3
noname/library/card-type.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface CardType extends Record<string, number> { }
export const cardType: CardType;

View File

@ -0,0 +1 @@
export const cardType = {};

3
noname/library/character-filter.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface CharacterFilter extends Record<string, (mode: string) => boolean> { }
export const characterFilter: CharacterFilter;

View File

@ -0,0 +1 @@
export const characterFilter = {};

View File

@ -0,0 +1,4 @@
type CharacterSex = "double" | "female" | "male" | "none" | "unknown" | string & {};
type CharacterGroup = "wei" | "shu" | "wu" | "qun" | "jin";
type CharacterHP = number | `${number}/${number}` | `${number}/${number}/${number}`;
export type CharacterInformation = [CharacterSex, CharacterGroup, CharacterHP, string[], string[]?];

3
noname/library/character-intro.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface CharacterIntro extends Record<string, string> { }
export const characterIntro: CharacterIntro;

View File

@ -0,0 +1 @@
export const characterIntro = {};

5
noname/library/character-pack.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
import { CharacterInformation } from "./character-information";
interface CharacterPack extends Record<string, Record<string, CharacterInformation>> { }
export const characterPack: CharacterPack;

View File

@ -0,0 +1 @@
export const characterPack = {};

3
noname/library/character-replace.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface CharacterReplace extends Record<string, string[]> { }
export const characterReplace: CharacterReplace;

View File

@ -0,0 +1 @@
export const characterReplace = {};

3
noname/library/character-sort.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface CharacterSort extends Record<string, Record<string, string[]>> { }
export const characterSort: CharacterSort;

View File

@ -0,0 +1 @@
export const characterSort = {};

3
noname/library/character-title.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface CharacterTitle extends Record<string, string> { }
export const characterTitle: CharacterTitle;

View File

@ -0,0 +1 @@
export const characterTitle = {};

5
noname/library/dynamic-translate.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
import { Player } from "./element/player";
interface DynamicTranslate extends Record<string, (player: Player) => string> { }
export const dynamicTranslate: DynamicTranslate;

View File

@ -0,0 +1 @@
export const dynamicTranslate = {};

View File

@ -0,0 +1,7 @@
import { GameEvent } from "./element/game-event.js";
import { Player } from "./element/player.js";
export const element = {
Player: Player,
GameEvent: GameEvent
};

View File

@ -0,0 +1,50 @@
import { Get as get } from "../../../noname.js";
export class GameEvent {
/**
* @param {string} [name]
* @param {false} [trigger]
*/
constructor(name, trigger) {
if (typeof name == 'string') {
this.name = name;
const gameEvent = get.event();
if (gameEvent) {
const type = `onNext${name[0].toUpperCase()}${name.slice(1)}`;
if (gameEvent.hasHandler(type)) this.pushHandler(...gameEvent.getHandler(type));
}
game.globalEventHandlers.addHandlerToEvent(this);
}
this.step = 0;
this.finished = false;
/**
* @type {GameEvent[]}
*/
this.next = [];
/**
* @type {GameEvent[]}
*/
this.after = [];
this.custom = {
add: {},
replace: {}
};
this._aiexclude = [];
this._notrigger = [];
this._result = {};
this._set = [];
if (trigger !== false && !game.online) this._triggered = 0;
}
static initialGameEvent() {
return (new this).finish();
}
finish() {
this.finished = true;
return this;
}
}

View File

@ -0,0 +1 @@
export class Player { }

3
noname/library/emotion-list.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface EmotionList extends Record<string, number> { }
export const emotionList: EmotionList;

View File

@ -0,0 +1,10 @@
export const emotionList = {
xiaowu_emotion: 14,
xiaokuo_emotion: 8,
shibing_emotion: 15,
guojia_emotion: 20,
zhenji_emotion: 20,
xiaosha_emotion: 20,
xiaotao_emotion: 20,
xiaojiu_emotion: 20
};

View File

@ -0,0 +1 @@
export const extensionPack = {};

3
noname/library/skin.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface Skin extends Record<string, number> { }
export const skin: Skin;

1
noname/library/skin.js Normal file
View File

@ -0,0 +1 @@
export const skin = {};

3
noname/library/update-urls.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface UpdateURLs extends Record<string, string> { }
export const updateURLs: UpdateURLs;

View File

@ -0,0 +1,4 @@
export const updateURLs = {
coding: "https://gitcode.net/sinat_33405273/noname/-/raw/",
github: "https://raw.githubusercontent.com/libccy/noname"
};

34
noname/status.js Normal file
View File

@ -0,0 +1,34 @@
import { Library as lib } from "../noname.js";
import { aiStatus } from "./status/ai.js";
import { cardTag } from "./status/card-tag.js";
import { postReconnect } from "./status/post-reconnect.js";
export const status = {
paused: false,
paused2: false,
paused3: false,
over: false,
clicked: false,
auto: false,
event: lib.element.GameEvent.initialGameEvent(),
ai: aiStatus,
lastdragchange: [],
skillaudio: [],
dieClose: [],
dragline: [],
dying: [],
/**
* @type {import("./status/global-history.js").GlobalHistory[]}
*/
globalHistory: [{
cardMove: [],
custom: [],
useCard: [],
changeHp: [],
everything: []
}],
cardtag: cardTag,
renku: [],
prehidden_skills: [],
postReconnect: postReconnect
}

7
noname/status/ai.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import { Player } from "../library/element/player";
interface AIStatus extends Record<string, any> {
customAttitude: ((from: Player, to: Player) => number)[];
}
export const aiStatus: AIStatus;

3
noname/status/ai.js Normal file
View File

@ -0,0 +1,3 @@
export const aiStatus = {
customAttitude: []
};

3
noname/status/card-tag.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface CardTag extends Record<string, `${number}`[]> { }
export const cardTag: CardTag;

View File

@ -0,0 +1,7 @@
export const cardTag = {
yingbian_zhuzhan: [],
yingbian_kongchao: [],
yingbian_fujia: [],
yingbian_canqu: [],
yingbian_force: []
};

9
noname/status/global-history.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
import { GameEvent } from "../library/element/game-event";
export interface GlobalHistory {
cardMove: GameEvent[];
custom: any[];
useCard: GameEvent[];
changeHp: GameEvent[];
everything: GameEvent[];
}

View File

@ -0,0 +1 @@
export const postReconnect = {};