refactor: migrate states generator#1291
Merged
Azgaar merged 3 commits intoJan 30, 2026
Merged
Conversation
✅ Deploy Preview for afmg ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates the states generator from legacy JavaScript to a TypeScript module, wires it into the module bootstrap flow, and tightens type information around pack.states and related data.
Changes:
- Introduces
StatesModuleinsrc/modules/states-generator.tsas a TypeScript port of the oldpublic/modules/states-generator.js, preserving the publicwindow.StatesAPI and internal behavior (generation, expansion, diplomacy, forms, statistics). - Updates
PackedGraphtyping to use the newStateinterface and adds an explicitreligionsarray, improving type safety of the globalpack. - Adjusts
Names.getStateto accept an optionalbaseparameter, hooks the new states module intosrc/modules/index.ts, and removes the old script tag formodules/states-generator.jsfromsrc/index.html.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/types/PackedGraph.ts |
Replaces states: any[] with states: State[] and adds a typed religions array to PackedGraph, aligning the global pack structure with the new TypeScript states module. |
src/modules/states-generator.ts |
New TypeScript implementation of the states generator (creation, expansion, normalization, poles, neighbors, colors, statistics, campaigns, diplomacy, forms, full names) exposing the same window.States API, with small logic cleanups (e.g., using d3 helpers, fixing the valid filter) but still containing an existing bug in war power accumulation noted by a TODO. |
src/modules/names-generator.ts |
Makes the base argument to getState optional and derives it from culture when omitted, which supports the new call sites that only pass a name and culture. |
src/modules/index.ts |
Registers the new states-generator TypeScript module in the shared modules bootstrap so window.States is constructed before legacy JS consumers use it. |
src/index.html |
Removes the now‑redundant <script> tag for modules/states-generator.js, ensuring only the TypeScript module defines window.States. |
public/modules/states-generator.js |
Deletes the legacy JavaScript implementation that has been superseded by the new TypeScript module. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Collaborator
Author
|
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Had to redo the states migration. Here we go now
Type of change
Versioning