added resource labels for renderer

This commit is contained in:
Rudis Muiznieks 2021-09-06 08:51:41 -05:00
parent 66168728c3
commit 829404ba53
24 changed files with 73 additions and 19 deletions

View File

@ -2,4 +2,8 @@ class ConsoleLogger implements ILogger {
public msg (text: string): void { public msg (text: string): void {
console.log(text); console.log(text);
} }
public unsafeMsg (text: string): void {
console.error(text);
}
} }

View File

@ -6,9 +6,21 @@ class DebugLogger implements ILogger {
} }
public msg (text: string): void { public msg (text: string): void {
const p = document.createElement('p'); this._doMsg(text, true);
p.innerText = text; }
this._container.appendChild(p);
public unsafeMsg (text: string): void {
this._doMsg(text, false);
}
private _doMsg (text: string, safe: boolean): void {
const el = document.createElement('p');
if (safe) {
el.innerText = text;
} else {
el.innerHTML = text;
}
this._container.appendChild(el);
if (this._container.parentElement !== null) { if (this._container.parentElement !== null) {
this._container.parentElement.scrollTop = this._container.parentElement.scrollTop =
this._container.parentElement.scrollHeight; this._container.parentElement.scrollHeight;

View File

@ -1,3 +1,4 @@
interface ILogger { interface ILogger {
msg: (text: string) => void; msg: (text: string) => void;
unsafeMsg: (text: string) => void;
} }

View File

@ -25,6 +25,17 @@ function startGame (state: GameState, renderer: IRenderer): void {
gameLoop(state, renderer); // start the main loop gameLoop(state, renderer); // start the main loop
} }
function initialRender (state: GameState): void {
if (state.logger === null) return;
state.logger.unsafeMsg(`<strong>Welcome to irreligio.us!</strong>
<br><br>
The game is still in an active state of development and nowhere near its final form. This is a debugging interface that can show all resources even before they're unlocked, and many factors may be sped up significantly to aid in development. There is a chance that playing it now may spoil aspects of the game for you later when it's closer to being finished.
<br><br>
Additionally, the game has not been as is not in any kind of state to be playtested or balanced in any way, and even though it auto-saves and resumes, it's changing so much that save data may become corrupt and force you to clear cookies and localstorage and lose all progress before the game loads again. If you want to actually play a fun incremental game, this isn't really ready yet.
<br><br>
The game's source code on <a href='https://github.com/rudism/irreligious'>Github</a> is likely further along than this. Have fun!<br><br>`);
}
// run with default config at startup // run with default config at startup
((): void => { ((): void => {
const config = new GameConfig(); const config = new GameConfig();
@ -37,6 +48,7 @@ function startGame (state: GameState, renderer: IRenderer): void {
config.cfgPastorRecruitRate = 0.5; config.cfgPastorRecruitRate = 0.5;
const renderer = new DebugRenderer(); const renderer = new DebugRenderer();
renderer.onInitialRender = initialRender;
const state = config.generateState(); const state = config.generateState();
// re-run main loop immediately on user clicks // re-run main loop immediately on user clicks

View File

@ -86,35 +86,35 @@ class GameConfig {
// create world religions // create world religions
state.addResource(ResourceKey.christianity, new Religion( state.addResource(ResourceKey.christianity, new Religion(
'christian', 'christians', 'God, Jesus, Bible, churches.', 'Christianity', 'christian', 'christians', 'God, Jesus, Bible, churches.',
(this.cfgReligion.christianity ?? 0) * this.worldPopulation)); (this.cfgReligion.christianity ?? 0) * this.worldPopulation));
state.addResource(ResourceKey.islam, new Religion( state.addResource(ResourceKey.islam, new Religion(
'muslim', 'muslims', 'God, Muhammad, Quran, mosques.', 'Islam', 'muslim', 'muslims', 'God, Muhammad, Quran, mosques.',
(this.cfgReligion.islam ?? 0) * this.worldPopulation)); (this.cfgReligion.islam ?? 0) * this.worldPopulation));
state.addResource(ResourceKey.hinduism, new Religion( state.addResource(ResourceKey.hinduism, new Religion(
'hindu', 'hindus', 'Dogma-free spiritualism.', 'Hinduism', 'hindu', 'hindus', 'Dogma-free spiritualism.',
(this.cfgReligion.hinduism ?? 0) * this.worldPopulation)); (this.cfgReligion.hinduism ?? 0) * this.worldPopulation));
state.addResource(ResourceKey.buddhism, new Religion( state.addResource(ResourceKey.buddhism, new Religion(
'buddhist', 'buddhists', 'The minimization of suffering.', 'Buddhism', 'buddhist', 'buddhists', 'The minimization of suffering.',
(this.cfgReligion.buddhism ?? 0) * this.worldPopulation)); (this.cfgReligion.buddhism ?? 0) * this.worldPopulation));
state.addResource(ResourceKey.sikhism, new Religion( state.addResource(ResourceKey.sikhism, new Religion(
'sikh', 'sikhs', 'Meditation and ten Gurus', 'Sikhism', 'sikh', 'sikhs', 'Meditation and ten Gurus',
(this.cfgReligion.sikhism ?? 0) * this.worldPopulation)); (this.cfgReligion.sikhism ?? 0) * this.worldPopulation));
state.addResource(ResourceKey.judaism, new Religion( state.addResource(ResourceKey.judaism, new Religion(
'jew', 'jews', 'God, Abraham, Torah, synagogues.', 'Judaism', 'jew', 'jews', 'God, Abraham, Torah, synagogues.',
(this.cfgReligion.judaism ?? 0) * this.worldPopulation)); (this.cfgReligion.judaism ?? 0) * this.worldPopulation));
state.addResource(ResourceKey.other, new Religion( state.addResource(ResourceKey.other, new Religion(
'other', 'others', 'A variety of belief systems.', 'Other', 'person from other faiths', 'people from other faiths', 'A variety of belief systems.',
(this.cfgReligion.other ?? 0) * this.worldPopulation)); (this.cfgReligion.other ?? 0) * this.worldPopulation));
state.addResource(ResourceKey.atheism, new Religion( state.addResource(ResourceKey.atheism, new Religion(
'atheist', 'atheists', 'Atheists and agnostics.', 'Non-Religious', 'atheist', 'atheists', 'Atheists and agnostics.',
(this.cfgReligion.atheism ?? 0) * this.worldPopulation)); (this.cfgReligion.atheism ?? 0) * this.worldPopulation));
// add jobs // add jobs

View File

@ -3,6 +3,7 @@
class BuildingPermit extends Research { class BuildingPermit extends Research {
constructor (config: GameConfig) { constructor (config: GameConfig) {
super( super(
'Building Permit',
'building permit', 'building permit',
'building permits', 'building permits',
'Unlocks several new buildings you can build outside of your compounds.'); 'Unlocks several new buildings you can build outside of your compounds.');

View File

@ -3,6 +3,7 @@
class Church extends Infrastructure { class Church extends Infrastructure {
constructor (config: GameConfig) { constructor (config: GameConfig) {
super( super(
'Churches',
'church', 'church',
'churches', 'churches',
`Preaching grounds for ${formatNumber(config.cfgCapacity.churches?.pastors ?? 0)} pastors.`); `Preaching grounds for ${formatNumber(config.cfgCapacity.churches?.pastors ?? 0)} pastors.`);

View File

@ -3,6 +3,7 @@
class Compound extends Infrastructure { class Compound extends Infrastructure {
constructor (config: GameConfig) { constructor (config: GameConfig) {
super( super(
'Compounds',
'compound', 'compound',
'compounds', 'compounds',
'Provides space for tents, houses, and churches and a place to hide more money.'); 'Provides space for tents, houses, and churches and a place to hide more money.');

View File

@ -3,6 +3,7 @@
class Credibility extends Passive { class Credibility extends Passive {
constructor (config: GameConfig) { constructor (config: GameConfig) {
super( super(
'Credibility',
'credibility', 'credibility',
'credibilities', 'credibilities',
'Affects your ability to recruit and retain followers.'); 'Affects your ability to recruit and retain followers.');

View File

@ -4,7 +4,8 @@ class CryptoCurrency extends Purchasable {
constructor (config: GameConfig) { constructor (config: GameConfig) {
super( super(
'FaithCoin', 'FaithCoin',
'FaithCoins', 'faithcoin',
'faithcoins',
"A crypto coin that can't be spent directly, but provides a steady stream of passive income."); "A crypto coin that can't be spent directly, but provides a steady stream of passive income.");
this.cost.money = config.cfgInitialCost.cryptoCurrency; this.cost.money = config.cfgInitialCost.cryptoCurrency;
this._costMultiplier.money = config.cfgCostMultiplier.cryptoCurrency; this._costMultiplier.money = config.cfgCostMultiplier.cryptoCurrency;

View File

@ -2,6 +2,7 @@
class Follower implements IResource { class Follower implements IResource {
public readonly resourceType = ResourceType.religion; public readonly resourceType = ResourceType.religion;
public readonly label = 'Your Followers';
public readonly singularName = 'follower'; public readonly singularName = 'follower';
public readonly pluralName = 'followers'; public readonly pluralName = 'followers';
public readonly description = 'In you they trust.'; public readonly description = 'In you they trust.';

View File

@ -3,6 +3,7 @@
class House extends Infrastructure { class House extends Infrastructure {
constructor (config: GameConfig) { constructor (config: GameConfig) {
super( super(
'Houses',
'house', 'house',
'houses', 'houses',
`Provides room to house ${formatNumber(config.cfgCapacity.houses?.followers ?? 0)} followers.`); `Provides room to house ${formatNumber(config.cfgCapacity.houses?.followers ?? 0)} followers.`);

View File

@ -2,6 +2,7 @@
interface IResource { interface IResource {
readonly resourceType: ResourceType; readonly resourceType: ResourceType;
readonly label?: string;
readonly singularName: string; readonly singularName: string;
readonly pluralName: string; readonly pluralName: string;
readonly description: string; readonly description: string;

View File

@ -15,7 +15,7 @@ abstract class Job implements IResource {
description: 'Promote one of your followers.', description: 'Promote one of your followers.',
isEnabled: (state: GameState): boolean => isEnabled: (state: GameState): boolean =>
(this.max === undefined || this.value < this.max(state)) (this.max === undefined || this.value < this.max(state))
&& this.value < this._availableJobs(state), && this._availableJobs(state) > 0,
performAction: (state: GameState): void => { performAction: (state: GameState): void => {
this._promoteFollower(state); this._promoteFollower(state);
}, },
@ -34,6 +34,7 @@ abstract class Job implements IResource {
protected _isUnlocked = false; protected _isUnlocked = false;
constructor ( constructor (
public readonly label: string,
public readonly singularName: string, public readonly singularName: string,
public readonly pluralName: string, public readonly pluralName: string,
public readonly description: string public readonly description: string

View File

@ -3,6 +3,7 @@
class Megachurch extends Infrastructure { class Megachurch extends Infrastructure {
constructor (config: GameConfig) { constructor (config: GameConfig) {
super( super(
'Megachurches',
'megachurch', 'megachurch',
'megachurches', 'megachurches',
`Room for ${formatNumber(config.cfgCapacity.megaChurches?.pastors ?? 0)} pastors`); `Room for ${formatNumber(config.cfgCapacity.megaChurches?.pastors ?? 0)} pastors`);

View File

@ -9,8 +9,9 @@ class Money extends Purchasable {
public value: number public value: number
) { ) {
super( super(
'money', 'Money',
'moneys', '${}',
'${}',
'Used to purchase goods and services.', 'Used to purchase goods and services.',
'Collect Tithes', 'Collect Tithes',
'Voluntary contributions from followers.'); 'Voluntary contributions from followers.');

View File

@ -8,6 +8,7 @@ abstract class Passive implements IResource {
public advanceAction?: (time: number, state: GameState) => void = undefined; public advanceAction?: (time: number, state: GameState) => void = undefined;
constructor ( constructor (
public readonly label: string,
public readonly singularName: string, public readonly singularName: string,
public readonly pluralName: string, public readonly pluralName: string,
public readonly description: string public readonly description: string

View File

@ -5,6 +5,7 @@ class Pastor extends Job {
constructor () { constructor () {
super( super(
'Pastors',
'pastor', 'pastor',
'pastors', 'pastors',
'Collect tithings for you and recruit new members from other faiths automatically.'); 'Collect tithings for you and recruit new members from other faiths automatically.');

View File

@ -26,6 +26,7 @@ abstract class Purchasable implements IResource {
protected _isUnlocked = false; protected _isUnlocked = false;
constructor ( constructor (
public readonly label: string,
public readonly singularName: string, public readonly singularName: string,
public readonly pluralName: string, public readonly pluralName: string,
public readonly description: string, public readonly description: string,

View File

@ -5,6 +5,7 @@ class Religion implements IResource {
public readonly valueInWholeNumbers = true; public readonly valueInWholeNumbers = true;
constructor ( constructor (
public readonly label: string,
public readonly singularName: string, public readonly singularName: string,
public readonly pluralName: string, public readonly pluralName: string,
public readonly description: string, public readonly description: string,

View File

@ -5,11 +5,13 @@ abstract class Research extends Purchasable {
public inc = undefined; public inc = undefined;
constructor ( constructor (
public readonly label: string,
public readonly singularName: string, public readonly singularName: string,
public readonly pluralName: string, public readonly pluralName: string,
public readonly description: string public readonly description: string
) { ) {
super( super(
label,
singularName, singularName,
pluralName, pluralName,
description, description,

View File

@ -3,6 +3,7 @@
class Tent extends Infrastructure { class Tent extends Infrastructure {
constructor (config: GameConfig) { constructor (config: GameConfig) {
super( super(
'Tents',
'tent', 'tent',
'tents', 'tents',
`Provides room to house ${formatNumber(config.cfgCapacity.tents?.followers ?? 0)} followers.`); `Provides room to house ${formatNumber(config.cfgCapacity.tents?.followers ?? 0)} followers.`);

View File

@ -1,6 +1,8 @@
/// <reference path="../model/logging/DebugLogger.ts" /> /// <reference path="../logging/DebugLogger.ts" />
class DebugRenderer implements IRenderer { class DebugRenderer implements IRenderer {
public onInitialRender?: (state: GameState) => void;
private _initialized = false; private _initialized = false;
private _handleClick = true; private _handleClick = true;
@ -12,7 +14,6 @@ class DebugRenderer implements IRenderer {
console.error('could not find game container'); console.error('could not find game container');
return; return;
} }
this._initialized = true;
state.onResourceClick.push((): void => { state.onResourceClick.push((): void => {
this._handleClick = true; this._handleClick = true;
}); });
@ -43,7 +44,7 @@ class DebugRenderer implements IRenderer {
// create containers for each resource // create containers for each resource
for (const rkey of rkeys) { for (const rkey of rkeys) {
const resource = state.resource[rkey]; const resource = state.resource[rkey];
if (resource === undefined) continue; if (resource === undefined || resource.label === undefined) continue;
const resContainer = document.getElementById( const resContainer = document.getElementById(
`resource-container-${resource.resourceType}`); `resource-container-${resource.resourceType}`);
if (resContainer === null) continue; if (resContainer === null) continue;
@ -53,7 +54,7 @@ class DebugRenderer implements IRenderer {
let content = ` let content = `
<span class='resource-title' <span class='resource-title'
title='${this._escape(resource.description)}'> title='${this._escape(resource.description)}'>
${this._escape(resource.pluralName)}</span><br> ${this._escape(resource.label)}</span><br>
<span class='resource-value'></span> <span class='resource-value'></span>
<span class='resource-max'></span> <span class='resource-max'></span>
<span class='resource-inc'></span> <span class='resource-inc'></span>
@ -142,6 +143,11 @@ class DebugRenderer implements IRenderer {
} }
} }
this._handleClick = false; this._handleClick = false;
if (!this._initialized && this.onInitialRender !== undefined) {
this.onInitialRender(state);
}
this._initialized = true;
} }
private _escape (text: string): string { private _escape (text: string): string {

View File

@ -1,3 +1,4 @@
interface IRenderer { interface IRenderer {
render: (state: GameState) => void; render: (state: GameState) => void;
onInitialRender?: (state: GameState) => void;
} }