Commit Graph

166 Commits

Author SHA1 Message Date
haven1433
b8aa9ee781 smarter line splitting during scripts 2023-08-13 22:28:56 -05:00
haven1433
d32c0c2e1d count empty lines when adding error squiggles 2023-08-13 11:43:42 -05:00
haven1433
db232c9675 Improve hover help logic 2023-08-02 23:11:00 -05:00
haven1433
b6cfcb3577 hide filler arguments 2023-07-31 23:03:57 -05:00
haven1433
0914efdb62 improve matching algorithm
instead of just preferring to match the lowest possible ID that counts as a partial match, add some extra criteria to make it act closer to how people expect.
* prefer entries where no letters are skipped
* prefer entries where the start of the partial matches the start of the full
2023-07-31 22:35:22 -05:00
haven1433
788d343357 text warnings get orange underline, not red underline (warning, not error) 2023-07-31 20:48:08 -05:00
haven1433
a958748824 script improvements: double-click highlight and tips
double-click on a command should highlight the entire command, even if it's a macro with `.`s.
When selecting a command, show the help tip for it.
2023-07-31 20:40:52 -05:00
haven1433
435a36a535 Add human-readable documentation for scripts 2023-07-14 06:44:03 -05:00
haven1433
c7485c5275 bugfixes from testing
* pressing escape should close the script tip
* fix automatic inclusion of <auto> behavior
* Fix possible crash when looking for closing } when there isn't one
* Only update TextEditor layers if they've changed (performance)
* creating a new event script should include lock/faceplayer/release
* adjust focus when switching tabs (close open tips)
* only try to access list coments if the list isn't null
2023-07-12 21:32:44 -05:00
haven1433
cce2153c2b fix broken macro-arg-order conversion 2023-07-08 22:22:01 -05:00
haven1433
46f57a0a97 add error underlines for scripts 2023-07-08 00:05:34 -05:00
haven1433
daea25bd4e make it possible to add comments to list elements
right now the comments are only shown by the script editor. But they could be added to other things too, like maybe wild pokemon rates?
2023-07-07 08:58:16 -05:00
haven1433
f14b44eb5e decompiled scripts now have sections appearing in address order
instead of labeling sections based on what address calls them, label section based on what order they appear in memory.
2023-07-01 21:40:59 -05:00
haven1433
e095bace1e beef up insert missing closers
make the caret adjust correctly
insert a blank line between {}
move {} to newlines
2023-06-30 08:04:14 -05:00
haven1433
6fc0f568dc Basic implementation for flag/vars show&tell
Currently hidden
2023-06-29 19:31:08 -05:00
haven1433
348e1e5b96 don't combine scripts if an anchor has multiple pointers 2023-06-26 23:08:27 -05:00
haven1433
cc383f59a3 allow decompiled scripts to use anchor names 2023-06-26 22:22:21 -05:00
haven1433
d072b42e57 Track multi-pointer commands correctly when using multiple <auto> 2023-06-21 20:26:21 -05:00
haven1433
97f5bb7589 self-referential scripts should add script formatting 2023-06-19 21:53:24 -05:00
haven1433
f724f70cdb Improve memory allocation
* Avoid using foreach/enumorables in `MacroScriptLine.Matches` since it's called so often.
* Use Span<char> to reduce string allocations in `ArrayRun.ctor` and `ArrayRunEnumSegment.GetOptions`
2023-06-14 22:31:55 -05:00
haven1433
bd35c3deb3 decrease memory footprint
* don't store the delta object used for initial setup
* avoid making lambdas in `ScriptLine.Matches`, which is called very often.
* use use List<int> instead of SortedSpan<int> for building the initial DestinationToSource cache, since we're already guaranteed that they'll be added in order and without duplicates. This greatly reduces the number of int[] arrays created during startup.
* allow `ArrayRunPointerSegment` to cache the table content results from parsing its InnerFormat, so it doesn't have to re-parse each time. This greatly reduces the number of string allocations.
* Use `ThreadSafeDictionary` for `TryGetValueCaseInsensitive` so we don't need to create a new collection of keys each time we call the method. Also add key caching to `ThreadSafeDictionary` so we don't need to make a new collection each time it's requested.
* Make `GetOptions` return a readonly list. We already know it's unique, this means we don't have to make a new collection every time we parse segments.
* limit the number of undo tokens we store (default 100) to save memory
* Use `byte[]` and `Array.Copy` instead of `List<byte>` and `AddRange` to reduce byte array allocations when loading a file.
* Freeze geometries in the `Icons` collection.
* add option for running garbage collection from the developer menu
* use a custom `AutomationPeer` to prevent WPF from holding memory after controls have been closed.
2023-06-14 20:54:36 -05:00
haven1433
8f131f1bfa fix label resolution for data pointers
Only allow adding unresolved labels for script pointers
2023-06-14 00:18:35 -05:00
haven1433
e39ace9b7d script parser improvements
make it possible for a script edit to expand the rom, rather than running out of space.

