Skip to content

Commit

Permalink
Fix-bugs-with-generation (#637)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ryceg authored May 30, 2021
1 parent 8b5ff23 commit 4ba2c75
Show file tree
Hide file tree
Showing 18 changed files with 592 additions and 564 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ jobs:

- name: Copy resources
run: cp -r ./src/Resources ./gh-pages/src/

- name: Copy index.html
run: cp -r ./index.html ./

- name: Copy main
run: cp -r ./main.js ./

- name: Copy main map
run: cp -r ./main.js.map ./

- name: Create TypeDocs
run: yarn typedoc
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.

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

## 2.8.9

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

## 2.8.8

### Added
Expand Down
35 changes: 19 additions & 16 deletions lib/religion/createTownReligion.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { Town, TownRolls } from '../town/_common'
import { Deity, DeityRank, PantheonTypes, religion } from './religion'
import { Deity, DeityRank, Pantheon, PantheonTypes, religion } from './religion'
import { calcPercentage } from '../src/calcPercentage'
// import { weightedRandomFetcher } from '../src/weightedRandomFetcher'
import { RaceName } from '@lib'
import { random } from '../src/random'

export const createTownReligion = (town: Town, pantheon?: PantheonTypes, deity?: string) => {
if (!pantheon) pantheon = 'greek'
town.religion.pantheon = pantheon
const tempWeights = getTownDeityWeightings(town)
export const createTownReligion = (town: Town, pantheon?: Pantheon) => {
if (!pantheon) pantheon = religion.pantheon.greek
town.religion.pantheon = pantheon.name
const tempWeights = getTownDeityWeightings(town, pantheon.gods)
town.religionProbabilities = gradeDeityWeightings(tempWeights)
// if (!deity) deity = getRandomDeity(town)
// town.religion.deity = deity
}

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

const getDeityWeightFromRace = (town: Town, deity: Deity) => {
console.log(`Getting the weight for ${deity.name}`)
let probability = rankProbabilities[deity.rank] || 10
Object.keys(town._demographicPercentile).forEach(function (key) {
console.log(town)
for (const key of Object.keys(town._demographicPercentile)) {
const race = key as RaceName
if (deity?.probabilityWeightings?.race?.[race]) {
const raceWeight = deity.probabilityWeightings.race[race]
if (raceWeight) probability += calcPercentage(raceWeight, town._demographicPercentile[race])
}
})
}
return probability
}

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

for (const deity of deities) {
if (town.ignoreRace) {
weightings[deity.name] = rankProbabilities[deity.rank]
if (town?.ignoreRace) {
weightings[deity.name] = rankProbabilities[deity.rank] || 7
} else {
weightings[deity.name] = getDeityWeightFromRace(town, deity)
weightings[deity.name] = getDeityWeightFromRace(town, deity) || 7
}

weightings[deity.name] = addIfDefined(deity?.probabilityWeightings?.economicIdeology?.[town.economicIdeology], weightings[deity.name])
Expand All @@ -65,7 +65,6 @@ export const getUnalteredTownDeityWeightings = (town: Town, deities = getFallbac
weightings[deity.name])
}
}
console.log(weightings)
return weightings
}

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

export const getFallbackPantheon = (town: Town): Pantheon => {
const pantheonName = town.religion.pantheon
const pantheon = religion.pantheon[pantheonName as PantheonTypes] || town.religion._customPantheon || religion.pantheon.greek
return pantheon
}

export const getFallbackDeities = (town: Town): Deity[] => {
const pantheonName = town.religion.pantheon || 'greek'
const pantheon = religion.pantheon[pantheonName as PantheonTypes]
return pantheon.gods
return getFallbackPantheon(town).gods
}
39 changes: 33 additions & 6 deletions lib/religion/getPantheon.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,66 @@
import { findInArray } from '../../lib/src/findInArray'
import { Town } from '../../lib/town/_common'
import { compileWeightToPercentile, getTownDeityWeightings } from './createTownReligion'
import { compileWeightToPercentile, getFallbackPantheon, getTownDeityWeightings } from './createTownReligion'
import { Deity, Pantheon, religion } from './religion'

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

export const getPantheon = (town: Town, customPantheon?: Pantheon): Pantheon => {
if (isUsingCustomPantheon(town)) return getCustomPantheon(town, customPantheon)
townHasPantheon(town)
console.log(`Getting pantheon that matched ${town.religion.pantheon}`)
if (isUsingCustomPantheon(town, customPantheon)) {
console.log('Using a custom pantheon!')
return getCustomPantheon(town, customPantheon)
}
return religion.pantheon[town.religion.pantheon]
}

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

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

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

/** If the pantheon being used doesn't exist in the data, it's obviously custom. */
export const isUsingCustomPantheon = (town: Town) => {
export const isUsingCustomPantheon = (town: Town, customPantheon = getFallbackPantheon(town)) => {
console.log('Checking to see if you are using a custom pantheon...')
// if (!town.religion.pantheon) return false
if (!town.religion._customPantheon) return false
if (religion.pantheon[town.religion.pantheon]) return false
if (customPantheon?.name === 'greek') return false
console.log('Looks like you are using a custom pantheon!')
if (town.religion.pantheon === customPantheon.name) return true
return true
}

export const seeIfCustomPantheonExists = (town: Town, customPantheon?: Pantheon): boolean => {
console.log('Checking to see if a custom pantheon exists...')
if (customPantheon) return true
if (town.religion.customPantheon) return true
if (town.religion._customPantheon) return true
console.log('Looks like the custom pantheon does not exist!')
return false
}

export const getCustomPantheon = (town: Town, customPantheon?: Pantheon): Pantheon => {
if (town.religion.customPantheon) return town.religion.customPantheon
console.log('Getting the custom pantheon...')
if (customPantheon) return customPantheon
throw new Error('Custom panthon not defined!')
if (town.religion._customPantheon) return town.religion._customPantheon
throw new Error('Custom pantheon not defined!')
}

/** For getting ALL deities, including 0% ones. */
Expand Down Expand Up @@ -74,3 +92,12 @@ export const getPantheonPercentages = (town: Town, customPantheon?: Pantheon) =>
.reverse()
)
}

