Skip to content

Commit

Permalink
Remove sim/global-variables.d.ts
Browse files Browse the repository at this point in the history
The sim no longer uses any global variables, so this can and should be
removed.

`server/global-variables` has also been cleaned up, since I'm working
on this.
  • Loading branch information
Zarel committed Oct 27, 2020
1 parent 6fe378b commit 1776ca4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 58 deletions.
5 changes: 4 additions & 1 deletion config/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,10 @@ export const Formats: FormatList = [
}
const customRules = this.format.customRules || [];
if (!customRules.includes('!obtainableabilities')) customRules.push('!obtainableabilities');
// const TeamValidator: new (format: string | Format) => TeamValidator = this.constructor as TeamValidator;

const TeamValidator: typeof import('../sim/team-validator').TeamValidator =
require('../sim/team-validator').TeamValidator;

const validator = new TeamValidator(dex.getFormat(`${this.format.id}@@@${customRules.join(',')}`));
const moves = set.moves;
set.moves = [ability.id];
Expand Down
2 changes: 1 addition & 1 deletion server/chat-plugins/datasearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import {QueryProcessManager} from '../../lib/process-manager';
import {Utils} from '../../lib/utils';
import {TeamValidator} from '../../sim/team-validator';

interface DexOrGroup {
abilities: {[k: string]: boolean};
Expand Down Expand Up @@ -2423,7 +2424,6 @@ if (!PM.isParentProcess) {
global.Chat = require('../chat').Chat;
global.toID = Dex.toID;
Dex.includeData();
global.TeamValidator = require('../../sim/team-validator').TeamValidator;

// @ts-ignore
require('../../lib/repl').Repl.start('dexsearch', cmd => eval(cmd)); // eslint-disable-line no-eval
Expand Down
12 changes: 5 additions & 7 deletions server/global-variables.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as ChatType from './chat';
import * as RoomsType from './rooms';
import * as RoomlogsType from './roomlogs';
import * as SocketsType from './sockets';
import * as TeamValidatorAsyncType from './team-validator-async';
import * as UsersType from './users';
Expand All @@ -9,13 +8,14 @@ import * as VerifierType from './verifier';
import {ConfigType} from "../server/config-loader";

import {IPTools as IPToolsType} from './ip-tools';
import {LadderStore as LadderStoreType} from './ladders-remote';
import {Ladders as LaddersType} from './ladders';
import {LoginServer as LoginServerType} from './loginserver';
import {Monitor as MonitorType} from './monitor';
import {Punishments as PunishmentsType} from './punishments';
import {Tournaments as TournamentsType} from './tournaments';

import {Dex as DexType} from '../sim/dex';

declare global {
namespace NodeJS {
interface Global {
Expand All @@ -30,7 +30,6 @@ declare global {
Punishments: any;
Rooms: any;
Sockets: any
TeamValidator: any;
TeamValidatorAsync: any;
Tournaments: any;
Users: any;
Expand All @@ -41,18 +40,17 @@ declare global {
}
const Config: ConfigType;
const Chat: typeof ChatType.Chat;
const Dex: typeof DexType;
const IPTools: typeof IPToolsType;
const Ladders: typeof LaddersType;
const LadderStoreT: typeof LadderStoreType;
const LoginServer: typeof LoginServerType;
const Monitor: typeof MonitorType;
const Punishments: typeof PunishmentsType;
const Rooms: typeof RoomsType.Rooms;
const Sockets: typeof SocketsType.Sockets;
const TeamValidatorAsync: typeof TeamValidatorAsyncType;
const Rooms: typeof RoomsType.Rooms;
const Tournaments: typeof TournamentsType;
const Roomlogs: typeof RoomlogsType.Roomlogs;
const Users: typeof UsersType.Users;
const Verifier: typeof VerifierType;
const toID: typeof Dex.toID;
const toID: typeof DexType.toID;
}
6 changes: 3 additions & 3 deletions server/ladders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* @license MIT
*/

const LadderStore: typeof LadderStoreT = (typeof Config === 'object' && Config.remoteladder ?
require('./ladders-remote') :
require('./ladders-local')).LadderStore;
const LadderStore: typeof import('./ladders-remote').LadderStore = (
typeof Config === 'object' && Config.remoteladder ? require('./ladders-remote') : require('./ladders-local')
).LadderStore;

const SECONDS = 1000;
const PERIODIC_MATCH_INTERVAL = 60 * SECONDS;
Expand Down
11 changes: 3 additions & 8 deletions server/team-validator-async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import {crashlogger} from '../lib/crashlogger';
import {TeamValidator} from '../sim/team-validator';

export class TeamValidatorAsync {
format: Format;
Expand Down Expand Up @@ -68,15 +69,9 @@ export const PM = new QueryProcessManager<{
return '1' + packedTeam;
});

import {Repl} from '../lib/repl';
import {TeamValidator} from '../sim/team-validator';
import {Config} from './config-loader';

if (!PM.isParentProcess) {
// This is a child process!
global.Config = Config;

global.TeamValidator = TeamValidator;
global.Config = require('./config-loader');

global.Monitor = {
crashlog(error: Error, source = 'A team validator process', details: AnyObject | null = null) {
Expand All @@ -97,7 +92,7 @@ if (!PM.isParentProcess) {
global.Dex = require('../sim/dex').Dex.includeData();

// eslint-disable-next-line no-eval
Repl.start(`team-validator-${process.pid}`, cmd => eval(cmd));
require('../lib/repl').Repl.start(`team-validator-${process.pid}`, (cmd: string) => eval(cmd));
} else {
PM.spawn(global.Config ? Config.validatorprocesses : 1);
}
38 changes: 0 additions & 38 deletions sim/global-variables.d.ts

This file was deleted.

0 comments on commit 1776ca4

Please sign in to comment.