Start a new topic

Binding SubClass

Sorry... But here i go again. Since i have NO DOCS on the c# bindings (Don't get me wrong, really appreciate the help i have gotten on the forums).


But i keep encountering funny things and have no where else to go...


Latest...Why can't i subclass a [JS(Extern=true)] base the class:


The Phaser.Game EXTERNAL class works great by itself, but if i subclass it get a

System.NullReferenceException: undefined is not an object (evaluating '$t.$baseType.ctor.call') error..


base class:


 

	[Js(Name="Phaser.Game", Extern=true)]
	public class Game
	{
		public extern Game(Union<number, string> width = default(Union<number, string>), Union<number, string> height = default(Union<number, string>), number renderer = default(number), any parent = default(any), any state = default(any), boolean transparent = default(boolean), boolean antialias = default(boolean), any physicsConfig = default(any));
		public extern Game(IGameConfig config);

		public Phaser.GameObjectFactory add { get; set; }
		public boolean antialias { get; set; }
		public Phaser.Cache cache { get; set; }
		public Phaser.Camera camera { get; set; }

                ...
        }

and subclass

	public class MyGame : Phaser.Game
	{
		public MyGame(double width, double height, Element element, object state) : base(width, height, PhaserClass.AUTO, element, state)
		{
			Trace.Info("***** MY GAME *****");
		}
	}

 


Now why would NORMAL sub-classing work... Unless its some kinda JS attribute combination thing... Which brings me back to NO DOCS... I need to know HOW to do some of these on a day to day basis... I have been waiting since i purchased (around a year ago)


That seems so simple... butits not working... SO I MUST BE DOING SOMETHING WRONG.


Can someone at DUOCODE please TAKE a little time and write SOME KINDA docs... I know you say read the XML comments... but that does not cut it.


What can i NOT subclass and External... And holy crap if i can't !!!


Please help... Yet again... sorry... no where else to go!!!


We are happy to see such an advanced C# bindings for extern JS libs.


Great job Mackey!

Oops.. Forgot to show how to init code example above:


 MyGame game = new MyGame(document.getElementById('container'), new MyState());


SIMPLE HUH

KUDOS... DuoCode 2.2


Subclassing externs is fixed (Plus Unions and Emit Enum Strings). Now you can make beautiful plugin apis that MIRROR the type script definitions and use the native api verbatim but with a .net context.


Take a look auth the two main classes to make phaser games (The Phaser.Game and Phaser.State really do all the work):


 

	public class MyGame : Phaser.Game
	{
		public MyGame(object parent = null, object state = null) : base(800, 600, Phaser.Globals.PhaserClass.AUTO, parent, state) { }

		[Js(Name="update")]
		public void OnUpdate(double time)
		{
			base.update(time);
			//Trace.Info("MyGame: Update Loop - {0}", time);
		}
	}

	public class MyState : Phaser.State
	{
		public MyState()
		{
			Trace.Info("Using My State");
		}

		[Js(Name = "init")]
		public void OnInit(params object[] args)
		{
			Js.function(nameof(Phaser.State.init)).apply(this, args);
			Trace.Info("*** OnInit: MY STATE INIT ***");
		}

		[Js(Name="preload")]
		public void OnPreload()
		{
			base.preload();
			Trace.Info("*** OnPreload: MY STATE PRELOAD ***");
		}

		[Js(Name = "create")]
		public void OnCreate()
		{
			base.create();
			Trace.Info("*** OnCreate: MY STATE CREATE ***");
		}
	}

 

Create large complex games (or whatever) using the strong typed native javascript (TypeScript) apis.


I think that is KOOL... For me it is what was missing from duo code... DUO CODE IS GREAT... but what is the point without API to work with... whether your making simple apps, enterprise business apps for even games and other graphic type applications (Three.js and Babylon.js Comming SOON)


Check Out Web Application Toolkit Release (Will be Update With DuoCode Version 2.2 Release):


 

=========================================
Web Application Toolkit
=========================================
AjaxGateway.Net is a GWT like development toolkit for building complex AJAX-RPC web applications. It supports HTML5 web and native client platforms using the C# and TypeScript languages. Its goal is to enable productive development of enterprise web applications for C# and TypeScript developers.<br/>

<br />
Download the latest <a href="https://raw.githubusercontent.com/MackeyK24/AjaxGateway.Net/master/Toolkits/MonoDevelop.AjaxGateway_2.0.mpack">AjaxGateway.Net - Xamarin Studio Toolkit</a><br/>

