feat: slider-input - statesGrowthRate

This commit is contained in:
Azgaar 2024-08-20 01:36:17 +02:00
parent 794537131d
commit bba23c6fc7
2 changed files with 12 additions and 39 deletions

View file

@ -378,9 +378,9 @@ window.BurgsAndStates = (() => {
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p}); const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
const cost = []; const cost = [];
const globalNeutralRate = byId("growthRate").valueAsNumber || 1; const globalGrowthRate = byId("growthRate").valueAsNumber || 1;
const statesNeutralRate = byId("statesNeutral")?.valueAsNumber || 1; const statesGrowthRate = byId("statesGrowthRate")?.valueAsNumber || 1;
const neutral = (cells.i.length / 2) * globalNeutralRate * statesNeutralRate; // limit cost for state growth const growthRate = (cells.i.length / 2) * globalGrowthRate * statesGrowthRate; // limit cost for state growth
// remove state from all cells except of locked // remove state from all cells except of locked
for (const cellId of cells.i) { for (const cellId of cells.i) {
@ -419,7 +419,7 @@ window.BurgsAndStates = (() => {
const cellCost = Math.max(cultureCost + populationCost + biomeCost + heightCost + riverCost + typeCost, 0); const cellCost = Math.max(cultureCost + populationCost + biomeCost + heightCost + riverCost + typeCost, 0);
const totalCost = p + 10 + cellCost / states[s].expansionism; const totalCost = p + 10 + cellCost / states[s].expansionism;
if (totalCost > neutral) return; if (totalCost > growthRate) return;
if (!cost[e] || totalCost < cost[e]) { if (!cost[e] || totalCost < cost[e]) {
if (cells.h[e] >= 20) cells.state[e] = s; // assign state to cell if (cells.h[e] >= 20) cells.state[e] = s; // assign state to cell

View file

@ -55,36 +55,18 @@ function insertEditorHtml() {
<div id="statesRegenerateButtons" style="display: none"> <div id="statesRegenerateButtons" style="display: none">
<button id="statesRegenerateBack" data-tip="Hide the regeneration menu" class="icon-cog-alt"></button> <button id="statesRegenerateBack" data-tip="Hide the regeneration menu" class="icon-cog-alt"></button>
<button id="statesRandomize" data-tip="Randomize states Expansion value and re-calculate states and provinces" class="icon-shuffle"></button> <button id="statesRandomize" data-tip="Randomize states Expansion value and re-calculate states and provinces" class="icon-shuffle"></button>
<span data-tip="Additional growth rate. Defines how many lands will stay neutral"> <div data-tip="Additional growth rate. Defines how many land cells remain neutral" style="display: inline-block">
<label class="italic">Growth rate:</label> <slider-input id="statesGrowthRate" min=".1" max="3" step=".05" value="1">Growth rate:</slider-input>
<input </div>
id="statesNeutral"
type="range"
min=".1"
max="3"
step=".05"
value="1"
style="width: 12em"
/>
<input
id="statesNeutralNumber"
type="number"
min=".1"
max="3"
step=".05"
value="1"
style="width: 4em"
/>
</span>
<button id="statesRecalculate" data-tip="Recalculate states based on current values of growth-related attributes" class="icon-retweet"></button> <button id="statesRecalculate" data-tip="Recalculate states based on current values of growth-related attributes" class="icon-retweet"></button>
<span data-tip="Allow states neutral distance, expansion and type changes to take an immediate effect"> <div data-tip="Allow states neutral distance, expansion and type changes to take an immediate effect" style="display: inline-block">
<input id="statesAutoChange" class="checkbox" type="checkbox" /> <input id="statesAutoChange" class="checkbox" type="checkbox" />
<label for="statesAutoChange" class="checkbox-label"><i>auto-apply changes</i></label> <label for="statesAutoChange" class="checkbox-label"><i>auto-apply changes</i></label>
</span> </div>
<span data-tip="Allow system to change state labels when states data is change"> <div data-tip="Allow system to change state labels when states data is change" style="display: inline-block">
<input id="adjustLabels" class="checkbox" type="checkbox" /> <input id="adjustLabels" class="checkbox" type="checkbox" />
<label for="adjustLabels" class="checkbox-label"><i>auto-change labels</i></label> <label for="adjustLabels" class="checkbox-label"><i>auto-change labels</i></label>
</span> </div>
</div> </div>
<button id="statesManually" data-tip="Manually re-assign states" class="icon-brush"></button> <button id="statesManually" data-tip="Manually re-assign states" class="icon-brush"></button>
@ -118,8 +100,7 @@ function addListeners() {
byId("statesRegenerateBack").on("click", exitRegenerationMenu); byId("statesRegenerateBack").on("click", exitRegenerationMenu);
byId("statesRecalculate").on("click", () => recalculateStates(true)); byId("statesRecalculate").on("click", () => recalculateStates(true));
byId("statesRandomize").on("click", randomizeStatesExpansion); byId("statesRandomize").on("click", randomizeStatesExpansion);
byId("statesNeutral").on("input", changeStatesGrowthRate); byId("statesGrowthRate").on("input", () => recalculateStates(false));
byId("statesNeutralNumber").on("change", changeStatesGrowthRate);
byId("statesManually").on("click", enterStatesManualAssignent); byId("statesManually").on("click", enterStatesManualAssignent);
byId("statesManuallyApply").on("click", applyStatesManualAssignent); byId("statesManuallyApply").on("click", applyStatesManualAssignent);
byId("statesManuallyCancel").on("click", () => exitStatesManualAssignment(false)); byId("statesManuallyCancel").on("click", () => exitStatesManualAssignment(false));
@ -868,14 +849,6 @@ function recalculateStates(must) {
refreshStatesEditor(); refreshStatesEditor();
} }
function changeStatesGrowthRate() {
const growthRate = +this.value;
byId("statesNeutral").value = growthRate;
byId("statesNeutralNumber").value = growthRate;
tip("Growth rate: " + growthRate);
recalculateStates(false);
}
function randomizeStatesExpansion() { function randomizeStatesExpansion() {
pack.states.forEach(s => { pack.states.forEach(s => {
if (!s.i || s.removed) return; if (!s.i || s.removed) return;