Skip to content

Commit 4ba2c75

Browse files
authored
Fix-bugs-with-generation (#637)
* Change button to only appear afterwards * disable cookies popup if analytics is disabled * change town to always generate in full * change to _customPantheon property * reword to make it clearer * Add FallbackDeities * Add _customPantheon * remove pregen, add _customPantheon * Add to createTown the missing properties * Make pantheon functions console log what they'r doing * Fix editing * CSS * Fix rollup * remove error * change release
1 parent 8b5ff23 commit 4ba2c75

File tree

18 files changed

+592
-564
lines changed

18 files changed

+592
-564
lines changed

.github/workflows/release.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ jobs:
3030

3131
- name: Copy resources
3232
run: cp -r ./src/Resources ./gh-pages/src/
33+
34+
- name: Copy index.html
35+
run: cp -r ./index.html ./
36+
37+
- name: Copy main
38+
run: cp -r ./main.js ./
39+
40+
- name: Copy main map
41+
run: cp -r ./main.js.map ./
3342

3443
- name: Create TypeDocs
3544
run: yarn typedoc

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## 2.8.9
8+
9+
### Added
10+
- Toast to notify user when they have selected an invalid combination of town terrain + location.
11+
### Changed
12+
- Fixed an issue with editing towns not working. Like, at all.
13+
- Fixed an issue where changing town location and terrain would throw an error.
14+
- Made religion testing a little more robust.
15+
- Wording and CSS on the welcome screen.
16+
- Town now fully generates on start instead of in two passes.
17+
718
## 2.8.8
819

920
### Added

lib/religion/createTownReligion.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
import { Town, TownRolls } from '../town/_common'
3-
import { Deity, DeityRank, PantheonTypes, religion } from './religion'
3+
import { Deity, DeityRank, Pantheon, PantheonTypes, religion } from './religion'
44
import { calcPercentage } from '../src/calcPercentage'
55
// import { weightedRandomFetcher } from '../src/weightedRandomFetcher'
66
import { RaceName } from '@lib'
77
import { random } from '../src/random'
88

9-
export const createTownReligion = (town: Town, pantheon?: PantheonTypes, deity?: string) => {
10-
if (!pantheon) pantheon = 'greek'
11-
town.religion.pantheon = pantheon
12-
const tempWeights = getTownDeityWeightings(town)
9+
export const createTownReligion = (town: Town, pantheon?: Pantheon) => {
10+
if (!pantheon) pantheon = religion.pantheon.greek
11+
town.religion.pantheon = pantheon.name
12+
const tempWeights = getTownDeityWeightings(town, pantheon.gods)
1313
town.religionProbabilities = gradeDeityWeightings(tempWeights)
14-
// if (!deity) deity = getRandomDeity(town)
15-
// town.religion.deity = deity
1614
}
1715

1816
/**
@@ -29,14 +27,16 @@ export const rankProbabilities: Record<DeityRank, number> = {
2927
}
3028

3129
const getDeityWeightFromRace = (town: Town, deity: Deity) => {
30+
console.log(`Getting the weight for ${deity.name}`)
3231
let probability = rankProbabilities[deity.rank] || 10
33-
Object.keys(town._demographicPercentile).forEach(function (key) {
32+
console.log(town)
33+
for (const key of Object.keys(town._demographicPercentile)) {
3434
const race = key as RaceName
3535
if (deity?.probabilityWeightings?.race?.[race]) {
3636
const raceWeight = deity.probabilityWeightings.race[race]
3737
if (raceWeight) probability += calcPercentage(raceWeight, town._demographicPercentile[race])
3838
}
39-
})
39+
}
4040
return probability
4141
}
4242

@@ -46,10 +46,10 @@ export const getUnalteredTownDeityWeightings = (town: Town, deities = getFallbac
4646
const weightings: Record<string, number> = {}
4747

4848
for (const deity of deities) {
49-
if (town.ignoreRace) {
50-
weightings[deity.name] = rankProbabilities[deity.rank]
49+
if (town?.ignoreRace) {
50+
weightings[deity.name] = rankProbabilities[deity.rank] || 7
5151
} else {
52-
weightings[deity.name] = getDeityWeightFromRace(town, deity)
52+
weightings[deity.name] = getDeityWeightFromRace(town, deity) || 7
5353
}
5454

5555
weightings[deity.name] = addIfDefined(deity?.probabilityWeightings?.economicIdeology?.[town.economicIdeology], weightings[deity.name])
@@ -65,7 +65,6 @@ export const getUnalteredTownDeityWeightings = (town: Town, deities = getFallbac
6565
weightings[deity.name])
6666
}
6767
}
68-
console.log(weightings)
6968
return weightings
7069
}
7170

@@ -210,8 +209,12 @@ export const addIfDefined = (arg: number | undefined, target: number) => {
210209
return target + arg
211210
}
212211

212+
export const getFallbackPantheon = (town: Town): Pantheon => {
213+
const pantheonName = town.religion.pantheon
214+
const pantheon = religion.pantheon[pantheonName as PantheonTypes] || town.religion._customPantheon || religion.pantheon.greek
215+
return pantheon
216+
}
217+
213218
export const getFallbackDeities = (town: Town): Deity[] => {
214-
const pantheonName = town.religion.pantheon || 'greek'
215-
const pantheon = religion.pantheon[pantheonName as PantheonTypes]
216-
return pantheon.gods
219+
return getFallbackPantheon(town).gods
217220
}

lib/religion/getPantheon.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,66 @@
11
import { findInArray } from '../../lib/src/findInArray'
22
import { Town } from '../../lib/town/_common'
3-
import { compileWeightToPercentile, getTownDeityWeightings } from './createTownReligion'
3+
import { compileWeightToPercentile, getFallbackPantheon, getTownDeityWeightings } from './createTownReligion'
44
import { Deity, Pantheon, religion } from './religion'
55

66
export const getDeity = (town: Town, deity: string, customPantheon?: Pantheon) => {
7+
console.log(`Getting ${deity}...`)
78
return findInArray(
89
getPantheonDeities(town, customPantheon), 'name', deity)
910
}
1011

1112
export const getPantheon = (town: Town, customPantheon?: Pantheon): Pantheon => {
12-
if (isUsingCustomPantheon(town)) return getCustomPantheon(town, customPantheon)
13+
townHasPantheon(town)
14+
console.log(`Getting pantheon that matched ${town.religion.pantheon}`)
15+
if (isUsingCustomPantheon(town, customPantheon)) {
16+
console.log('Using a custom pantheon!')
17+
return getCustomPantheon(town, customPantheon)
18+
}
1319
return religion.pantheon[town.religion.pantheon]
1420
}
1521

1622
export const getPantheonDeities = (town: Town, customPantheon?: Pantheon): Deity[] => {
23+
console.log('Getting pantheon deities...')
1724
return getPantheon(town, customPantheon).gods
1825
}
1926

2027
export const getPantheonNames = (town: Town, customPantheon?: Pantheon) => {
28+
console.log('Getting pantheon names...')
2129
return Object.keys(getAllPantheons(town, customPantheon))
2230
}
2331

2432
export const getAllPantheons = (town: Town, customPantheon?: Pantheon) => {
33+
console.log('Getting all pantheons...')
2534
const pantheons: Record<string, Pantheon> = Object.assign({}, religion.pantheon)
2635
if (seeIfCustomPantheonExists(town, customPantheon)) pantheons[getCustomPantheon(town, customPantheon).name] = getCustomPantheon(town, customPantheon)
2736
return pantheons
2837
}
2938

3039
/** If the pantheon being used doesn't exist in the data, it's obviously custom. */
31-
export const isUsingCustomPantheon = (town: Town) => {
40+
export const isUsingCustomPantheon = (town: Town, customPantheon = getFallbackPantheon(town)) => {
41+
console.log('Checking to see if you are using a custom pantheon...')
42+
// if (!town.religion.pantheon) return false
43+
if (!town.religion._customPantheon) return false
3244
if (religion.pantheon[town.religion.pantheon]) return false
45+
if (customPantheon?.name === 'greek') return false
46+
console.log('Looks like you are using a custom pantheon!')
47+
if (town.religion.pantheon === customPantheon.name) return true
3348
return true
3449
}
3550

3651
export const seeIfCustomPantheonExists = (town: Town, customPantheon?: Pantheon): boolean => {
52+
console.log('Checking to see if a custom pantheon exists...')
3753
if (customPantheon) return true
38-
if (town.religion.customPantheon) return true
54+
if (town.religion._customPantheon) return true
55+
console.log('Looks like the custom pantheon does not exist!')
3956
return false
4057
}
4158

4259
export const getCustomPantheon = (town: Town, customPantheon?: Pantheon): Pantheon => {
43-
if (town.religion.customPantheon) return town.religion.customPantheon
60+
console.log('Getting the custom pantheon...')
4461
if (customPantheon) return customPantheon
45-
throw new Error('Custom panthon not defined!')
62+
if (town.religion._customPantheon) return town.religion._customPantheon
63+
throw new Error('Custom pantheon not defined!')
4664
}
4765

4866
/** For getting ALL deities, including 0% ones. */
@@ -74,3 +92,12 @@ export const getPantheonPercentages = (town: Town, customPantheon?: Pantheon) =>
7492
.reverse()
7593
)
7694
}
95+
96+
const townHasPantheon = (town: Town) => {
97+
switch (typeof town.religion.pantheon) {
98+
case 'undefined':
99+
town.religion.pantheon = 'greek'
100+
break
101+
case 'string':
102+
}
103+
}

lib/religion/getPredominantReligion.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ interface WorshipMakeup extends PredominantInfo {
1010
}
1111

1212
export const getPredominantReligion = (town: Town, percentages: Record<string, number>): WorshipMakeup => {
13-
console.log('Getting the predominant race...')
14-
13+
console.log('Getting the predominant deity...')
14+
console.log(percentages)
1515
// Pick out the primary & secondary Race name percentages.
16-
const [primary, secondary] = sortArray(percentages).reverse()
16+
const sortedArray = sortArray(percentages).reverse()
17+
console.log(sortedArray)
18+
const [primary, secondary] = sortedArray
1719
const [primaryDeity, percentile] = primary
1820

1921
const [secondaryDeity, secondaryPercentile] = secondary

lib/town/_common.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export type TownRolls =
2828

2929
export interface TownBasics {
3030
name: string
31-
pregen?: boolean
3231
generated: 'biome' | 'full'
3332
type: TownType
3433
_type: TownType
@@ -81,7 +80,7 @@ export interface Town extends TownBasics {
8180
guard: Faction
8281
religionProbabilities: Record<string, number>
8382
religion: {
84-
customPantheon?: Pantheon
83+
_customPantheon?: Pantheon
8584
/** Each item indexes the matching deity in the pantheon */
8685
_modifiers: Record<string, number>
8786
/** Probabilities sans the manual bonuses. */

scripts/rollup.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ const isProduction = env === 'production'
1111

1212
const plugins = [
1313
// avoids issues with the Node-specific variable `process`.
14-
replace({ 'process.env.NODE_ENV': JSON.stringify(env) }),
14+
replace({
15+
'process.env.NODE_ENV': JSON.stringify(env),
16+
'preventAssignment': true
17+
}),
1518
json(),
1619
babel({ extensions: ['.js', '.ts'], babelHelpers: 'bundled' }),
1720
nodeResolve({ browser: true }),

src/Religion/EditPantheon.twee

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
<<run $("body").on("change", ["button", 'input'], function() {
33
$(document).trigger(":liveupdate");
44
});>>
5-
<<lb>><<if State.metadata.get('patreonPass') === $_>><<set _isPatron to true>><<import '$town.religion.customPantheon' 'json' 'Import Custom Pantheon'>><<else>><<set _isPatron to false>><<button "Import (Patreon Only)">><<run setup.openDialog({
5+
<<lb>><<if State.metadata.get('patreonPass') === $_>><<set _isPatron to true>><<import '$town.religion._customPantheon' 'json' 'Import Custom Pantheon'>><<else>><<set _isPatron to false>><<button "Import (Patreon Only)">><<run setup.openDialog({
66
header: 'Patreon Only',
77
passage: 'ImportPatreon',
88
rerender: true
99
})>><</button>><</if>> --
1010
<<listbox "$town.religion.pantheon" autoselect>><<optionsfrom lib.getPantheonNames($town, State.metadata.get('pantheon'))>><</listbox>>
11-
<<if def $town.religion.customPantheon or State.metadata.has('pantheon')>>
12-
<<run State.metadata.set('pantheon', $town.religion.customPantheon)>>
11+
<<if def $town.religion._customPantheon or State.metadata.has('pantheon')>>
12+
<<run State.metadata.set('pantheon', $town.religion._customPantheon)>>
1313
--
1414
<<button "Delete custom pantheon">>
1515
<<if lib.isUsingCustomPantheon($town, State.metadata.get('pantheon'))>>
1616
<<set $town.religion.pantheon to 'greek'>>
1717
<</if>>
18-
<<set $town.religion.customPantheon to {}>><<update>>
18+
<<set $town.religion._customPantheon to {}>><<update>>
1919
<<run State.metadata.delete('pantheon')>>
2020
<</button>>
2121
<</if>> -- <<button "Refresh">><<update>><</button>>

src/Start/CustomStart/BiomeGeneration.twee

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
:: BiomeGeneration [force-one-column nobr nofx]
2-
<<run $("body").on("change", ".races-slider", function() {
3-
$(document).trigger(":liveupdate");
4-
});>>
5-
<<liveblock>>
1+
:: BiomeGeneration [force-one-column nofx]
2+
<span style='display:flex'><<liveblock>>
63
<<link "reroll">>
74
<<set $town.name to setup.createTownName($town)>><<update>>
8-
<</link>>
9-
<label class="auto-update" name="Town name"><<textbox "$town.name" $town.name>></label>
10-
<</liveblock>>
11-
<<button "Refresh">><<update>><<replace "#refresh">><<include "BiomeGenerationRefresh">><</replace>><</button>>
12-
<span id="refresh"><<include "BiomeGenerationRefresh">></span>
5+
<</link>> -- <label class="auto-update" name="Town name"><<textbox "$town.name" $town.name>></label>
6+
<</liveblock>></span>
7+
<hr>
8+
<<include "BiomeGenerationRefresh">>
139
<hr>
1410
<<include "EditSliders">>
1511
<hr>

src/Start/CustomStart/BiomeGenerationRefresh.twee

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
:: BiomeGenerationRefresh [force-one-column nobr nofx]
2-
<details open><summary>Basics</summary><<liveblock>><<include "ListboxOptions">><span class="auto-update">
2+
<<run $('body').on('change', 'select', () => {
3+
let { terrain, location } = State.variables.town;
4+
if (!lib.terrain?.[terrain]?.location?.[location]?.origin) {
5+
State.variables.town.location = Object.keys(lib.terrain[terrain].location).random();
6+
$(document).trigger({
7+
type: ':notify',
8+
message: 'There are no origins for a ' + terrain + ' ' + location + '.',
9+
time: false,
10+
classes: false
11+
});
12+
location = State.variables.town.location;
13+
State.variables.town.origin = Object.keys(lib.terrain[terrain].location[location].origin).random();
14+
}
15+
State.variables.listboxes = {
16+
terrain: Object.keys(lib.terrain),
17+
location: Object.keys(lib.terrain[terrain].location),
18+
vegetation: ['thick', 'lush', 'sparse', 'desolate'],
19+
origin: lib.terrain[terrain].location[location].origin,
20+
primaryCrop: lib.townData.misc.primaryCrop,
21+
primaryExport: lib.townData.misc.primaryExport,
22+
season: Object.keys(lib.terrain.temperate.weather.season),
23+
economicIdeology: lib.economicPairs,
24+
politicalIdeology: lib.politicalIdeologyPairs,
25+
politicalSource: ['absolute monarchy', 'constitutional monarchy', 'republic', 'anarchy']
26+
};
27+
$(document).trigger(':liveupdate');
28+
})>>
29+
<<liveblock>><details open><summary>Basics</summary><<include "ListboxOptions">><span class="auto-update">
330
<<print lib.firstCharacter($town.name)>> is located in the
431
<label name="Terrain" for="listbox-townterrain">
532
<<listbox "$town.terrain" autoselect>>
@@ -56,4 +83,4 @@ Politically, they are a
5683
<<listbox "$town.politicalSource" autoselect>>
5784
<<optionsfrom $listboxes.politicalSource>>
5885
<</listbox>>
59-
</label></span><</liveblock>></details><<done>><<run tippy('[data-tippy-content]')>><</done>>
86+
</label></span></details><<done>><<run tippy('[data-tippy-content]')>><</done>><</liveblock>>

0 commit comments

Comments
 (0)