Lint code

This commit is contained in:
2026-08-05 19:01:45 +02:00
parent 082d1b9723
commit aafbdc658e
46 changed files with 357 additions and 357 deletions
+2 -1
View File
@@ -7,7 +7,8 @@
"start": "node pony-town.js --login --admin --game",
"startlocal": "node pony-town.js --login --admin --game --local",
"start-inspect": "node --inspect pony-town.js --login --admin --game --local",
"lint": "tslint -c tslint.json src/ts/**/*.ts",
"lint": "eslint \"src/ts/**/*.ts\"",
"lint-fix": "eslint \"src/ts/**/*.ts\" --fix",
"dev": "gulp dev",
"dev-sprites": "gulp dev --sprites",
"sw-generate": "workbox generateSW workbox-config.js && gulp patchWebWorker",
-1
View File
@@ -13,7 +13,6 @@ if (document.body.getAttribute('data-debug') !== 'true' || localStorage.producti
}
if (typeof module !== 'undefined' && (module as any).hot) {
(module as any).hot.accept();
}
+1 -1
View File
@@ -338,7 +338,7 @@ export class PonyTownGame implements Game {
}
apply = (func: () => void) => {
return this.zone.run(func);
}
};
applyChanges = () => this.zone.run(() => { });
private getScale() {
const defaultScale = pixelRatio() > 1 ? 3 : 2;
+1 -1
View File
@@ -1,4 +1,4 @@
import { isError } from "../common/utils";
import { isError } from '../common/utils';
export interface Game {
fps: number;
+2 -2
View File
@@ -133,12 +133,12 @@ export class GamePadController implements InputController {
}
private gamepadconnected = (e: Event) => {
this.gamepadIndex = (e as GamepadEvent).gamepad.index;
}
};
private gamepaddisconnected = (e: Event) => {
if (this.gamepadIndex === (e as GamepadEvent).gamepad.index) {
this.scanGamepads();
}
}
};
}
function readAxis(manager: InputManager, keyX: Key, keyY: Key, axisX: number, axisY: number, zeroed: boolean): boolean {
+3 -3
View File
@@ -70,7 +70,7 @@ export class KeyboardController implements InputController {
this.stack.push(code);
}
}
}
};
private keyup = (e: KeyboardEvent) => {
let code = fixKeyCode(e.keyCode);
@@ -89,8 +89,8 @@ export class KeyboardController implements InputController {
}
removeItem(this.stack, code);
}
};
private blur = () => {
this.manager.clear();
}
};
}
+7 -7
View File
@@ -49,7 +49,7 @@ export class MouseController implements InputController {
this.manager.setValue(Key.MOUSE_X, Math.floor(e.clientX - rect.left));
this.manager.setValue(Key.MOUSE_Y, Math.floor(e.clientY - rect.top));
}
}
};
private mousedown = (e: MouseEvent) => {
e.preventDefault();
e.stopPropagation();
@@ -61,29 +61,29 @@ export class MouseController implements InputController {
if (button) {
this.manager.setValue(button, 1);
}
}
};
private mouseup = (e: MouseEvent) => {
const button = MOUSE_BUTTONS[e.button];
if (button) {
this.manager.setValue(button, 0);
}
}
};
private mousewheel: any = (e: WheelEvent) => {
this.manager.addValue(Key.MOUSE_WHEEL_X, clamp(e.deltaX, -1, 1));
this.manager.addValue(Key.MOUSE_WHEEL_Y, clamp(e.deltaY, -1, 1));
}
};
private contextmenu = (e: Event) => {
e.preventDefault();
e.stopPropagation();
}
};
private click = (e: Event) => {
e.preventDefault();
e.stopPropagation();
}
};
private blur = () => {
for (const button of MOUSE_BUTTONS) {
this.manager.setValue(button, 0);
}
}
};
}
+4 -4
View File
@@ -152,7 +152,7 @@ export class TouchController implements InputController {
this.touch2Id = touch.identifier;
}
}
}
};
private touchmove = (e: any) => {
e.preventDefault();
e.stopPropagation();
@@ -165,7 +165,7 @@ export class TouchController implements InputController {
this.manager.setValue(Key.MOUSE_Y, this.touchCurrent.y);
this.updateInput();
}
}
};
private touchend = (e: any) => {
e.preventDefault();
e.stopPropagation();
@@ -188,10 +188,10 @@ export class TouchController implements InputController {
this.manager.setValue(Key.TOUCH_SECOND_CLICK, 1);
this.touch2Id = -1;
}
}
};
private blur = () => {
this.reset();
}
};
private getTouchXY(touch: Touch) {
const { left, top } = this.element!.getBoundingClientRect();
+6 -6
View File
@@ -1,9 +1,9 @@
import { noop, once } from "lodash";
import { getUrl } from "./rev";
import { spriteSheets } from "../generated/sprites";
import { createCanvas, loadImage } from "../common/canvasUtils";
import { createFonts } from "../common/fonts";
import { SpriteSheet } from "../common/interfaces";
import { noop, once } from 'lodash';
import { getUrl } from './rev';
import { spriteSheets } from '../generated/sprites';
import { createCanvas, loadImage } from '../common/canvasUtils';
import { createFonts } from '../common/fonts';
import { SpriteSheet } from '../common/interfaces';
export function createSpriteUtils() {
createFonts();
@@ -437,7 +437,7 @@ export class AdminAccountDetails implements OnInit, OnDestroy {
}
highlighCharacter = (char: Character | undefined): boolean => {
return !!char && includes(this.ponyNames, char.name.toLowerCase());
}
};
clearSessions() {
if (this.account) {
this.clearingSessions = true;
@@ -7,7 +7,7 @@ import { transliterate } from 'transliteration';
})
export class TranslitPipe implements PipeTransform {
transform(value: string) {
if (!value || /^[a-z0-9-_.,\[\]!@#$%^&*{}|\/\\ ]+$/i.test(value))
if (!value || /^[a-z0-9-_.,[]!@#$%^&*{}|\/\\ ]+$/i.test(value))
return undefined;
const translit = transliterate(value);
@@ -8,7 +8,7 @@ function icon(value: string | undefined, defaultValue: any): any {
const extensions = {
browser: [
[/(Amigo|YaBrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]
[/(Amigo|YaBrowser)\/([\w.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]
],
};
+2 -2
View File
@@ -27,8 +27,8 @@ export class Help {
ngAfterViewInit() {
this.route.fragment.subscribe(f => {
const element = document.querySelector("#" + f);
const element = document.querySelector('#' + f);
if (element) setTimeout(() => element.scrollIntoView(), 10);
})
});
}
}
+1 -1
View File
@@ -79,7 +79,7 @@ export class AdminModel {
console.error(error);
this.error = error.message;
return undefined;
}
};
private checkError = <T>(promise: Promise<T>) => promise.catch(this.handleError) as Promise<T | undefined>;
private running = true;
private initializedLive = false;
+1 -1
View File
@@ -467,7 +467,7 @@ export class Model {
this.pending = true;
const alert = !!this.accountAlert ? 'y' : '';
const alert = this.accountAlert ? 'y' : '';
return this.post<JoinResponse>('/api/game/join', { version, ponyId, serverId, alert, url: location.href })
.finally(() => this.pending = false);
@@ -102,7 +102,7 @@ export class CharacterPreview implements OnDestroy, OnChanges, AfterViewInit {
this.lastFrame = now;
this.tryDraw();
}
}
};
private tryDraw() {
try {
this.draw();
@@ -248,7 +248,7 @@ export class ChatBox implements AfterViewInit, OnDestroy {
private say(message: string, chatType: ChatType, entityId: number): boolean {
this.game.lastChatMessageType = chatType;
if (message.toLowerCase().startsWith('/shrug')) {
var rawMessage = message.substring(6);
let rawMessage = message.substring(6);
return !!this.game.send(server =>
server.say(entityId, ((rawMessage !== '') ? rawMessage + ' ' : '') + `¯\\_(ツ)_/¯`,
chatType));
@@ -694,17 +694,17 @@ export class ChatLog implements AfterViewInit, OnDestroy, DoCheck {
scrollHandler = () => {
this.scrollingToEnd = true;
this.scroll.nativeElement.scrollTop = 99999;
}
};
clickNameHandler = (message: ChatLogMessage) => {
this.zone.run(() => this.nameClick.emit(message));
}
};
clickLabel = (message: ChatLogMessage) => {
this.zone.run(() => {
if (message.label) {
this.toggleType.emit(message.label);
}
});
}
};
private clearList() {
removeAllNodes(this.linesElement);
}
@@ -772,12 +772,12 @@ export class ChatLog implements AfterViewInit, OnDestroy, DoCheck {
return findEntityFromMessages(id, this.whisper) ||
findEntityFromMessages(id, this.party) ||
findEntityFromMessages(id, this.local);
}
};
private findEntityFromMessagesByName = (name: string): FakeEntity | undefined => {
return findEntityFromMessagesByName(name, this.game.playerId, this.whisper) ||
findEntityFromMessagesByName(name, this.game.playerId, this.party) ||
findEntityFromMessagesByName(name, this.game.playerId, this.local);
}
};
}
function findEntityFromMessages(id: number, messages: ChatLogMessage[]): FakeEntity | undefined {
@@ -199,7 +199,7 @@ export class Dropdown {
} else if (this.autoClose && e.keyCode === 27) { // esc
this.close();
}
}
};
private canvasCloseHandler: any = () => this.close();
}
@@ -54,5 +54,5 @@ export class FocusTrap implements OnInit, OnDestroy {
this.lastActiveElement.focus();
}
}
}
};
}
@@ -30,7 +30,7 @@ export class SignInBox implements OnInit {
.then(data => {
this.mocks = data;
})
.catch(noop)
.catch(noop);
}
async createNew() {
const name = prompt('Account name');
@@ -32,7 +32,7 @@ export class ToolsFrame {
if (this.popoverIsOpen) {
this.togglePopover();
}
}
};
togglePopover() {
const rect = (this.element.nativeElement as HTMLElement).getBoundingClientRect();
this.placement = (rect.left < (window.innerWidth / 2)) ? 'right' : 'left';
@@ -170,5 +170,5 @@ export class ToolsRegions implements OnInit, OnDestroy {
this.player.y += dy * delta * PONY_SPEED_TROT;
this.update();
}
}
};
}
+1 -1
View File
@@ -56,7 +56,7 @@ export class Shader {
const attribs = vertexCode.match(/^attribute [a-zA-Z0-9_]+ ([a-zA-Z0-9_]+)/mg)!;
for (var i = 0; i < attribs.length; ++i) {
for (let i = 0; i < attribs.length; ++i) {
const [, name] = /attribute [a-zA-Z0-9_]+ ([a-zA-Z0-9_]+)/.exec(attribs[i])!;
gl.bindAttribLocation(program, i, name);
}
+1 -1
View File
@@ -116,7 +116,7 @@ export async function getChat(search: string, date: string, caseInsensitive: boo
const options = { maxBuffer: 1 * 1024 * 1024 }; // 1MB
async function fetchChatlog(lines: number) {
const logFile = paths.pathTo('logs', `info.${format(date, 'yyyyMMdd')}.log`)
const logFile = paths.pathTo('logs', `info.${format(date, 'yyyyMMdd')}.log`);
const { stdout } = await execAsync(`grep ${flags}"${query}" "${logFile}" | tail -n ${lines}`, options);
return stdout;
}
@@ -68,5 +68,5 @@ export class CollectableController implements Controller {
this.pick(client, entity);
}
}
}
};
}
+2 -2
View File
@@ -25,8 +25,8 @@ export class PlantController implements Controller {
private interact: Interact = (entity, client) => {
this.world.removeEntity(entity, this.map);
removeItem(this.plants, entity);
this.config.onPick && this.config.onPick(entity, client);
}
this.config?.onPick?.(entity, client);
};
private nextSpawn = 0;
constructor(private world: World, private map: ServerMap, private config: PlantConfig) {
}
+6 -6
View File
@@ -84,19 +84,19 @@ export class StatsTracker {
this.logStat(
url || (req.baseUrl + req.path), typeof result === 'string' ? result.length : JSON.stringify(result).length);
}
}
};
logSwearing = () => {
this.dailySwearing++;
}
};
logSpamming = () => {
this.dailySpamming++;
}
};
logRecvStats = (id: number, name: string, binary: boolean, size: number) => {
this.logSocketStats(this.recvStats, id, name, binary, size);
}
};
logSendStats = (id: number, name: string, binary: boolean, size: number) => {
this.logSocketStats(this.sendStats, id, name, binary, size);
}
};
private logSocketStats(stats: (SocketStats | undefined)[], id: number, name: string, binary: boolean, size: number) {
const entry = stats[id] || (stats[id] = {
id,
@@ -112,7 +112,7 @@ export class StatsTracker {
lastHourSize: new ByteSize(),
});
if (!!binary) {
if (binary) {
entry.countBin++;
} else {
entry.countStr++;