Author Topic: MODULE+PLUGIN: Interfacer v0.80 Beta 4 - Scripting your interface, simplified!  (Read 5170 times)

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
Presently it's linking against the Interfacer plugin itself:

Code: C#
  1. using AGS.Plugin.Interfacer;
  2. using System;
  3. using System.IO;
  4.  
  5. namespace InterfacerModulator
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             try
  12.             {
  13.                 string name = InterfacerModule.Name; // InterfacerModule is a new helper class in AGS.Plugin.Interfacer.dll
  14.                 string fileName = Path.GetFullPath(name + ".scm");
  15.                 string author = InterfacerModule.Author;
  16.                 string description = InterfacerModule.Description;
  17.                 string version = InterfacerModule.Version;
  18.                 string scriptText = InterfacerModule.ScriptText;
  19.                 string headerText = InterfacerModule.HeaderText;
  20.                 int uniqueKey = InterfacerModule.UniqueKey;
  21.                 Exporter.ExportScriptModule(fileName, author, description, name, version, scriptText, headerText, uniqueKey);
  22.             }
  23.             catch
  24.             {
  25.             }
  26.         }
  27.     }
  28. }

The Exporter class is based directly on AGSEditor.AGS.Editor.ImportExport:

Code: C#
  1. using System.IO;
  2. using System.Text;
  3.  
  4. namespace InterfacerModulator
  5. {
  6.     internal class Exporter
  7.     {
  8.         private const string MODULE_FILE_SIGNATURE = "AGSScriptModule\0";
  9.         private const uint MODULE_FILE_TRAILER = 0xb4f76a65;
  10.  
  11.         public static void ExportScriptModule(string fileName, string author, string description, string name,
  12.             string version, string scriptText, string headerText, int uniqueKey)
  13.         {
  14.             BinaryWriter writer = new BinaryWriter(new FileStream(fileName, FileMode.Create, FileAccess.Write));
  15.             writer.Write(Encoding.ASCII.GetBytes(MODULE_FILE_SIGNATURE));
  16.             writer.Write((int)1); // version (???)
  17.             WriteNullTerminatedString(author, writer);
  18.             WriteNullTerminatedString(description, writer);
  19.             WriteNullTerminatedString(name, writer);
  20.             WriteNullTerminatedString(version, writer);
  21.             writer.Write((int)scriptText.Length);
  22.             WriteNullTerminatedString(scriptText, writer);
  23.             writer.Write((int)headerText.Length);
  24.             WriteNullTerminatedString(headerText, writer);
  25.             writer.Write((int)uniqueKey);
  26.             writer.Write((int)0); // Permissions
  27.             writer.Write((int)0); // We are owner
  28.             writer.Write((uint)MODULE_FILE_TRAILER);
  29.             writer.Close();
  30.         }
  31.  
  32.         private static void WriteNullTerminatedString(string text, BinaryWriter writer)
  33.         {
  34.             writer.Write(Encoding.Default.GetBytes(text));
  35.             writer.Write((byte)0);
  36.         }
  37.     }
  38. }

The InterfacerModulator builds directly to the AGS.Plugin.Interfacer project folder. Then when the AGS.Plugin.Interfacer is built, there is a post-build event that copies the AGS.Plugin.Interfacer.dll to the project directory, runs InterfacerModulator.exe, then deletes the DLL.

And...just in case you were wondering, InterfacerModule.Author, InterfacerModule.Description, etc. are defined as static readonly so that the exporter will read the values at run-time (as opposed to const where they would only be read at compile-time).

Edit: Just to make things a bit cleaner, I've now got the InterfacerModulator.exe set to build directly into the Release folder for the AGS.Interfacer.dll. When the DLL is built, it will run the EXE, and copy the DLL back into the EXE's project folder. Should help keep everything in sync if there's any changes.
« Last Edit: 16 Jun 2012, 21:31 by monkey_05_06 »

Grim

  • *Dreamer Of The Day*
    • Grim worked on a game that was nominated for an AGS Award!
Just wanted to say that this module seems really interesting to me and I've been keeping an eye on this thread for a while now... Making interface is like a whole other world compared to scripting your in-game events, and I confess I do struggle with it. I often wished there was something like Interfacer... and now there is! I'm just patiently waiting for a final version to give it a go. But yeah, monkey, great idea and I totally support what you're doing! :)