make a leading `0x` work for commands that expect pointers
2023-06-04 21:39:11 -05:00
haven1433
ed4a6f755c allow script macros to be game-specific 2023-06-04 20:59:47 -05:00
haven1433
2833a28fe9 fix mart data generation bug
when generating data for a new stream and the pointer is to freespace, be aware that we're creating a stream starting from length zero, rather than whatever the model data parses as the length. The parsed length doesn't matter, because we're pointing at freespace.
2023-05-24 22:56:16 -05:00
haven1433
ade3bdedc7 Don't combine code sections if the skip bytes are referenced
* In sky attack, after the two-turn-animation command, the `end` command is pointed to by other pieces of script. Since its address actually matters, don't combine things together into a single script.
* Both CollectScripts and FindLength have script aggregation logic that needs to be limited.
2023-05-24 21:57:22 -05:00
haven1433
292935e152 improve performance
For script performance:
* call data.GetGameCode() less often, using a cached value for the ScriptParser
* use a 4-byte game code instead of string parsing for the game code

For map previews in the table tool performance
* Don't use dispatcher foreground/background thread swapping, it's safe to add the previews to the collection from the background thread.
* Check the exit condition more often

For drawing performance:
* Use Array.Copy when we don't need to worry about Transparency, since it's much faster.
* Make `Darken` faster, we call it a lot
* Reuse DarkenRect utility in HighlightCollision

