Merge pull request #8794 from howard-stearns/clientOnly-tablet

make marketplace tablet be clientOnly
This commit is contained in:
Chris Collins 2016-10-14 10:54:54 -07:00 committed by GitHub
commit d70b58555e
2 changed files with 38 additions and 8 deletions

View file

@ -39,7 +39,7 @@ function calcSpawnInfo() {
}
// ctor
WebTablet = function (url, width, dpi) {
WebTablet = function (url, width, dpi, clientOnly) {
var ASPECT = 4.0 / 3.0;
var WIDTH = width || DEFAULT_WIDTH;
@ -63,7 +63,7 @@ WebTablet = function (url, width, dpi) {
dimensions: {x: WIDTH, y: HEIGHT, z: DEPTH},
parentID: MyAvatar.sessionUUID,
parentJointIndex: -2
});
}, clientOnly);
var WEB_ENTITY_REDUCTION_FACTOR = {x: 0.78, y: 0.85};
var WEB_ENTITY_Z_OFFSET = -0.01;
@ -84,7 +84,7 @@ WebTablet = function (url, width, dpi) {
dpi: DPI,
parentID: this.tabletEntityID,
parentJointIndex: -1
});
}, clientOnly);
this.state = "idle";
};
@ -93,4 +93,14 @@ WebTablet.prototype.destroy = function () {
Entities.deleteEntity(this.webEntityID);
Entities.deleteEntity(this.tabletEntityID);
};
WebTablet.prototype.pickle = function () {
return JSON.stringify({webEntityID: this.webEntityID, tabletEntityID: this.tabletEntityID});
};
WebTablet.unpickle = function (string) {
if (!string) {
return;
}
var tablet = JSON.parse(string);
tablet.__proto__ = WebTablet.prototype;
return tablet;
};

View file

@ -30,6 +30,10 @@ var TOOLBAR_MARGIN_Y = 0;
var marketplaceVisible = false;
var marketplaceWebTablet;
// We persist clientOnly data in the .ini file, and reconsistitute it on restart.
// To keep things consistent, we pickle the tablet data in Settings, and kill any existing such on restart and domain change.
var persistenceKey = "io.highfidelity.lastDomainTablet";
function shouldShowWebTablet() {
var rightPose = Controller.getPoseValue(Controller.Standard.RightHand);
var leftPose = Controller.getPoseValue(Controller.Standard.LeftHand);
@ -40,7 +44,8 @@ function shouldShowWebTablet() {
function showMarketplace(marketplaceID) {
if (shouldShowWebTablet()) {
updateButtonState(true);
marketplaceWebTablet = new WebTablet("https://metaverse.highfidelity.com/marketplace");
marketplaceWebTablet = new WebTablet("https://metaverse.highfidelity.com/marketplace", null, null, true);
Settings.setValue(persistenceKey, marketplaceWebTablet.pickle());
} else {
var url = MARKETPLACE_URL;
if (marketplaceID) {
@ -54,14 +59,25 @@ function showMarketplace(marketplaceID) {
UserActivityLogger.openedMarketplace();
}
function hideTablet(tablet) {
if (!tablet) {
return;
}
updateButtonState(false);
tablet.destroy();
marketplaceWebTablet = null;
Settings.setValue(persistenceKey, "");
}
function clearOldTablet() { // If there was a tablet from previous domain or session, kill it and let it be recreated
var tablet = WebTablet.unpickle(Settings.getValue(persistenceKey, ""));
hideTablet(tablet);
}
function hideMarketplace() {
if (marketplaceWindow.visible) {
marketplaceWindow.setVisible(false);
marketplaceWindow.setURL("about:blank");
} else if (marketplaceWebTablet) {
updateButtonState(false);
marketplaceWebTablet.destroy();
marketplaceWebTablet = null;
hideTablet(marketplaceWebTablet);
}
marketplaceVisible = false;
}
@ -102,6 +118,10 @@ function onClick() {
browseExamplesButton.clicked.connect(onClick);
marketplaceWindow.visibleChanged.connect(onMarketplaceWindowVisibilityChanged);
clearOldTablet(); // Run once at startup, in case there's anything laying around from a crash.
// We could also optionally do something like Window.domainChanged.connect(function () {Script.setTimeout(clearOldTablet, 2000)}),
// but the HUD version stays around, so lets do the same.
Script.scriptEnding.connect(function () {
toolBar.removeButton("marketplace");
browseExamplesButton.clicked.disconnect(onClick);