gavioto / playn

Automatically exported from code.google.com/p/playn
0 stars 0 forks source link

Please design all the Platform classes to be extensible. #215

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
For our game, we need a customization of PlayN that provides access to HTTP 
request and response headers. For this, I wrote a small extension that builds 
upon PlayN. See https://github.com/inder123/playn-ext

My life will be a lot easier if the fields in each of the platform classes were 
set with protected visibility.
It would also help a great deal if the fields were initialized through an 
additional constructor that took them as parameters. 

Here is an example version:

public JavaPlatform extends Abstract Platform {
  protected final JavaAnalytics analytics;
  protected final JavaAudio audio;
  protected final JavaNet net;
  protected final JavaRegularExpression regex;
  protected final JavaStorage storage;
  protected final JsonImpl json;
  protected final JavaKeyboard keyboard;
  protected final JavaPointer pointer;
  protected final JavaGraphics graphics;
  protected final JavaMouse mouse;
  protected final JavaAssets assets;

  public JavaPlatform(float scaleFactor, boolean headless) {
    this(scaleFactor, headless, new JavaAnalytics(), new JavaAudio(), new JavaNet(this), new JavaRegularExpression(), new JavaStorage(), new JsonImpl(), new JavaKeyboard(), new JavaPointer(), new JavaGraphics(this, scaleFactor, headless), new JavaMouse(), new JavaAssets(this));
  }

  protected JavaPlatform( JavaAnalytics analytics, JavaAudio audio, .....) {
  super(new JavaLog());
  this.analytics = analytics;
  this.audio = audio;
  // initalize others
}

Similar constructor would be needed for IOSPlatform, AndroidPlatform, and 
HtmlPlatform.
Thank you.

Original issue reported on code.google.com by inder123 on 5 Sep 2012 at 8:48

GoogleCodeExporter commented 9 years ago
Here is an example of how to do this for the iOS version of the platform:
http://code.google.com/r/inder123-playn/source/detail?r=a6cd6c22a0b5aeb0a43f1b26
9dbaf4945684dcdb&name=inder/extensible

If it helps you, I can provide similar revisions for all the platforms in this 
branch.

Original comment by inder123 on 5 Sep 2012 at 9:26