Commit Graph

89 Commits

Author SHA1 Message Date
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
6880808551 add <auto> automatically after a space
turn this feature off if the user hits backspace after the insertion. Turn it back on if the user types auto themselves.
2023-07-02 14:42:07 -05:00
haven1433
c678ec7f7b goto source right-click option for scripts (prototype) 2023-07-01 22:42:55 -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
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
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
fdc891bf0a script editor: don't add pointer formats to sources that have moved 2023-04-24 07:05:39 -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
60e8910578 in case of repoint, track the new code address correctly
useful to prevent the cursor from going crazy during a repoint operation
2023-03-18 21:25:32 -05:00
haven1433
f648df04cf script editor improvements
* when jumping to a script from a map, format the script. This gets us things like text/marts immediately, instead of needing to load, then edit, to see runs that the script points to.
* When editing a script, keep better track of the cursor, so it doesn't jump around when the script address changes or a pointer within the script changes.
2023-03-17 20:50:07 -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
e65644a236 repoint scripts based on previous script size, not computed size from model 2023-03-05 21:39:19 -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
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
1688ad8d5c r10 through r15 are valid thumb variable names 2023-03-01 22:25:49 -06:00
haven1433
303bb131a3 <auto> improvements
* Selecting brock's script should select the _whole_ script
* Get correct number of code sections when scripts point to freespace
* Make sure script concatenation works correctly for `goto` followed by `end` (vanilla games do this a lot)
* multiple if statements / gotos all get compiled into one script, so long as it's all contiginous script data
* make sure `trainerbattle 01` works correctly with labels
* include blank line separators between labels when decompiling scripts
2023-01-24 20:26:46 -06:00
haven1433
5371397475 first part of <auto> support 2022-12-18 10:26:02 -06:00
haven1433
66f3bd9006 syntax highlighting for multiline comments 2022-12-06 21:40:45 -06:00
haven1433
a185ebe207 track cursor when changing text during script compiles
for example, when adding {} to the end of a script, or when changing ?????? to an actual address
2022-12-04 23:04:57 -06:00
haven1433
7d8ae74a00 script bugfixes
add enum types for fanfare / bufferitem
allow script constants to contain underscores
allow autocomplete for constants that are the last argument
allow 'find usages -> scripts' to find usages from macros (and fix crash)
2022-12-04 22:38:04 -06:00
haven1433
380738609b draft of auto-complete for script tool 2022-12-03 19:09:31 -06:00
haven1433
bf1d30fe7d more macros
also clear constant cache when refreshing ViewPort
2022-12-02 23:28:56 -06:00
haven1433
830740ad34 script editor is now colored 2022-12-02 20:44:59 -06:00
haven1433
4e7148a5f6 thumb editor is now colored 2022-12-02 11:35:24 -06:00
haven1433
f4221580c1 allow resizing for code tool content (ctrl+scroll) 2022-11-02 09:00:12 -05:00
haven1433
4317864b64 fix disappearing script section bug 2022-10-04 16:58:45 -05:00
haven1433
ad15f35193 undo should refresh the code tool 2022-09-30 16:10:33 -05:00
Haven1433
ee28bc8a02 initial ai script support 2022-09-12 20:23:40 -05:00
Haven1433
280fae25a6 scripts should remember their length
instead of calculating their length each time, an edited script can be passed its previous length. This lets you have multiple ends within the same script without issue.
2022-08-31 20:30:17 -05:00
Haven1433
b2e776105f Improve script parsing logic
Previously, trying to edit a script with gotos/calls inline would cause trouble, because the destination is likely contained within the same script. But HMA parses the anchor and puts the script in a separate textbox, which is confusing. Worse, it prevents you from making your script longer, because it thinks it would overwrite itself because of the anchor.

Add logic to handle this case.
- If a script is completely contained within the script that's currently under edit, don't give the script its own textbox.
- If the script would overwrite some bytes, but those bytes are a script that (1) is totally contained within the script you're editing, and (2) is only referenced by the script you're editing; then allow the overwrite to occur.
2022-08-30 21:40:13 -05:00
Haven1433
74ac612261 properties for code/text vertical offset tracking 2022-03-05 22:45:22 -06:00
Haven1433
12a6a71523 thumb tool improvements
* Don't clear an anchor to the start of the code we're writing, it may be important. We may later care about keeping pointers that point one byte into the thumb code as well, since the low bit is set to 1 for branch-exchange.
* Have ldr instructions write word aligned values even when starting from a 4N+2 offset.
2021-12-07 19:59:47 -06:00
Benjamin Popp
80c642f24f Add ability to automatically repoint thumb code
* When given 4 instructions, that's enough space to replace it with a load, a branch, and an address.
* If the 4 instructions are such that they don't have any external dependencies (they don't contain a branch or a load), they can be safely moved to a new address.

These two points together mean that we can arbitrarily (and safely) expand almost any function. This should be very useful for both users and prototyping.
2021-09-23 21:57:05 -05:00
Benjamin Popp
d7f081f9b9 Update the script when clicking off and back on
even from an errored state
also verify that an error _does_ show up after typing in an error
2021-08-11 21:19:10 -05:00
Benjamin Popp
9d9a12f988 don't force repoints if editing a script with a NoInfo anchor
sometimes scripts are created at locations that have NoInfo anchors. In this case, do allow repoints, and do interpret the data as a script even though the anchor is wrong.
2021-08-02 17:00:23 -05:00
Benjamin Popp
0a9a61f2ef Keep anchors when editing script text 2021-07-29 16:12:22 -05:00
Benjamin Popp
d8d18b3d8c editing a script needs to clear pointer formats before inserting data
in order for clearing a pointer to clear itself from any anchors that use it, the pointer must still point to that anchor... so we need to clear the data before we change it.
2021-07-24 22:36:19 -05:00
Benjamin Popp
46af7d65de fix script-insertion anchor issue
when writing a new script run, don't pass in the pointer sources for the parent script
2021-07-23 23:23:29 -05:00
Benjamin Popp
7bcef5b874 move orphans into a special folder to make the intent more clear
When editing XSE scripts, it's possible to have a script that used to be called, but now isn't. If we don't track those orphans, they just become dead data.
Put orphans in a subfolder so that the intent is more clear.
2021-07-23 15:55:26 -05:00
Benjamin Popp
0995bb9068 Fixing script parsing bugs
* Don't crash if a line contains nothing but whitespace
* Decode variable-arg commands correctly
* Decode animation scripts as animation scripts
2021-04-28 20:53:13 -05:00
Benjamin Popp
52a89e5657 Allow thumb compiler to make metadata changes.
Replace the existing method with a pair of methods.
One method requires a token, so that it can make metadata changes.
The other returns a set of runs along with its set of compiled bytes, so that pointers can be adjusted.
2021-03-29 14:15:54 -05:00
Benjamin Popp
04d1e92bfc Add Right click option for displaying existing event scripts 2021-01-27 15:51:23 -06:00
Benjamin Popp
c5b56211f4 Thumb compiler improvements
Allow # on numbers during delayed ldr instructions
Expand selection based on increased code length as the user edits the script.
2020-10-10 21:23:27 -05:00
Benjamin Popp
3966d66181 Right-click -> add new XSE script 2020-08-18 21:33:53 -05:00
Benjamin Popp
9932ee3478 Add initial support for animation scripts
Animation scripts can use the same engine as map scripts and battle scripts... except that they include a new type of parameter.

With animation scripts, the last parameter of some lines is allowed to include arbitrarily many arguments. This is represented by putting the last argument in brackets `[]`.
2020-08-10 19:38:56 -05:00