Gamua / Starling-Framework

The Cross Platform Game Engine
http://www.starling-framework.org
Other
2.82k stars 821 forks source link

Suggestion: override platform in SystemUtil #979

Closed kevinfoley closed 7 years ago

kevinfoley commented 7 years ago

Using SystemUtil, we can easily add platform-specific functionality.

if (SystemUtil.isIOS)
    quitButton.visible = false;
else
    quitButton.addEventListener(Event.TRIGGERED, onPressQuit);

if (SystemUtil.isDesktop) 
    showDesktopStuff();

However, this can be a headache if we want to temporarily test platform-specific functionality on a different platform (particularly, testing mobile layouts or functionality in the desktop debugger):

if (SystemUtil.isIOS || true) { //NOTE TO SELF: DON'T FORGET TO REMOVE '|| true' !
    quitButton.visible = false;
else
    quitButton.addEventListener(Event.TRIGGERED, onPressQuit);

if (SystemUtil.isDesktop && false) //NOTE TO SELF: DON'T FORGET TO REMOVE '&& false' !
    showDesktopStuff();

Obviously there are cleaner ways to handle this than my contrived examples. However, it would be nice if we could override the current platform in SystemUtil so that we didn't have to do it elsewhere. Something to the effect of SystemUtil.pretendPlatformIsAndroid()

PrimaryFeather commented 7 years ago

Good idea!

I simply added a setter for SystemUtil.platform. That should do the trick.

joshtynjala commented 7 years ago

It's worth mentioning that you can use the -XversionPlatform option when running a mobile AIR app on desktop with ADL.

-XversionPlatform IOS -XversionPlatform AND

If you're launching from an IDE, there may be a way to pass additional options to ADL.

(I know that Animate CC doesn't support extra ADL options, so the ability to override the platform in ActionScript is still a good idea)