Other performance changes
* Protototype for ObserableList<T> for a more configurable version of ObservableCollection
2023-05-21 20:34:12 -05:00
haven1433
675b124457 fix script length calculation bug
Situation:
* Script A refers to B and C. B and C occur right after eachother.
* Scirpt B does not refer to script C, so C doesn't get included in the same body.
-> when editing B, B needs to know that its length does not include C. So the script-length-cache that B uses shouldn't know about C, since B doesn't refer to C.
-> Therefore, B can't use the same cache as A.
* track length caches based on the code body start, not based on the entire model. This lets each code body have its own cache.
2023-05-12 08:05:38 -05:00
haven1433
d0f64db1fa update script keywords when address changes
otherwise it's possible to jump directly from a battle script to an event script and have the keywords not update
2023-05-10 07:36:28 -05:00
haven1433
88cff1cc98 improve script usage help text
* filter out matching games [] blocks correctly (including whitespace after the [])
* only show options for this game
2023-05-06 09:44:43 -05:00
haven1433
6892d4f0bc improve handling of script-length calculation
We previously had code that tried to find lengths of sub-scripts from scripts, but only followed pointers forward, not backward, to prevent infinite loops. But it didn't properly handle scripts that _do_ have backwards pointers: it was returning a length of 1 for those, which is wrong.
2023-04-27 23:40:06 -05:00
haven1433
224c9462ec improve <auto> and <section> logic
* don't allow streams to have <section> labels
* update the <auto> algorithm to allow stream pointers to be picked up in the middle of a script. This will get changed if the script is recompiled to put the streams at the end, but it allows longer scripts to be read no matter where the streams were placed.
2023-04-25 08:08:01 -05:00
haven1433
fdc891bf0a script editor: don't add pointer formats to sources that have moved 2023-04-24 07:05:39 -05:00
haven1433
d396300c02 update current/available blockset addresses when repointing blocksets
also fix possible race condition when refreshing border render while drawing the map
also fix condition where writing script data content formats shouldn't write empty runs if the token doesn't allow changes.
2023-03-22 22:10:45 -05:00
haven1433
e666861f1a improve freespace address interactions for scripts
if you use a freespace address, the script should introduce a new blank stream for you to use. This didn't work correctly for marts, now it does.
2023-03-21 20:44:40 -05:00
haven1433
11db60e5d2 use number section headers rather than addresses as section headers
* better for experts because they can more easily parse a handful of section headers compared to random hex addresses
* Better for new users because it helps them learn that they can use whatever names they want for the headers of scripts and for pointers.
2023-03-21 19:59:01 -05:00
haven1433
7c357f00fd don't support <auto> when reading/writing script addresses, only data addresses 2023-03-20 22:09:25 -05:00
haven1433
f21f3c0e0e auto pointers should get syntax highlighting 2023-03-18 21:47:44 -05:00
haven1433
6ef8253e02 fix cursor when resolving ?????? addresses
doing <??????> auto-included a new {} block, which is cool. But that block needs to not be included when calculating the new cursor position, because the cursor position should remain _before_ the new {}, so it's still on the same line in case you're writing `trainerbattle` or something with multiple pointers in the line.
2023-03-18 21:47:00 -05:00
haven1433
2bef8d62f0 write updated run after deserializing 2023-03-17 22:04:30 -05:00
haven1433
d547f88ebc insert end token when writing a movement stream
note that this could be dangerous, since we're writing an end token to an arbitrary address that is still being decided on. A couple things mitigate this problem:
* the user can use <auto> pointers in scripts
* addresses won't be checked/used unless the user has both an open < and a close >.
2023-03-17 15:06:21 -05:00
haven1433
542ac1ca86 auto-include closing } after inserting a { 2023-03-17 14:27:23 -05:00
haven1433
0e518c4c37
Get all tests passing (#122)
* submit failing tests

* Grab failing trainer test from remote branch (#121)

* Updated flash constants

* Fixed flash constant locations

I originally supplied anchor references, not locations of the constants themselves. That's been fixed. Also, I changed the field name for flash.radius, so it's hopefully clearer.

* Fixed some other pointer issues with RAM addresses in script commands

RAM addresses can't be encased in <> nicely. Some commands still needed their RAM-address pointers to have the ::|h formatting instead.

* Fixing some parameter formats in the script reference file.

There were a few other commands that needed RAM-address parameters set to their correct format so that typing "2024284" doesn't auto format to 0xA024284, etc.

* update script reference (again)

* Added a failing test for duplicating trainer data

Bug report in query: https://discord.com/channels/538022037718040588/538022038376415234/1083215729177931877

---------

Co-authored-by: ShinyTillDawn <80070404+ShinyTillDawn@users.noreply.github.com>

* Fix test

ExportTilesetWithPalette2_EditTileset_ImportTilesetWithPalette2_DataMatches
-> fix formatting in LzSpriteRun
-> fix overflow error in SpriteRun
-> fix default palette detection in SpriteTool
-> improve test so it gives better failure info

* fix trainer duplication assert

fix test name / remove unneeded comments
handle Trainer team runs specially
update assertion error message

* Improve pointer error logic

Pointers are allowed to point into the middle of an existing run. Such a pointer is an error, but is not a metadata inconsistency. Update metadata checking for new logic. Update pointer logic to display pointer as an error.

* improve handling of `auto`

allow <auto> to be used if there's a one-byte gap

* improve interruptingSourceRun logic

an interrupting table is not always valid.
It's only valid if the source is at an index that would make it a pointer.

* don't clear bytes, clear anchors

If you have a custom anchor name in the middle of a script and then edit the script, that custom anchor name will be lost. But anything pointing to it will still point to it.

---------

Co-authored-by: ShinyTillDawn <80070404+ShinyTillDawn@users.noreply.github.com>
2023-03-10 21:40:55 -06:00
haven1433
4959d8f8ca don't auto-format script pointers in edge cases
* points to itself? Don't add the format
* points into existing data? Don't add the format
2023-03-07 07:29:37 -06:00
haven1433
ccbdca51f3 support |z suffix for arguments in script reference files 2023-03-05 21:39:41 -06:00
haven1433
10f177154c fix broken tests 2023-03-04 22:00:44 -06:00
haven1433
43542dcf17 don't create orphans while no-edit formatting a script
When scripts get merged together, some inner-scripts no longer appear to be real scripts. These were showing up as orphans when the scripts get formatted, since that causes scripts to get merged. But the pointers are still there, so they're not actually orphans.

Fix the orphan-naming logic so that it won't name things as orphans if they're inner scripts that still have pointers
2023-03-04 21:33:49 -06:00
haven1433
3fdb3a8028 improve caching for improved performance
don't re-calculate the length of scripts if nothing has changed
2023-03-03 22:46:17 -06:00
haven1433
8896946db2 ai script performance updates
ai script children should appear as ai scripts
editing an AI script shouldn't make a bunch of orphans
introduce a light caching system for noticing when scripts don't need to be loaded again.
script edits that don't change any compiled bytes should be capable of skipping the metadata update in situations where the metadata is already correct
2023-03-03 22:10:49 -06:00
haven1433
7e6dc34302 use decorations instead of mart for pokemart2
And fix name to decorationmart
2023-03-02 19:48:30 -06:00