const townHasPantheon = (town: Town) => {
switch (typeof town.religion.pantheon) {
case 'undefined':
town.religion.pantheon = 'greek'
break
case 'string':
}
}
8 changes: 5 additions & 3 deletions lib/religion/getPredominantReligion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ interface WorshipMakeup extends PredominantInfo {
}

export const getPredominantReligion = (town: Town, percentages: Record<string, number>): WorshipMakeup => {
console.log('Getting the predominant race...')

console.log('Getting the predominant deity...')
console.log(percentages)
// Pick out the primary & secondary Race name percentages.
const [primary, secondary] = sortArray(percentages).reverse()
const sortedArray = sortArray(percentages).reverse()
console.log(sortedArray)
const [primary, secondary] = sortedArray
const [primaryDeity, percentile] = primary

const [secondaryDeity, secondaryPercentile] = secondary
Expand Down
3 changes: 1 addition & 2 deletions lib/town/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export type TownRolls =

export interface TownBasics {
name: string
pregen?: boolean
generated: 'biome' | 'full'
type: TownType
_type: TownType
Expand Down Expand Up @@ -81,7 +80,7 @@ export interface Town extends TownBasics {
guard: Faction
religionProbabilities: Record<string, number>
religion: {
customPantheon?: Pantheon
_customPantheon?: Pantheon
/** Each item indexes the matching deity in the pantheon */
_modifiers: Record<string, number>
/** Probabilities sans the manual bonuses. */
Expand Down
5 changes: 4 additions & 1 deletion scripts/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const isProduction = env === 'production'

const plugins = [
// avoids issues with the Node-specific variable `process`.
replace({ 'process.env.NODE_ENV': JSON.stringify(env) }),
replace({
'process.env.NODE_ENV': JSON.stringify(env),
'preventAssignment': true
}),
json(),
babel({ extensions: ['.js', '.ts'], babelHelpers: 'bundled' }),
nodeResolve({ browser: true }),
Expand Down
8 changes: 4 additions & 4 deletions src/Religion/EditPantheon.twee
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
<<run $("body").on("change", ["button", 'input'], function() {
$(document).trigger(":liveupdate");
});>>
<<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({
<<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({
header: 'Patreon Only',
passage: 'ImportPatreon',
rerender: true
})>><</button>><</if>> --
<<listbox "$town.religion.pantheon" autoselect>><<optionsfrom lib.getPantheonNames($town, State.metadata.get('pantheon'))>><</listbox>>
<<if def $town.religion.customPantheon or State.metadata.has('pantheon')>>
<<run State.metadata.set('pantheon', $town.religion.customPantheon)>>
<<if def $town.religion._customPantheon or State.metadata.has('pantheon')>>
<<run State.metadata.set('pantheon', $town.religion._customPantheon)>>
--
<<button "Delete custom pantheon">>
<<if lib.isUsingCustomPantheon($town, State.metadata.get('pantheon'))>>
<<set $town.religion.pantheon to 'greek'>>
<</if>>
<<set $town.religion.customPantheon to {}>><<update>>
<<set $town.religion._customPantheon to {}>><<update>>
<<run State.metadata.delete('pantheon')>>
<</button>>
<</if>> -- <<button "Refresh">><<update>><</button>>
Expand Down
16 changes: 6 additions & 10 deletions src/Start/CustomStart/BiomeGeneration.twee
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
:: BiomeGeneration [force-one-column nobr nofx]
<<run $("body").on("change", ".races-slider", function() {
$(document).trigger(":liveupdate");
});>>
<<liveblock>>
:: BiomeGeneration [force-one-column nofx]
<span style='display:flex'><<liveblock>>
<<link "reroll">>
<<set $town.name to setup.createTownName($town)>><<update>>
<</link>>
<label class="auto-update" name="Town name"><<textbox "$town.name" $town.name>></label>
<</liveblock>>
<<button "Refresh">><<update>><<replace "#refresh">><<include "BiomeGenerationRefresh">><</replace>><</button>>
<span id="refresh"><<include "BiomeGenerationRefresh">></span>
<</link>> -- <label class="auto-update" name="Town name"><<textbox "$town.name" $town.name>></label>
<</liveblock>></span>
<hr>
<<include "BiomeGenerationRefresh">>
<hr>
<<include "EditSliders">>
<hr>
Expand Down
31 changes: 29 additions & 2 deletions src/Start/CustomStart/BiomeGenerationRefresh.twee
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
:: BiomeGenerationRefresh [force-one-column nobr nofx]
<details open><summary>Basics</summary><<liveblock>><<include "ListboxOptions">><span class="auto-update">
<<run $('body').on('change', 'select', () => {
let { terrain, location } = State.variables.town;
if (!lib.terrain?.[terrain]?.location?.[location]?.origin) {
State.variables.town.location = Object.keys(lib.terrain[terrain].location).random();
$(document).trigger({
type: ':notify',
message: 'There are no origins for a ' + terrain + ' ' + location + '.',
time: false,
classes: false
});
location = State.variables.town.location;
State.variables.town.origin = Object.keys(lib.terrain[terrain].location[location].origin).random();
}
State.variables.listboxes = {
terrain: Object.keys(lib.terrain),
location: Object.keys(lib.terrain[terrain].location),
vegetation: ['thick', 'lush', 'sparse', 'desolate'],
origin: lib.terrain[terrain].location[location].origin,
primaryCrop: lib.townData.misc.primaryCrop,
primaryExport: lib.townData.misc.primaryExport,
season: Object.keys(lib.terrain.temperate.weather.season),
economicIdeology: lib.economicPairs,
politicalIdeology: lib.politicalIdeologyPairs,
politicalSource: ['absolute monarchy', 'constitutional monarchy', 'republic', 'anarchy']
};
$(document).trigger(':liveupdate');
})>>
<<liveblock>><details open><summary>Basics</summary><<include "ListboxOptions">><span class="auto-update">
<<print lib.firstCharacter($town.name)>> is located in the
<label name="Terrain" for="listbox-townterrain">
<<listbox "$town.terrain" autoselect>>
Expand Down Expand Up @@ -56,4 +83,4 @@ Politically, they are a
<<listbox "$town.politicalSource" autoselect>>
<<optionsfrom $listboxes.politicalSource>>
<</listbox>>
</label></span><</liveblock>></details><<done>><<run tippy('[data-tippy-content]')>><</done>>
</label></span></details><<done>><<run tippy('[data-tippy-content]')>><</done>><</liveblock>>
23 changes: 0 additions & 23 deletions src/Start/CustomStart/listboxRefresh.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
$('body').on('change', '.auto-update select', () => {
const { terrain, location } = State.variables.town
switch (passage()) {
case 'BiomeGeneration':
case 'BiomeGenerationRefresh':
State.variables.listboxes = {
terrain: Object.keys(lib.terrain),
location: Object.keys(lib.terrain[terrain].location),
vegetation: ['thick', 'lush', 'sparse', 'desolate'],
origin: lib.terrain[terrain].location[location].origin,
primaryCrop: lib.townData.misc.primaryCrop,
primaryExport: lib.townData.misc.primaryExport,
season: Object.keys(lib.terrain.temperate.weather.season),
economicIdeology: lib.economicPairs,
politicalIdeology: lib.politicalIdeologyPairs,
politicalSource: ['absolute monarchy', 'constitutional monarchy', 'republic', 'anarchy']
}
break
case 'NPCProfileEdit':
}

$(document).trigger(':liveupdate')
})

$(document).on(':passageend', () => {
lib.addTippyAccessibility()
Expand Down
2 changes: 1 addition & 1 deletion src/Start/Start.twee
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<<run console.log($town)>>
<<if !_isTextOutput>><section id='quick-scenario-generator'><h3 class='hide-on-print'>Quick Scenario Generator</h3><<include "CreateScenario">></section><</if>>
<<include "Popup">><<done>><<run tippy('#detailed-description')>><</done>>
<<if State.metadata.get('cookiePopupWasShown') !== true>>
<<if State.metadata.get('cookiePopupWasShown') !== true && settings.disableAnalytics !== true>>
<<run setup.openDialog({
header: `Cookies`,
passage: 'CookieConsent',
Expand Down
Loading

0 comments on commit 4ba2c75

Please sign in to comment.