MODULE+PLUGIN: Interfacer v0.80 Beta 4 - Scripting your interface, simplified!

Started by monkey0506, Thu 17/05/2012 02:25:55

Previous topic - Next topic

monkey0506

Presently it's linking against the Interfacer plugin itself:

Code: CSharp
using AGS.Plugin.Interfacer;
using System;
using System.IO;

namespace InterfacerModulator
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string name = InterfacerModule.Name; // InterfacerModule is a new helper class in AGS.Plugin.Interfacer.dll
                string fileName = Path.GetFullPath(name + ".scm");
                string author = InterfacerModule.Author;
                string description = InterfacerModule.Description;
                string version = InterfacerModule.Version;
                string scriptText = InterfacerModule.ScriptText;
                string headerText = InterfacerModule.HeaderText;
                int uniqueKey = InterfacerModule.UniqueKey;
                Exporter.ExportScriptModule(fileName, author, description, name, version, scriptText, headerText, uniqueKey);
            }
            catch
            {
            }
        }
    }
}


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

Code: CSharp
using System.IO;
using System.Text;

namespace InterfacerModulator
{
    internal class Exporter
    {
        private const string MODULE_FILE_SIGNATURE = "AGSScriptModule\0";
        private const uint MODULE_FILE_TRAILER = 0xb4f76a65;

        public static void ExportScriptModule(string fileName, string author, string description, string name,
            string version, string scriptText, string headerText, int uniqueKey)
        {
            BinaryWriter writer = new BinaryWriter(new FileStream(fileName, FileMode.Create, FileAccess.Write));
            writer.Write(Encoding.ASCII.GetBytes(MODULE_FILE_SIGNATURE));
            writer.Write((int)1); // version (???)
            WriteNullTerminatedString(author, writer);
            WriteNullTerminatedString(description, writer);
            WriteNullTerminatedString(name, writer);
            WriteNullTerminatedString(version, writer);
            writer.Write((int)scriptText.Length);
            WriteNullTerminatedString(scriptText, writer);
            writer.Write((int)headerText.Length);
            WriteNullTerminatedString(headerText, writer);
            writer.Write((int)uniqueKey);
            writer.Write((int)0); // Permissions
            writer.Write((int)0); // We are owner
            writer.Write((uint)MODULE_FILE_TRAILER);
            writer.Close();
        }

        private static void WriteNullTerminatedString(string text, BinaryWriter writer)
        {
            writer.Write(Encoding.Default.GetBytes(text));
            writer.Write((byte)0);
        }
    }
}


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.

Grim

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! :)

SMF spam blocked by CleanTalk