RigsOfRods / rigs-of-rods

Main development repository for Rigs of Rods soft-body physics simulator
https://www.rigsofrods.org
GNU General Public License v3.0
991 stars 175 forks source link

Script editor #3074

Closed ohlidalp closed 9 months ago

ohlidalp commented 11 months ago

Script writing is powerful but clumsy:

  1. edit in external editor, save to Documents\My Games\Rigs of Rods\scripts
  2. switch to RoR, either type loadscript ... to console or use ScriptMonitor menu to Load/Reload the script
  3. if there's an error, switch to Angelscript.log and figure the error
  4. repeat

To make scripting fun, the dev/test cycle needs to be quick and comfy. So we needed an ingame editor with a "(RE)START" button and error reporting.

Behold the 'script_editor.as' AngelScript editor written in AngelScript:

obrazek

At the moment it's somewhat glitchy but the START/STOP button works perfectly. It relies entirely on ImGui::InputTextMultiline(), errors and syntax highlight is done by overdrawing. The numbers are: line number, line length, comment offset, num errors - most are not useful but look cool, you can disable them in the View menu.

Update: yes, the hyperlink opens the default browser (only tested on Win10). obrazek

Update2: added game.findResourceFileInfo() which lists files in pre-defined resource groups. This allowed me to list up files in user's 'scripts' dir: obrazek

ohlidalp commented 11 months ago

I'm getting ahead of myself... but just a little.

BTW is it weird to run a physics sandbox game just to make and use your own text editor in there? 😅

obrazek

AnotherFoxGuy commented 11 months ago

I just tested this, and one crash that I found is that if you try and load a script from a terrain folder the game crashes

ohlidalp commented 11 months ago

I just realized I'm not nearly done here, so I've converted this to draft.

@AnotherFoxGuy Probably an uncaught exception. I just added an exception-reporting event type, but I need to manually wrap all troublesome funcs. The save/loadStringResource() aren't wrapped yet.

I just added an API giving script info - I need it to make nice exception window, and also to tell which exceptions belong to who - the editor needs to catch all so it can diagnose it's guest script. The thisScript is a new automatic global var.

obrazek

ohlidalp commented 11 months ago

If this isn't cool, IDK what is 😎 obrazek

ohlidalp commented 11 months ago

@AnotherFoxGuy I can't seem to reproduce the crash you mentioned. obrazek

ohlidalp commented 10 months ago

Latest development: :angel:script bindings of OGRE overlay system and a prototype editor script allowing you to add/edit/delete elements and export OGRE's .overlay files.. Also the editor now has tabs and autosave. image