-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML5FrontEnd: Add platform and mobile detection #1897
Changes from 1 commit
c57766b
108933a
bb81af4
ce735a7
1602b0a
e873a91
162d77a
19b7c37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ class HTML5FrontEnd | |
public var browserWidth(get, never):Int; | ||
public var browserHeight(get, never):Int; | ||
public var browserPosition(get, null):FlxPoint; | ||
public var platform(get, never):FlxPlatform; | ||
public var isMobile(get, never):Bool; | ||
|
||
@:allow(flixel.FlxG) | ||
private function new() {} | ||
|
@@ -37,7 +39,7 @@ class HTML5FrontEnd | |
{ | ||
return SAFARI; | ||
} | ||
return UNKNOWN; | ||
return FlxBrowser.UNKNOWN; | ||
} | ||
|
||
private function get_browserPosition():FlxPoint | ||
|
@@ -59,6 +61,49 @@ class HTML5FrontEnd | |
{ | ||
return Browser.window.innerHeight; | ||
} | ||
|
||
private inline function get_platform():FlxPlatform | ||
{ | ||
|
||
if (Browser.navigator.userAgent.indexOf("Win") > -1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably wrap There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, and instead of |
||
{ | ||
return WINDOWS; | ||
} | ||
else if (Browser.navigator.userAgent.indexOf("Linux") > -1 | ||
&& Browser.navigator.userAgent.indexOf("Android") == -1) | ||
{ | ||
return LINUX; | ||
} | ||
else if (Browser.navigator.userAgent.indexOf("X11") > -1) | ||
{ | ||
return UNIX; | ||
} | ||
else if (Browser.navigator.userAgent.indexOf("Android") > -1) | ||
{ | ||
return ANDROID; | ||
} | ||
else if (Browser.navigator.userAgent.indexOf("BlackBerry") > -1) | ||
{ | ||
return BLACKBERRY; | ||
} | ||
else if (Browser.navigator.userAgent.indexOf("iPhone") > -1 | ||
|| Browser.navigator.userAgent.indexOf("iPad") > -1 | ||
|| Browser.navigator.userAgent.indexOf("iPod") > -1) | ||
{ | ||
return IOS; | ||
} | ||
else if (Browser.navigator.userAgent.indexOf("IEMobile") > -1) | ||
{ | ||
return WINDOWS_PHONE; | ||
} | ||
else return FlxPlatform.UNKNOWN; | ||
} | ||
|
||
private inline function get_isMobile():Bool | ||
{ | ||
var platform = this.platform; | ||
return platform == ANDROID || platform == BLACKBERRY || platform == IOS || platform == WINDOWS_PHONE; | ||
} | ||
} | ||
|
||
enum FlxBrowser | ||
|
@@ -70,4 +115,17 @@ enum FlxBrowser | |
OPERA; | ||
UNKNOWN; | ||
} | ||
|
||
enum FlxPlatform | ||
{ | ||
WINDOWS; | ||
LINUX; | ||
UNIX; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly does |
||
MAC; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... |
||
ANDROID; | ||
BLACKBERRY; | ||
WINDOWS_PHONE; | ||
IOS; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems |
||
UNKNOWN; | ||
} | ||
#end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is way to long to be a good candidate for
inline
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably just run this entire thing once in
new()
and cache the result? It's not like it's gonna change at runtime, right? :)