private void CreateRoom() { RoomResourceView res = new RoomResourceView(Program.RoomIncremental); Program.Rooms.Add(Program.RoomIncremental, res); AddResource(Rooms.Node, res, "room" + Program.RoomIncremental++.ToString(), -1, true, false, true); }
public void Insert() { RoomResourceView res = new RoomResourceView(Program.RoomIncremental); Program.Rooms.Add(Program.RoomIncremental, res); Program.IDE.AddResource(Node, res, "room" + Program.RoomIncremental++.ToString(), -1, true, false, true); }
public void Duplicate() { RoomResourceView res = new RoomResourceView(Program.RoomIncremental); Program.Rooms.Add(Program.RoomIncremental, res); res.CreationCode = CreationCode; Program.IDE.AddResource(Node.Parent, res, "room" + Program.RoomIncremental++.ToString(), Node.Index + 1, true, false, true); }
public DesignerForm() { InitializeComponent(); PopulateNewResourceTree(); // //ScriptResourceView res = new ScriptResourceView(Program.ScriptIncremental); //Program.Scripts.Add(Program.ScriptIncremental++, res); //res.Code = Properties.Resources.scr_main; //AddResource(Scripts.Node, res, "scr_main", -1, false, false, false); // SpriteResourceView spr = new SpriteResourceView(Program.SpriteIncremental); Program.Sprites.Add(Program.SpriteIncremental++, spr); //spr.SubImages = new Bitmap[] { new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format32bppArgb) }; //Graphics.FromImage(spr.SubImages.First()).Clear(Color.Red); using (Bitmap temp = Properties.Resources.Earth) // make temp a temporary copy { spr.Animation = new FrameBasedAnimation(temp, false, false, false); } AddResource(Sprites.Node, spr, "spr_earth", -1, false, false, false); // ObjectResourceView obj = new ObjectResourceView(Program.ObjectIncremental); Program.Objects.Add(Program.ObjectIncremental++, obj); obj.Sprite = 0; obj.events.Add(new ObjectEvent(EventType.Create, 0)); // I'm likin' linq! First time using it ^^ ActionDefinition setVariable = (from lib in Program.Library where lib.TabCaption == "control" select lib.Actions into actions from action in actions where action.Name == "Variable" select action).First(); // yea let's use our setVariable action we found with linq :) obj.events[0].Actions.Add(new ActionDeclaration(setVariable)); obj.events[0].Actions[0].Arguments[0] = "image_speed"; obj.events[0].Actions[0].Arguments[1] = ".5"; obj.events[0].Actions.Add(new ActionDeclaration(setVariable)); obj.events[0].Actions[1].Arguments[0] = "image_xscale"; obj.events[0].Actions[1].Arguments[1] = "3.2"; obj.events[0].Actions.Add(new ActionDeclaration(setVariable)); obj.events[0].Actions[2].Arguments[0] = "image_yscale"; obj.events[0].Actions[2].Arguments[1] = "2.4"; //obj.events[0].Actions.Add(new ActionDeclaration(Program.Library[3].Actions[20])); // 'Execute Code' action in 'Control' lib, by index //obj.events[0].Actions[1].Arguments[0] = "show_message(\r\n \"hspeed: \" + string(hspeed) + \r\n \"#vspeed: \" + string(vspeed) + \r\n \"#speed: \" + string(speed) + \r\n \"#dir: \" + string(direction) \r\n);"; AddResource(Objects.Node, obj, "object0", -1, false, false, false); // TreeNode RoomsNode = treeView1.Nodes["Rooms"]; RoomResourceView res1 = new RoomResourceView(Program.RoomIncremental); res1.CreationCode = "instance_create(0, 0, object0)";//\r\nscr_main();"; Program.Rooms.Add(Program.RoomIncremental, res1); AddResource(Rooms.Node, res1, "room" + Program.RoomIncremental++, -1, false, false, false); }
private AssemblyBuilder CreateExecutable(string name) { ILGenerator il; name = name.Replace('\\', '/'); string exename = name.Contains('/') ? name.Substring(name.LastIndexOf('/') + 1) : name; string pathname = name.Contains('/') ? name.Remove(name.LastIndexOf('/')) : null; string asmname = exename.Contains('.') ? exename.Remove(exename.LastIndexOf('.')) : exename; // // We are generating a dynamic assembly here. // // Get type information from the runtime assembly var asm_runtime = Assembly.Load("GameCreator.Runtime"); var asm_gamei = Assembly.Load("GameCreator.Runtime.Game.Interpreted"); var asm_game = Assembly.Load("GameCreator.Runtime.Game"); Type t_gamei = asm_gamei.GetType("GameCreator.Runtime.Game.Interpreted.InterpretedGame"); Type t_game = asm_game.GetType("GameCreator.Runtime.Game.Game"); Type t_ext = typeof(ResourceExtensions); Type t_obj = typeof(Framework.Object); Type t_room = typeof(Room); Type t_event = typeof(Event); Type t_lib = typeof(Framework.ActionLibrary); Type t_context = typeof(LibraryContext); Type t_rcontext = typeof(ResourceContext); // Define our dynamic assembly System.Reflection.Emit.AssemblyBuilder asm = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(asmname), AssemblyBuilderAccess.RunAndSave, pathname); ModuleBuilder mod = asm.DefineDynamicModule(exename, exename); // Define our Program type TypeBuilder program = mod.DefineType(string.Format("{0}.Program", asmname)); System.Resources.IResourceWriter resw = mod.DefineResource(string.Format("{0}.Program.resources", asmname), string.Empty); FieldBuilder resourceManager = program.DefineField("resourceManager", typeof(System.Resources.ResourceManager), FieldAttributes.Static); MethodBuilder GetResourceManager = program.DefineMethod("GetResourceManager", MethodAttributes.Static, typeof(System.Resources.ResourceManager), Type.EmptyTypes); il = GetResourceManager.GetILGenerator(); System.Reflection.Emit.Label grm_l_1 = il.DefineLabel(); il.Emit(OpCodes.Ldsfld, resourceManager); il.Emit(OpCodes.Dup); il.Emit(OpCodes.Brtrue_S, grm_l_1); il.Emit(OpCodes.Pop); il.Emit(OpCodes.Ldstr, string.Format("{0}.Program", asmname)); il.Emit(OpCodes.Ldtoken, program); il.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle", BindingFlags.Static | BindingFlags.Public)); il.Emit(OpCodes.Callvirt, typeof(Type).GetProperty("Assembly").GetGetMethod()); il.Emit(OpCodes.Newobj, typeof(System.Resources.ResourceManager).GetConstructor(new Type[] { typeof(string), typeof(Assembly) })); il.Emit(OpCodes.Dup); il.Emit(OpCodes.Stsfld, resourceManager); il.MarkLabel(grm_l_1); il.Emit(OpCodes.Ret); //program.SetCustomAttribute(new CustomAttributeBuilder(typeof(STAThreadAttribute).GetConstructor(new Type[] { }), new object[] { })); // our static Main() function // { // GameCreator.Runtime.Object obj; // GameCreator.Runtime.Event ev; // GameCreator.Runtime.ActionLibrary lib; // GameCreator.Runtime.Game.Init(); // ... // lib = GameCreator.ActionLibrary.Define(id); // lib.DefineAction(actionid, kind, execution, question, func, code, args); // ... // GameCreator.Runtime.Script.Define("name", index, "code"); // ... // obj = GameCreator.Runtime.Object.Define("name", index); // ev = obj.DefineEvent(event, num); // ev.DefineAction(libid, actionid, args, appliesto, relative, not); // ... // GameCreator.Runtime.Room.Define("name", index).CreationCode = "code"; // ... // GameCreator.Runtime.Game.Name = "name"; // GameCreator.Runtime.Game.Run(); // (return) // } // GameCreator.Runtime.Object obj; // GameCreator.Runtime.Event ev; // GameCreator.Runtime.ActionLibrary lib; MethodBuilder initLibraries = program.DefineMethod("InitLibraries", MethodAttributes.Static); il = initLibraries.GetILGenerator(); foreach (ActionLibrary lib in Program.Library) { // lib = GameCreator.ActionLibrary.Define(id); il.EmitCall(OpCodes.Call, t_context.GetProperty("Current", BindingFlags.Public | BindingFlags.Static).GetGetMethod(), null); il.Emit(OpCodes.Ldc_I4, lib.LibraryID); il.EmitCall(OpCodes.Call, t_context.GetMethod("GetActionLibrary", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(int) }, null), null); foreach (ActionDefinition ad in lib.Actions) { // lib.DefineAction(actionid, kind, execution, question, func, code, args); il.Emit(OpCodes.Dup); il.Emit(OpCodes.Ldc_I4, ad.ActionID); il.Emit(OpCodes.Ldc_I4, (int)ad.Kind); il.Emit(OpCodes.Ldc_I4, (int)ad.ExecutionType); il.Emit(ad.IsQuestion ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); il.Emit(OpCodes.Ldstr, ad.FunctionName); il.Emit(OpCodes.Ldstr, ad.Code); // ... , new ActionArgumentType[] { x, y, z }, il.Emit(OpCodes.Ldc_I4, ad.ArgumentCount); il.Emit(OpCodes.Newarr, typeof(ActionArgumentType)); for (int i = 0; i < ad.ArgumentCount; i++) { il.Emit(OpCodes.Dup); il.Emit(OpCodes.Ldc_I4, i); il.Emit(OpCodes.Ldc_I4, (int)ad.Arguments[i].Type); il.Emit(OpCodes.Stelem_I4); } // il.EmitCall(OpCodes.Call, t_lib.GetMethod("DefineAction", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(int), typeof(ActionKind), typeof(ActionExecutionType), typeof(bool), typeof(string), typeof(string), typeof(ActionArgumentType[]) }, null), null); } il.Emit(OpCodes.Pop); } il.Emit(OpCodes.Ret); MethodBuilder defineSprites = program.DefineMethod("DefineSprites", MethodAttributes.Static); il = defineSprites.GetILGenerator(); foreach (SpriteResourceView res in Program.Sprites.Values) { // Define the resource int i = 0; foreach (Bitmap b in res.Animation.Frames) { resw.AddResource(string.Format("spr_{0}_{1}", res.ResourceID, i++), b); } // GameCreator.Runtime.Sprite.Define("name", index, subimages); il.EmitCall(OpCodes.Call, t_context.GetProperty("Current", BindingFlags.Public | BindingFlags.Static).GetGetMethod(), null); il.EmitCall(OpCodes.Call, t_context.GetProperty("Resources", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), null); il.EmitCall(OpCodes.Call, t_rcontext.GetProperty("Sprites", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), null); il.Emit(OpCodes.Ldstr, res.Name); il.Emit(OpCodes.Ldc_I4, res.ResourceID); il.Emit(OpCodes.Ldc_I4, res.Animation.FrameCount); il.EmitCall(OpCodes.Call, t_ext.GetMethod("Define", BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof(IndexedResourceManager <Sprite>), typeof(string), typeof(int), typeof(int) }, null), null); il.Emit(OpCodes.Pop); } il.Emit(OpCodes.Ret); MethodBuilder defineScripts = program.DefineMethod("DefineScripts", MethodAttributes.Static); il = defineScripts.GetILGenerator(); foreach (ScriptResourceView res in Program.Scripts.Values) { // GameCreator.Runtime.Script.Define("name", index, "code"); il.EmitCall(OpCodes.Call, t_context.GetProperty("Current", BindingFlags.Public | BindingFlags.Static).GetGetMethod(), null); il.EmitCall(OpCodes.Call, t_context.GetProperty("Resources", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), null); il.EmitCall(OpCodes.Call, t_rcontext.GetProperty("Sprites", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), null); il.Emit(OpCodes.Ldstr, res.Name); il.Emit(OpCodes.Ldc_I4, res.ResourceID); il.Emit(OpCodes.Ldstr, res.Code); il.EmitCall(OpCodes.Call, t_ext.GetMethod("Define", BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof(IndexedResourceManager <Script>), typeof(string), typeof(int), typeof(string) }, null), null); il.Emit(OpCodes.Pop); } il.Emit(OpCodes.Ret); MethodBuilder defineObjects = program.DefineMethod("DefineObjects", MethodAttributes.Static); il = defineObjects.GetILGenerator(); foreach (ObjectResourceView res in Program.Objects.Values) { // obj = GameCreator.Runtime.Object.Define("name", index); il.EmitCall(OpCodes.Call, t_context.GetProperty("Current", BindingFlags.Public | BindingFlags.Static).GetGetMethod(), null); il.EmitCall(OpCodes.Call, t_context.GetProperty("Resources", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), null); il.EmitCall(OpCodes.Call, t_rcontext.GetProperty("Objects", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), null); il.Emit(OpCodes.Ldstr, res.Name); il.Emit(OpCodes.Ldc_I4, res.ResourceID); il.EmitCall(OpCodes.Call, t_ext.GetMethod("Define", BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof(IndexedResourceManager <Framework.Object>), typeof(string), typeof(int) }, null), null); foreach (ObjectEvent ev in res.Events) { // ev = obj.DefineEvent(event, num); il.Emit(OpCodes.Dup); il.Emit(OpCodes.Ldc_I4, (int)ev.EventType); il.Emit(OpCodes.Ldc_I4, (int)ev.EventNumber); il.EmitCall(OpCodes.Call, t_obj.GetMethod("DefineEvent", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(int), typeof(int) }, null), null); foreach (ActionDeclaration ad in ev.Actions) { // ev.DefineAction(libid, actionid, args, appliesto, relative, not); il.Emit(OpCodes.Dup); il.Emit(OpCodes.Ldc_I4, ad.Kind.Library.LibraryID); il.Emit(OpCodes.Ldc_I4, ad.Kind.ActionID); // ... , new string[] { "arg", "arg", "arg" }, il.Emit(OpCodes.Ldc_I4, ad.Kind.ArgumentCount); il.Emit(OpCodes.Newarr, typeof(string)); for (int i = 0; i < ad.Kind.ArgumentCount; i++) { il.Emit(OpCodes.Dup); il.Emit(OpCodes.Ldc_I4, i); il.Emit(OpCodes.Ldstr, ad.Arguments[i]); il.Emit(OpCodes.Stelem_Ref); } // il.Emit(OpCodes.Ldc_I4, ad.AppliesTo); il.Emit(ad.Relative ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); il.Emit(ad.Not ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); il.EmitCall(OpCodes.Call, t_event.GetMethod("DefineAction", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(int), typeof(int), typeof(string[]), typeof(int), typeof(bool), typeof(bool) }, null), null); } il.Emit(OpCodes.Pop); } il.Emit(OpCodes.Dup); // obj.SpriteIndex = ind; il.Emit(OpCodes.Ldc_I4, res.Sprite); il.EmitCall(OpCodes.Call, t_obj.GetProperty("SpriteIndex").GetSetMethod(), null); //obj.Depth = d; il.Emit(OpCodes.Ldc_R8, res.Depth); il.EmitCall(OpCodes.Call, t_obj.GetProperty("Depth").GetSetMethod(), null); } il.Emit(OpCodes.Ret); MethodBuilder defineRooms = program.DefineMethod("DefineRooms", MethodAttributes.Static); il = defineRooms.GetILGenerator(); // Start defining rooms. // We perform a 'preorder iterative traversal' of the 'Rooms' TreeNode to ensure the rooms are defined in the correct order. // We can probably eliminate the stack by using the 'Parent' property of the nodes instead. Stack <TreeNode> nodes = new Stack <TreeNode>(); nodes.Push(Rooms.Node); while (nodes.Count != 0) { TreeNode tn = nodes.Pop(); if (tn.Tag.GetType() == typeof(RoomResourceView)) { RoomResourceView res = (RoomResourceView)(tn.Tag); // GameCreator.Runtime.Room.Define("name", index).CreationCode = "code"; il.EmitCall(OpCodes.Call, t_context.GetProperty("Current", BindingFlags.Public | BindingFlags.Static).GetGetMethod(), null); il.EmitCall(OpCodes.Call, t_context.GetProperty("Resources", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), null); il.EmitCall(OpCodes.Call, t_rcontext.GetProperty("Rooms", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), null); il.Emit(OpCodes.Ldstr, res.Name); il.Emit(OpCodes.Ldc_I4, res.ResourceID); il.EmitCall(OpCodes.Call, t_ext.GetMethod("Define", BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof(IndexedResourceManager <Room>), typeof(string), typeof(int) }, null), null); il.Emit(OpCodes.Ldstr, res.CreationCode); il.EmitCall(OpCodes.Call, t_room.GetProperty("CreationCode").GetSetMethod(), null); } tn = tn.LastNode; while (tn != null) { nodes.Push(tn); tn = tn.PrevNode; } } il.Emit(OpCodes.Ret); MethodBuilder main = program.DefineMethod("Main", MethodAttributes.Static); main.SetCustomAttribute(new CustomAttributeBuilder(typeof(STAThreadAttribute).GetConstructor(System.Type.EmptyTypes), new object[] { })); il = main.GetILGenerator(); // GameCreator.Runtime.Game.Interpreted.InterpretedGame.Initialize(); il.EmitCall(OpCodes.Call, t_gamei.GetMethod("Initialize"), null); // InitLibraries(); il.EmitCall(OpCodes.Call, initLibraries, null); // DefineScripts(); il.EmitCall(OpCodes.Call, defineScripts, null); // DefineSprites(); il.EmitCall(OpCodes.Call, defineSprites, null); // DefineObjects(); il.EmitCall(OpCodes.Call, defineObjects, null); // DefineRooms(); il.EmitCall(OpCodes.Call, defineRooms, null); // GameCreator.Runtime.Game.Name = "name"; //il.Emit(OpCodes.Ldstr, asmname); //il.EmitCall(OpCodes.Call, t_game.GetProperty("Name").GetSetMethod(), null); // GameCreator.Runtime.Game.ResourceManager = GetResourceManager(); il.EmitCall(OpCodes.Call, GetResourceManager, null); il.EmitCall(OpCodes.Call, t_game.GetProperty("ResourceManager").GetSetMethod(), null); // GameCreator.Runtime.Game.Interpreted.InterpretedGame.Run(); il.EmitCall(OpCodes.Call, t_gamei.GetMethod("Run"), null); // return statement, required il.Emit(OpCodes.Ret); program.CreateType(); asm.SetEntryPoint(main, PEFileKinds.WindowApplication); // Use 32 bit (i386) since GTK# requires it and we plan on using it later asm.Save(exename, PortableExecutableKinds.ILOnly, ImageFileMachine.I386); return(asm); }
public void Insert() { RoomResourceView res = new RoomResourceView(Program.RoomIncremental); Program.Rooms.Add(Program.RoomIncremental, res); Program.IDE.AddResource(Node.Parent, res, "room" + Program.RoomIncremental++.ToString(), Node.Index, true, false, true); }