mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
finally ios support (web)
This commit is contained in:
parent
f6a9880364
commit
19e23cdc91
7 changed files with 104 additions and 19 deletions
|
|
@ -90,14 +90,16 @@ class CameraController extends Object {
|
|||
pointercontainer.hidden = true;
|
||||
#end
|
||||
_ignoreCursor = true;
|
||||
Window.getInstance().lockPointer((x, y) -> orbit(x, y));
|
||||
if (!Util.isTouchDevice())
|
||||
Window.getInstance().lockPointer((x, y) -> orbit(x, y));
|
||||
#if hl
|
||||
Cursor.show(false);
|
||||
#end
|
||||
}
|
||||
|
||||
public function unlockCursor() {
|
||||
Window.getInstance().unlockPointer();
|
||||
if (!Util.isTouchDevice())
|
||||
Window.getInstance().unlockPointer();
|
||||
#if hl
|
||||
Cursor.show(true);
|
||||
#end
|
||||
|
|
|
|||
|
|
@ -150,6 +150,11 @@ class DtsObject extends GameObject {
|
|||
}
|
||||
|
||||
isInstanced = false;
|
||||
|
||||
if (!Util.isIOSInstancingSupported()) {
|
||||
this.useInstancing = false;
|
||||
}
|
||||
|
||||
if (this.level != null)
|
||||
isInstanced = this.level.instanceManager.isInstanced(this) && useInstancing;
|
||||
if (!isInstanced)
|
||||
|
|
@ -461,7 +466,7 @@ class DtsObject extends GameObject {
|
|||
var texture = ResourceLoader.getResource(fullName, ResourceLoader.getTexture, this.textureResources);
|
||||
texture.wrap = Wrap.Repeat;
|
||||
material.texture = texture;
|
||||
if (this.useInstancing) {
|
||||
if (this.identifier != "Marble") {
|
||||
var dtsshader = new DtsTexture();
|
||||
dtsshader.texture = texture;
|
||||
dtsshader.currentOpacity = 1;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import h3d.Matrix;
|
|||
import collision.CollisionEntity;
|
||||
import src.GameObject;
|
||||
import h3d.scene.Object;
|
||||
import src.Util;
|
||||
|
||||
class InteriorObject extends GameObject {
|
||||
public var collider:CollisionEntity;
|
||||
|
|
@ -25,6 +26,11 @@ class InteriorObject extends GameObject {
|
|||
this.level = level;
|
||||
if (this.level != null)
|
||||
this.collisionWorld = this.level.collisionWorld;
|
||||
|
||||
if (!Util.isIOSInstancingSupported()) {
|
||||
this.useInstancing = false;
|
||||
}
|
||||
|
||||
DifBuilder.loadDif(this.interiorFile, cast this, onFinish, -1, this.isCollideable);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,21 +32,23 @@ class JSPlatform {
|
|||
|
||||
var lastImmunityTime = Math.NEGATIVE_INFINITY;
|
||||
|
||||
js.Browser.window.setInterval(() -> {
|
||||
if (js.Browser.document.activeElement != null) {
|
||||
if (Util.isTouchDevice() && !Util.isSafari()) {
|
||||
if (Util.isInFullscreen()) {
|
||||
// They're in fullscreen, hide the overlay
|
||||
fullscreenEnforcer.classList.add('hidden');
|
||||
} else if (!dislikesFullscreen && js.Browser.window.performance.now() - lastImmunityTime > 666) {
|
||||
// They're not in fullscreen, show the overlay
|
||||
fullscreenEnforcer.classList.remove('hidden');
|
||||
if (!Util.isIOS()) {
|
||||
js.Browser.window.setInterval(() -> {
|
||||
if (js.Browser.document.activeElement != null) {
|
||||
if (Util.isTouchDevice() && !Util.isSafari()) {
|
||||
if (Util.isInFullscreen()) {
|
||||
// They're in fullscreen, hide the overlay
|
||||
fullscreenEnforcer.classList.add('hidden');
|
||||
} else if (!dislikesFullscreen && js.Browser.window.performance.now() - lastImmunityTime > 666) {
|
||||
// They're not in fullscreen, show the overlay
|
||||
fullscreenEnforcer.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setEnterFullscreenButtonVisibility(fullscreenButtonVisibility);
|
||||
}
|
||||
}, 250);
|
||||
setEnterFullscreenButtonVisibility(fullscreenButtonVisibility);
|
||||
}
|
||||
}, 250);
|
||||
}
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
|
|
|||
|
|
@ -384,6 +384,7 @@ class Marble extends GameObject {
|
|||
|
||||
var marbleDts = new DtsObject();
|
||||
var marbleShader = "";
|
||||
marbleDts.identifier = "Marble";
|
||||
if (connection == null) { // Our marble
|
||||
Console.log("Marble: " + Settings.optionsSettings.marbleModel + " (" + Settings.optionsSettings.marbleSkin + ")");
|
||||
marbleDts.dtsPath = Settings.optionsSettings.marbleModel;
|
||||
|
|
|
|||
|
|
@ -543,7 +543,9 @@ class Settings {
|
|||
var wnd = Window.getInstance();
|
||||
var zoomRatio = Window.getInstance().windowToPixelRatio;
|
||||
#if js
|
||||
var zoomRatio = Util.isTouchDevice() ? js.Browser.window.screen.height * js.Browser.window.devicePixelRatio / 768 : js.Browser.window.devicePixelRatio; // 768 / js.Browser.window.innerHeight; // js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio / 768;
|
||||
var zoomRatio = (Util.isTouchDevice() && !Util.isTablet()) ? js.Browser.window.screen.height * js.Browser.window.devicePixelRatio / 768 : js.Browser.window.devicePixelRatio; // 768 / js.Browser.window.innerHeight; // js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio / 768;
|
||||
if (Util.isIPhone())
|
||||
zoomRatio = 1.5;
|
||||
Settings.zoomRatio = zoomRatio;
|
||||
#end
|
||||
#if android
|
||||
|
|
@ -555,8 +557,10 @@ class Settings {
|
|||
Settings.optionsSettings.screenHeight = cast wnd.height;
|
||||
#end
|
||||
#if js
|
||||
Settings.optionsSettings.screenWidth = cast js.Browser.window.screen.width; // 1024; // cast(js.Browser.window.innerWidth / js.Browser.window.innerHeight) * 768; // cast js.Browser.window.innerWidth * js.Browser.window.devicePixelRatio * 0.5;
|
||||
Settings.optionsSettings.screenHeight = cast js.Browser.window.screen.height; // 768; // cast js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio * 0.5;
|
||||
Settings.optionsSettings.screenWidth = cast Math.max(js.Browser.window.screen.width,
|
||||
js.Browser.window.screen.height); // 1024; // cast(js.Browser.window.innerWidth / js.Browser.window.innerHeight) * 768; // cast js.Browser.window.innerWidth * js.Browser.window.devicePixelRatio * 0.5;
|
||||
Settings.optionsSettings.screenHeight = cast Math.min(js.Browser.window.screen.width,
|
||||
js.Browser.window.screen.height); // 768; // cast js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio * 0.5;
|
||||
|
||||
var canvasElement = js.Browser.document.getElementById("webgl");
|
||||
canvasElement.style.width = "100%";
|
||||
|
|
|
|||
65
src/Util.hx
65
src/Util.hx
|
|
@ -392,6 +392,10 @@ class Util {
|
|||
#if js
|
||||
switch (Settings.isTouch) {
|
||||
case None:
|
||||
if (isIOS()) {
|
||||
Settings.isTouch = Some(true);
|
||||
return true;
|
||||
}
|
||||
Settings.isTouch = Some(js.lib.Object.keys(js.Browser.window).contains('ontouchstart'));
|
||||
return js.lib.Object.keys(js.Browser.window).contains('ontouchstart');
|
||||
case Some(val):
|
||||
|
|
@ -430,6 +434,67 @@ class Util {
|
|||
#end
|
||||
}
|
||||
|
||||
public static inline function isIOS() {
|
||||
#if js
|
||||
var reg = ~/iPad|iPhone|iPod/;
|
||||
return reg.match(js.Browser.navigator.userAgent);
|
||||
#end
|
||||
#if hl
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public static inline function isTablet() {
|
||||
#if js
|
||||
var reg = ~/iPad|tablet/;
|
||||
return reg.match(js.Browser.navigator.userAgent);
|
||||
#end
|
||||
#if hl
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public static inline function isIPhone() {
|
||||
#if js
|
||||
var reg = ~/iPhone/;
|
||||
return reg.match(js.Browser.navigator.userAgent);
|
||||
#end
|
||||
#if hl
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public static function isIOSInstancingSupported() {
|
||||
#if js
|
||||
static var _supported = null;
|
||||
if (_supported != null)
|
||||
return _supported;
|
||||
|
||||
if (isIOS()) {
|
||||
var reg = ~/OS (\d+)_(\d+)_?(\d+)?/;
|
||||
if (reg.match(js.Browser.navigator.userAgent)) {
|
||||
var mainVer = Std.parseInt(reg.matched(1));
|
||||
if (mainVer < 17) {
|
||||
_supported = false;
|
||||
return false;
|
||||
} else {
|
||||
_supported = true;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
_supported = false;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
_supported = true;
|
||||
return true;
|
||||
}
|
||||
#end
|
||||
#if hl
|
||||
return true;
|
||||
#end
|
||||
}
|
||||
|
||||
public static inline function isInFullscreen() {
|
||||
#if js
|
||||
return (js.Browser.window.innerHeight == js.Browser.window.screen.height
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue