Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tool: agf2autoash, agf2glvar - generate scripts out of Game.agf #1264

Merged

Conversation

ivan-mogilko
Copy link
Contributor

@ivan-mogilko ivan-mogilko commented Apr 25, 2021

Resolves #1146 .

agf2autoash - stands for "AGF to Autogenerated ASH" - parses Game.agf (xml) and generates main game header with all the entities and arrays declarations.

Input: game project (*.agf).
Output: generated script header with game declarations.

Usage: agf2autoash Game.agf _AutoGenerated.ash

agf2glvar - parses Game.agf and generates ash/asc with user's global variables declarations and initialization.

Input: game project (*.agf).
Output: generated script header and body.

Usage: : agf2glvar Game.agf _GlobalVariables.ash _GlobalVariables.asc

XML parsing is done by a tinyxml2 library - a C++ library consisting of 1 header and 1 cpp file. I placed it inside the repository in this PR, but guess it may be done as a submodule too, since it's present on github (idk if worth the hassle, and we have other lib sources there already).
NOTE: tinyxml2's readme sais it works exclusively with utf-8; Editor still saves user text in ANSI encoding in game.agf. This may not be a problem if the library reads the element values as-is not trying to convert it to something, but it's best to double check this.

AGF reading is done by a small library of "parser classes" which are currently barebones, as this tool required mostly entity script names. Their composition is not final, and likely change when more sophisticated tools are made (e.g. #1188).

Builds on Windows and Linux. For MSVS it uses "Tools" solution. For Linux there are separate Makefiles per tool.

@ivan-mogilko ivan-mogilko added pull: under review ags3 related to ags3 (version with full backward compatibility) labels Apr 25, 2021
@ivan-mogilko ivan-mogilko force-pushed the ags3tools--agf2autoash branch 5 times, most recently from b212bdc to a3d11b3 Compare April 25, 2021 21:12
@ivan-mogilko ivan-mogilko changed the title Tool: agf2autoash - generates Autogenerated.ash from Game.agf Tool: agf2autoash, agf2glvar - generate scripts out of Game.agf Apr 25, 2021
@ivan-mogilko
Copy link
Contributor Author

Added separate agf2glvar tool which generates global variables from same project file (Game.agf).
(Updated description in the first comment)

@rofl0r
Copy link
Contributor

rofl0r commented Apr 25, 2021

i'd be interested to see output of the latter tool, especially contents of .asc file

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Apr 25, 2021

i'd be interested to see output of the latter tool, especially contents of .asc file

Here's an artificial example:

test--ashgen.zip

Contains:

  • Game.agf,
  • autogen.ash - game object declarations - created by agf2ash,
  • glvar.ash/asc pair - global variables - created by agf2glvar.

To clarify, these "global variables" are created in a separate dialog inside the editor, this is done purely for convenience of beginner users who may have trouble with properly declaring and importing/exporting them. But in the end these variables are of course just same kind of variables, only declared in automatically generated script.

asc contains "function game_start" for initializing String variables, because these are dynamic objects and cannot be assigned on the declaration.

@rofl0r
Copy link
Contributor

rofl0r commented Apr 25, 2021

Here's an artificial example:

thanks. interesting, i wasn't aware of special game_start func. oddly enough, your game last n'furious contains a different version of it in gamescript5,8,14-18.s and globalscript.s (as disassembled by agsutils).

btw autogen.ash contains this which looks like a bug #define {STATUSLINE} FindGUIID("{STATUSLINE}")

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Apr 26, 2021

There are several special callbacks with hardcoded names, they are allowed to be present in each script module and are called in an order:
https://github.com/adventuregamestudio/ags-manual/wiki/Globalfunctions_Event

btw autogen.ash contains this which looks like a bug #define {STATUSLINE} FindGUIID("{STATUSLINE}")

True, this carried over from C# formatting which uses {x} for placeholders, I fixed it in the latest commit.

@ivan-mogilko ivan-mogilko force-pushed the ags3tools--agf2autoash branch from 4f7e472 to 6964668 Compare May 5, 2021 22:27
agf2autoash - stands for "AGF to Autogenerated ASH" - parses the game project file (*.agf), which basically is XML, and generates a script header (*.ash) containing game's script declarations necessary for compiling all the scripts.

Input: game project (*.agf).
Output: generated script header with game declarations.

Usage: `agf2autoash Game.agf _AutoGenerated.ash`
@ivan-mogilko ivan-mogilko force-pushed the ags3tools--agf2autoash branch from 6964668 to 820fd4e Compare May 5, 2021 23:03
@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented May 5, 2021

Made an update to this.

Restructured code, now there's a clear separation between reading from xml to temporary data structs and generating scripts. Script generation is done using structs instead of continuously reading xml document. I think this makes these functions more flexible.

Fixed missing Views in auto header.

agf2glvar - parses the game project file (*.agf), and generates a script header (*.ash) and body (*.asc) containing project's global variable declarations and initialization.

Input: game project (*.agf).
Output: generated header and body.

Usage: `agf2glvar Game.agf _GlobalVariables.ash _GlobalVariables.asc`
@ivan-mogilko ivan-mogilko force-pushed the ags3tools--agf2autoash branch 2 times, most recently from 5cd3d15 to 28edb98 Compare May 6, 2021 14:08
+ corrected String::Replace(char, char) to not clone the string unless there's an actual change
+ in String::ReplaceMid() don't call memmove without actual need
@ivan-mogilko ivan-mogilko force-pushed the ags3tools--agf2autoash branch from 28edb98 to bfb2d22 Compare May 6, 2021 14:17
@ivan-mogilko ivan-mogilko merged commit 9cf25a6 into adventuregamestudio:master May 6, 2021
@ivan-mogilko ivan-mogilko deleted the ags3tools--agf2autoash branch May 6, 2021 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ags3 related to ags3 (version with full backward compatibility) context: game building related to compiling the game from input assets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tool: Generate script files from Game.agf
2 participants