removed unnecessary type specifications

This commit is contained in:
Rudis Muiznieks 2021-09-05 15:02:50 -05:00
parent 3e767b396b
commit caf5152551
20 changed files with 77 additions and 75 deletions

View File

@ -15,6 +15,7 @@
"ignoreRegExpLiterals": true}],
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/array-type": ["warn", {"default": "array-simple"}],
"@typescript-eslint/consistent-indexed-object-style": ["warn", "index-signature"],
"@typescript-eslint/consistent-type-assertions": ["warn", {

View File

@ -27,7 +27,7 @@ function startGame (state: GameState, renderer: IRenderer): void {
// run with default config at startup
((): void => {
const config: GameConfig = new GameConfig();
const config = new GameConfig();
// debug values to make the game play faster while testing
config.cfgTitheAmount = 1000;
@ -36,8 +36,8 @@ function startGame (state: GameState, renderer: IRenderer): void {
config.cfgCredibilityRestoreRate = 5;
config.cfgPastorRecruitRate = 0.5;
const renderer: IRenderer = new DebugRenderer();
const state: GameState = config.generateState();
const renderer = new DebugRenderer();
const state = config.generateState();
// re-run main loop immediately on user clicks
state.onResourceClick.push((): void => {

View File

@ -38,7 +38,7 @@ class GameConfig {
public cfgPastorRecruitRate = 0.01;
public generateState (): GameState {
const state: GameState = new GameState(this);
const state = new GameState(this);
// create player organization
state.addResource('plorg', new PlayerOrg());

View File

@ -7,11 +7,11 @@ class GameState {
public now = 0;
private readonly _versionMaj: number = 0;
private readonly _versionMin: number = 1;
private readonly _versionMaj = 0;
private readonly _versionMin = 1;
private _timeSinceSave = 0;
private readonly _timeBetweenSaves: number = 10000;
private readonly _timeBetweenSaves = 10000;
private _resources: { [key: string]: IResource } = { };
private readonly _resourceKeys: string[] = [];

View File

@ -6,7 +6,7 @@ class DebugLogger implements ILogger {
}
public msg (text: string): void {
const p: HTMLElement = document.createElement('p');
const p = document.createElement('p');
p.innerText = text;
this._container.appendChild(p);
if (this._container.parentElement !== null) {

View File

@ -9,7 +9,7 @@ class BuildingPermit extends Research {
public isUnlocked (state: GameState): boolean {
if (this._isUnlocked) return true;
const compounds: IResource = state.getResource('cmpnd');
const compounds = state.getResource('cmpnd');
if (compounds.value > 0) {
this._isUnlocked = true;
}

View File

@ -13,7 +13,7 @@ class Church extends Infrastructure {
public isUnlocked (state: GameState): boolean {
if (this._isUnlocked) return true;
const compounds: IResource = state.getResource('cmpnd');
const compounds = state.getResource('cmpnd');
if (compounds.value > 0) {
this._isUnlocked = true;
}

View File

@ -10,7 +10,7 @@ class Compound extends Infrastructure {
public isUnlocked (state: GameState): boolean {
if (this._isUnlocked) return true;
const tents: IResource = state.getResource('tents');
const tents = state.getResource('tents');
if (tents.value >= 5) {
this._isUnlocked = true;
}

View File

@ -14,7 +14,7 @@ class House extends Infrastructure {
public isUnlocked (state: GameState): boolean {
if (this._isUnlocked) return true;
const compounds: IResource = state.getResource('cmpnd');
const compounds = state.getResource('cmpnd');
if (compounds.value > 0) {
this._isUnlocked = true;
}

View File

@ -1,5 +1,5 @@
/// <reference path="./Purchasable.ts" />
abstract class Infrastructure extends Purchasable {
public readonly resourceType: ResourceType = ResourceType.infrastructure;
public readonly resourceType = ResourceType.infrastructure;
}

View File

@ -1,10 +1,10 @@
/// <reference path="./IResource.ts" />
abstract class Job implements IResource {
public readonly resourceType: ResourceType = ResourceType.job;
public readonly valueInWholeNumbers: boolean = true;
public readonly clickText: string = 'Hire';
public readonly clickDescription: string = 'Promote one of your followers.';
public readonly resourceType = ResourceType.job;
public readonly valueInWholeNumbers = true;
public readonly clickText = 'Hire';
public readonly clickDescription = 'Promote one of your followers.';
public value = 0;
public readonly cost: { [key: string]: number } = { };
@ -49,15 +49,15 @@ abstract class Job implements IResource {
protected _availableJobs (state: GameState): number {
// number of followers minus the number of filled jobs
const followers: number = state.getResource('plorg').value;
const hired: number = state.getResources().reduce(
const followers = state.getResource('plorg').value;
const hired = state.getResources().reduce(
(tot: number, rkey: string): number => {
const res: IResource = state.getResource(rkey);
const res = state.getResource(rkey);
return res.resourceType === ResourceType.job
? tot + res.value
: tot;
}, 0);
let max: number = followers - hired;
let max = followers - hired;
if (max < 0) max = 0;
return max;
}

View File

@ -13,7 +13,7 @@ class MegaChurch extends Infrastructure {
public isUnlocked (state: GameState): boolean {
if (this._isUnlocked) return true;
const permit: IResource = state.getResource('blpmt');
const permit = state.getResource('blpmt');
if (permit.value > 0) {
this._isUnlocked = true;
}

View File

@ -1,7 +1,7 @@
/// <reference path="./Purchasable.ts" />
class Money extends Purchasable {
public readonly resourceType: ResourceType = ResourceType.consumable;
public readonly resourceType = ResourceType.consumable;
private _lastCollectionTime = 0;
@ -16,7 +16,7 @@ class Money extends Purchasable {
}
public max: (state: GameState) => number = (state: GameState) => {
let max: number = state.config.cfgStartingMoneyMax;
let max = state.config.cfgStartingMoneyMax;
max += state.getResource('cmpnd').value * 500000;
return max;
};
@ -32,24 +32,24 @@ class Money extends Purchasable {
};
protected _purchaseAmount (state: GameState): number {
const plorg: IResource = state.getResource('plorg');
const plorg = state.getResource('plorg');
if (plorg.value === 0) {
state.log('You have no followers to collect from!');
return 0;
}
const diff: number = state.now - this._lastCollectionTime;
const diff = state.now - this._lastCollectionTime;
if (diff < state.config.cfgTimeBetweenTithes) {
const lost: number = state.config.cfgTimeBetweenTithes / diff / 3;
const lost = state.config.cfgTimeBetweenTithes / diff / 3;
state.getResource('creds').addValue(lost * -1, state);
}
// each follower gives you $10
const tithings: number = plorg.value * state.config.cfgTitheAmount;
const tithings = plorg.value * state.config.cfgTitheAmount;
this._lastCollectionTime = state.now;
return tithings;
}
protected _purchaseLog (amount: number, state: GameState): string {
const followers: number = state.getResource('plorg').value;
const followers = state.getResource('plorg').value;
return `You collected $${state.formatNumber(amount)} from ${state.formatNumber(followers)} followers.`;
}
}

View File

@ -1,18 +1,19 @@
/// <reference path="./IResource.ts" />
abstract class Passive implements IResource {
public readonly resourceType: ResourceType = ResourceType.passive;
public readonly valueInWholeNumbers: boolean = false;
public readonly clickText: null = null;
public readonly clickDescription: null = null;
public readonly resourceType = ResourceType.passive;
public readonly valueInWholeNumbers = false;
public readonly clickText = null;
public readonly clickDescription = null;
public value = 0;
public readonly cost: null = null;
public readonly cost = null;
public readonly clickAction: null = null;
public readonly clickAction = null;
public max: ((state: GameState) => number) | null = null;
public inc: ((state: GameState) => number) | null = null;
public advanceAction: ((time: number, state: GameState) => void) | null = null;
public advanceAction: (
(time: number, state: GameState) => void) | null = null;
constructor (
public readonly name: string,

View File

@ -9,7 +9,7 @@ class Pastor extends Job {
}
public max: (state: GameState) => number = (state) => {
let max: number = state.getResource('chrch').value * 2;
let max = state.getResource('chrch').value * 2;
max += state.getResource('mchch').value * 5;
return max;
};
@ -23,13 +23,13 @@ class Pastor extends Job {
public advanceAction (time: number, state: GameState): void {
this._timeSinceLastTithe += time;
if (this._timeSinceLastTithe >= state.config.cfgTimeBetweenTithes) {
const money: IResource = state.getResource('money');
const plorg: IResource = state.getResource('plorg');
const money = state.getResource('money');
const plorg = state.getResource('plorg');
// each pastor can collect from up to 100 followers
let tithed: number = this.value * 100;
let tithed = this.value * 100;
if (Math.floor(plorg.value) < tithed)
tithed = Math.floor(plorg.value);
let collected: number = tithed * state.config.cfgTitheAmount;
let collected = tithed * state.config.cfgTitheAmount;
if (money.max !== null && collected > money.max(state) - money.value)
collected = money.max(state) - money.value;
if (collected > 0) {

View File

@ -1,14 +1,14 @@
/// <reference path="./IResource.ts" />
class PlayerOrg implements IResource {
public readonly resourceType: ResourceType = ResourceType.religion;
public readonly name: string = 'Player';
public readonly description: string = 'In you they trust.';
public readonly valueInWholeNumbers: boolean = true;
public readonly clickText: string = 'Recruit';
public readonly clickDescription: string = 'Gather new followers.';
public readonly resourceType = ResourceType.religion;
public readonly name = 'Player';
public readonly description = 'In you they trust.';
public readonly valueInWholeNumbers = true;
public readonly clickText = 'Recruit';
public readonly clickDescription = 'Gather new followers.';
public value = 0;
public readonly cost: null = null;
public readonly cost = null;
private _timeSinceLastLost = 0;
private _lastRecruitmentLog = 0;
@ -16,7 +16,7 @@ class PlayerOrg implements IResource {
private _followerDests: { [key: string]: number } = { };
public max (state: GameState): number {
let max: number = state.config.cfgStartingPlayerMax;
let max = state.config.cfgStartingPlayerMax;
max += state.getResource('tents').value * 2;
max += state.getResource('house').value * 10;
return max;
@ -44,9 +44,9 @@ class PlayerOrg implements IResource {
}
// chance to fail increases as credibility decreases
const creds: IResource = state.getResource('creds');
const creds = state.getResource('creds');
if (creds.max !== null) {
const ratio: number = Math.ceil(creds.value) / creds.max(state);
const ratio = Math.ceil(creds.value) / creds.max(state);
if (Math.random() > ratio) {
state.log('Your recruitment efforts failed.');
return;
@ -75,9 +75,9 @@ class PlayerOrg implements IResource {
} else {
// lost followers must return to other faiths
for (let i = 0; i < diff * -1; i++) {
const dest: [string, IResource] = this._getRandomReligion(state);
const dest = this._getRandomReligion(state);
dest[1].addValue(1, state);
const curFollowers: number = this._followerDests[dest[0]];
const curFollowers = this._followerDests[dest[0]];
this._followerDests[dest[0]] = !isNaN(curFollowers)
? curFollowers + 1
: 1;
@ -96,9 +96,9 @@ class PlayerOrg implements IResource {
if (this.value > 0) {
const creds = state.getResource('creds');
if (creds.max !== null) {
const ratio: number = Math.ceil(creds.value) / creds.max(state);
const ratio = Math.ceil(creds.value) / creds.max(state);
if (Math.random() > ratio) {
const lost: number = Math.ceil(this.value / 25 * (1 - ratio));
const lost = Math.ceil(this.value / 25 * (1 - ratio));
this.addValue(lost * -1, state);
}
}
@ -115,7 +115,7 @@ class PlayerOrg implements IResource {
let total = 0;
for (const rkey of Object.keys(this._followerDests)) {
if (msg !== '') msg += ', ';
const religion: IResource = state.getResource(rkey);
const religion = state.getResource(rkey);
msg += `${state.formatNumber(this._followerDests[rkey])} to ${religion.name}`;
total += this._followerDests[rkey];
delete this._followerDests[rkey];
@ -127,7 +127,7 @@ class PlayerOrg implements IResource {
let total = 0;
for (const rkey of Object.keys(this._followerSources)) {
if (msg !== '') msg += ', ';
const religion: IResource = state.getResource(rkey);
const religion = state.getResource(rkey);
msg +=
`${state.formatNumber(this._followerSources[rkey])} from ${religion.name}`;
total += this._followerSources[rkey];
@ -140,9 +140,9 @@ class PlayerOrg implements IResource {
}
private _getRandomReligion (state: GameState): [string, IResource] {
const religs: string[] = ['xtian', 'islam', 'hindu',
const religs = ['xtian', 'islam', 'hindu',
'buddh', 'sikhi', 'judah', 'other', 'agnos'];
const source: string = religs[Math.floor(Math.random() * 8)];
const source = religs[Math.floor(Math.random() * 8)];
return [source, state.getResource(source)];
}
}

View File

@ -23,7 +23,7 @@ abstract class Purchasable implements IResource {
public clickAction (state: GameState): void {
if (this.max !== null && this.value >= this.max(state)) return;
if (state.deductCost(this.cost)) {
const amount: number = this._purchaseAmount(state);
const amount = this._purchaseAmount(state);
if (amount > 0) {
this.value += amount;
state.log(this._purchaseLog(amount, state));
@ -45,15 +45,15 @@ abstract class Purchasable implements IResource {
return this._isUnlocked;
}
public advanceAction (time: number, state: GameState): void {
public advanceAction (_time: number, _state: GameState): void {
return;
}
protected _purchaseAmount (state: GameState): number {
protected _purchaseAmount (_state: GameState): number {
return 1;
}
protected _purchaseLog (amount: number, state: GameState): string {
protected _purchaseLog (amount: number, _state: GameState): string {
return `You purchased ${amount} x ${this.name}.`;
}
}

View File

@ -1,16 +1,16 @@
/// <reference path="./IResource.ts" />
class Religion implements IResource {
public readonly resourceType: ResourceType = ResourceType.religion;
public readonly valueInWholeNumbers: boolean = true;
public readonly clickText: null = null;
public readonly clickDescription: null = null;
public readonly cost: null = null;
public readonly resourceType = ResourceType.religion;
public readonly valueInWholeNumbers = true;
public readonly clickText = null;
public readonly clickDescription = null;
public readonly cost = null;
public readonly max: null = null;
public readonly inc: null = null;
public readonly clickAction: null = null;
public readonly advanceAction: null = null;
public readonly max = null;
public readonly inc = null;
public readonly clickAction = null;
public readonly advanceAction = null;
constructor (
public readonly name: string,

View File

@ -1,7 +1,7 @@
/// <reference path="./Purchasable.ts" />
abstract class Research extends Purchasable {
public readonly resourceType: ResourceType = ResourceType.research;
public readonly resourceType = ResourceType.research;
constructor (
public readonly name: string,
@ -13,5 +13,5 @@ abstract class Research extends Purchasable {
this.clickDescription = 'Complete this research.';
}
public max: (_state: GameState) => number = (_state) => 1;
public max: (state: GameState) => number = (_state) => 1;
}

View File

@ -10,7 +10,7 @@ class Tent extends Infrastructure {
public max: (state: GameState) => number = (state) => {
// ten extra tents per compound
let max: number = state.config.cfgStartingTentMax;
let max = state.config.cfgStartingTentMax;
max += state.getResource('cmpnd').value * 10;
return max;
};