Commit Graph

27 Commits

Author SHA1 Message Date
urkerab
cd7aa49a16
Deep freeze an object's values directly (#10022) 2023-12-28 07:10:32 -08:00
Guangcong Luo
9cd64cba15 Freeze cached Sim objects
We're hunting ~~wabbits~~ validator bugs.

Honestly, this has been a long time coming, but Object.freeze perf
used to not be good enough for us to use it here. Here's hoping!
2023-12-07 01:26:51 -05:00
Mia
effb8ed103 Utils: Explicitly traverse the module tree to ensure no references are held long-term 2023-11-20 22:19:49 -06:00
Annika
9c5d654b89
Revert "Improved typing for utils.ts, and for iterating over base stats (#8919)" (#8938)
This reverts commit c589fb5a5a.
2022-10-16 18:27:25 -07:00
GregLyons
c589fb5a5a
Improved typing for utils.ts, and for iterating over base stats (#8919) 2022-10-16 18:08:11 -07:00
PartMan
161b48daff
Scavengers: Add Speedrun Twist (#8852) 2022-08-06 17:48:46 -07:00
Mia
7811795344
Handle new TypeScript version (#8449)
Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
2021-08-30 20:11:44 -07:00
Annika
33ad1a0a50 Move Modlog.formatArray to Utils 2021-08-12 16:38:14 -07:00
Annika
6ed55b6d1f
IPTools: Add sanity checks (#8331) 2021-07-09 19:59:45 -07:00
Guangcong Luo
4e213368dc Redesign Rock Paper Scissors
This new update will have it looking a lot nicer, and also fixes some
architectural issues with the old design.
2021-05-13 09:39:51 -04:00
Guangcong Luo
574bb28bbe
Implement Utils.Multiset (#8260)
If you grep the codebase for `|| 0) + 1` you get a lot of results,
all of which would be better implemented with a multiset.
2021-05-04 21:53:23 -07:00
Guangcong Luo
04243bc731 Fix crash in Utils.sortBy 2021-04-26 14:57:35 -04:00
Guangcong Luo
486f292904
Refactor everything to use Utils.sortBy (#8220)
A few uses of `array.sort()` have been left alone:

- sorting in `data/` because they aren't supposed to import anything

- `set-importer` because I still have no clue what that's for and what
  dependencies it is/isn't allowed to have

- `sort()` with no arguments used as a lexical sort (at which point
  `sortBy` offers no benefits)

All other cases have been replaced with `Utils.sortBy`, which should
be a massive increase in readability.

Sort orders should be much more readable now, without needing to puzzle
through sign issues. The order is always low-to-high, A-to-Z,
true-to-false.
2021-04-23 22:41:00 -07:00
Guangcong Luo
13189fdb02
Update Dex API (#8181)
This is the change that renames:

- `Dex.getMove` -> `Dex.moves.get`
- `Dex.getAbility` -> `Dex.abilities.get`
- `Dex.getItem` -> `Dex.items.get`
- `Dex.getSpecies` -> `Dex.species.get`
- `Dex.getEffect` -> `Dex.conditions.get`
- `Dex.getNature` -> `Dex.natures.get`
- `Dex.getType` -> `Dex.types.get`
- `Dex.getFormat` -> `Dex.formats.get`

In addition, some other APIs have been updated:

- `getByID` methods have also been added to every other table.
- `Dex.moves.all()` now gets an array of all moves
  - Plus equivalent methods for `abilities`, `items`, `species`, `formats`, `natures`, `types`
  - Note: there's no `Dex.conditions.all()`
- new API: `Dex.stats` for naming/iterating stats
- `Dex.getEffectByID` -> `Dex.conditions.getByID`
- `Dex.getType` -> `Dex.types.get`
- `Dex.data.Formats` -> `Dex.data.Rulesets`
- `Dex.formats` -> now an array `Dex.formats.all()`
- `Dex.getRuleTable` -> `Dex.formats.getRuleTable`
- `Dex.validateFormat` -> `Dex.formats.validate`

Team functions have been split off into a new `sim/teams` package:

- `Dex.packTeam` -> `Teams.pack`
- `Dex.fastUnpackTeam` -> `Teams.unpack`
- `Dex.generateTeam` -> `Teams.generate`
- `Dex.stringifyTeam` -> `Teams.export`

`Teams.export` has also been rewritten to better match how it works in client.

This implements #8178
2021-04-08 03:00:37 -07:00
Guangcong Luo
61ea2dd916 Implement Utils.escapeHTMLForceWrap
Combining escapeHTML and forceWrap allows us to use <wbr /> instead
of U+200B, fixing a copy/paste bug.
2021-02-15 06:09:58 -05:00
Mia
76c10841ea
Lib: Add an index file for all exports (#7972) 2021-01-31 18:00:19 -08:00
Mia
184e867761
Hangman: Support saving hangman entries (#7630) 2021-01-28 11:24:46 -08:00
Guangcong Luo
b5c25a84e2 Fix typo 2021-01-06 11:18:56 -08:00
Guangcong Luo
c44af3286d Implement Utils.forceWrap
I wrote a `forceWrap` method to support break-word wrapping in table
cells for scavengers, but apparently code blocks need it too, so I'm
moving it to Utils.

Fixes #7854
2020-12-30 17:41:41 -08:00
Mia
1b1d91df02
Utils: Visualize Maps/Sets in a cleaner fashion (#7830)
* Utils: Visualize Maps/Sets in a cleaner fashion

* OK

* Update lib/utils.ts

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>

* Update lib/utils.ts

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>

* Update lib/utils.ts

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
2020-12-27 12:51:11 -08:00
Mia
f792cfe28e
Move FSPath#waitUntil to Utils (#7805) 2020-12-14 14:15:52 -08:00
Mia
fca97b418c Fix build errors 2020-11-30 13:17:52 -06:00
Guangcong Luo
8d79bf9725 Rename Dex.deepClone to Utils.deepClone
`this.dex.deepClone` still exists as an alias to `Utils.deepClone` for
use in `data/`. I'll need to spend more time figuring out the correct
solution there.
2020-08-21 04:24:34 -07:00
Mia
deeed6c789
Remove sim/ and data/'s globals (#7091) 2020-08-07 06:44:15 -07:00
Guangcong Luo
8eeec74ce0 Use TypeScript tuples for low splitFirst limits 2020-07-02 15:06:53 -04:00
Guangcong Luo
e0f97dcf6b Replace Chat.uncache* with Utils.clearRequireCache
This replaces the old approach with a new "clear everything except a
whitelist" approach, which should overall involve much less code and
lead to fewer bugs of the "the path changed for a module and I forgot
to update the uncache paths" variety.

I considered a lot of other approaches, but they seem to have more
flaws without any advantages in exchange for them. (We moved away
from `uncacheTree` because it only tracks the first require: there's
no way to get a full list of dependents for a module, only its first
dependent.)
2020-06-12 22:02:32 -07:00
Mia
6839a1f4db
Add a library for utility functions (#6817) 2020-06-09 22:06:43 -07:00