<br/>
NuGet Packages:<br/>
===============<br/>
Gateway Native Runtime Library - https://www.nuget.org/packages/Ajax.Gateway.Net<br/>
Gateway ASP.NET MVC Runtime Library - https://www.nuget.org/packages/Ajax.Gateway.Mvc<br/>
Gateway <a href="http://duoco.de">DuoCode</a> Runtime Library - https://www.nuget.org/packages/Ajax.Gateway.Duo<br/>

<br/>
DuoCode Plugins:<br/>
===============<br/>
Gateway <a href="http://duoco.de">DuoCode</a> Plugin Runtime - https://www.nuget.org/packages/DuoCode.Plugins<br/>
Gateway <a href="http://duoco.de">DuoCode</a> Query Plugin - https://www.nuget.org/packages/DuoCode.Plugins.Query<br/>
Gateway <a href="http://duoco.de">DuoCode</a> Webix Plugin - https://www.nuget.org/packages/DuoCode.Plugins.Webix<br/>
Gateway <a href="http://duoco.de">DuoCode</a> Phaser Plugin - https://www.nuget.org/packages/DuoCode.Plugins.Phaser<br/>
Gateway <a href="http://duoco.de">DuoCode</a> Kiwi Plugin - https://www.nuget.org/packages/DuoCode.Plugins.Kiwi<br/>

 





Note: kiwi.d.cs... Its not me with the duplicate Namespaces... the typescript file either has that as a Namespace or module multiple times... I will work on the converter to consolidate duplicate namespaces...


Kinda the same way i implement Namespace to class name conflicts for P2, PIXI, PHASER and KIWI...


You should notice a few classes Get ALIASED with 'Class'


For Example: Phaser.Utils is BOTH a NAMESPACE AND A CLASS at the same level... So the automative resolve switch will for thru ALL classes and types and Alias 'Class' references with 'Class' leaving the namespaces in tact... Especially NESTED namespaces and modules... Works pretty good... I have a few kinks to works out... but the Generated Code looks pretty good to me...


Check out Nuget: DuoCode Phaser Plugin for what i got so far... and the Kiwi.d.cs (Sorry about the duplicate namespaces for now)... Maybe you can find some things i did wrong in those Bindings.

  

Just in case ANYONE is interested ... Here is a work Kiwi.d.cs (Except for subclass... but you can still hack preload and create.. etc onto the Entity or whatever... as shown above). Just would be be .net real if i can be able to subclass and Native Javascript API class via C# bindings... Anyways... I digress ... Here is Kiwi for DuoCode (Required Nuget Source: Install-Package DuoCode.Plugins)

cs
(140 KB)

Here is an example that works fine... I assume is because they are both Extern = true and using 'Object' as the name... But they api works great.


 

	[Js(Name = "Object", Extern = true, OptimizeArrayEnumeration = "toArray()")]
	public class JQuery : IEnumerable<Element>
	{
		#region Class Enumerator
		extern IEnumerator<Element> IEnumerable<Element>.GetEnumerator();
		public extern IEnumerator GetEnumerator();
		#endregion

		#pragma warning disable CS0824
		extern JQuery();
		#pragma warning restore CS0824

                ...
         }


	[Js(Name = "Object", Extern = true, OptimizeArrayEnumeration = "toArray()")]
	public class Bootstrap : JQuery
	{
		#pragma warning disable CS0824
		extern Bootstrap();
		#pragma warning restore CS0824

                ...
         }

 

I Just Mapped the WHOLE Kiwi.d.ts


Works great when i use without Subclassing. Example.. This works fins:


 

			var state = new Kiwi.State("Play");
			state.As<dynamic>().preload = new Action(() => {
				Trace.Info("Got preload");
				state.addImage("sky", "Images/sky-bg.png");
			});


			state.As<dynamic>().create = new Action(() => {
				Trace.Info("Got create");
				sky = new Kiwi.GameObjects.Sprite(state, state.textures.As<dynamic>().sky, 0, 0);
				state.addChild(sky);
			});

			PropertyDescriptor gameOptions = new PropertyDescriptor() { ["width"] = 768, ["height"] = 512 };
			game = new Kiwi.Game("root", "LoaingAnImage", state, gameOptions);
			Trace.Info("DONE");

 


The moment i try to subclass the Kiwi.State with:


 

	public class MyState : Kiwi.State
	{
		public MyState(string name) : base(name)
		{
			Trace.Info("*** WTF ***");		
		}
	}

 


SO ITS THE SAME THING... Can i not subclass and Extern=true... How am i supposed to add functionality


I know i have Jquery and Bootstrap working... and bootstrap subclasses JQuery...


I just don't know what the HECK I'm doing for as the JS(Attribute) ... I guess... What can be what with what options... Thats why i need HELP... The DOCS.


Can anyone explain how to make a subclass of an extern so i can add functionality


Login or Signup to post a comment