overte/unpublishedScripts/DomainContent/Home/reset.js
2016-03-27 16:44:53 -07:00

348 lines
No EOL
12 KiB
JavaScript

//
// reset.js
//
// Created by James B. Pollack @imgntn on 3/14/2016
// Copyright 2016 High Fidelity, Inc.
//
// This cleanups up and creates content for the home.
//
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
var _this;
function Reset() {
_this = this;
}
var utilsPath = Script.resolvePath('utils.js');
var kineticPath = Script.resolvePath("kineticObjects/wrapper.js?" + Math.random());
var fishTankPath = Script.resolvePath('fishTank/wrapper.js?' + Math.random());
var tiltMazePath = Script.resolvePath("tiltMaze/wrapper.js?" + Math.random())
var whiteboardPath = Script.resolvePath("whiteboard/wrapper.js?" + Math.random());
var plantPath = Script.resolvePath("growingPlant/wrapper.js?" + Math.random());
var cuckooClockPath = Script.resolvePath("cuckooClock/wrapper.js?" + Math.random());
var pingPongGunPath = Script.resolvePath("pingPongGun/wrapper.js?" + Math.random());
var transformerPath = Script.resolvePath("dressingRoom/wrapper.js?" + Math.random());
Script.include(utilsPath);
Script.include(kineticPath);
Script.include(fishTankPath);
Script.include(tiltMazePath);
Script.include(whiteboardPath);
// Script.include(plantPath);
Script.include(cuckooClockPath);
Script.include(pingPongGunPath);
Script.include(transformerPath);
var TRANSFORMER_URL_ARTEMIS = 'http://hifi-public.s3.amazonaws.com/ryan/DefaultAvatarFemale2/0314HiFiFemAviHeightChange.fbx';
var TRANSFORMER_URL_ALBERT = 'https://s3.amazonaws.com/hifi-public/ozan/avatars/albert/albert/albert.fbx';
var TRANSFORMER_URL_BEING_OF_LIGHT = 'http://hifi-public.s3.amazonaws.com/ryan/0318HiFiBoL/0318HiFiBoL.fbx';
var TRANSFORMER_URL_KATE = 'https://hifi-public.s3.amazonaws.com/ozan/avatars/kate/kate/kate.fbx';
var TRANSFORMER_URL_WILL = 'https://s3.amazonaws.com/hifi-public/models/skeletons/Will/Will.fbx';
Reset.prototype = {
tidying: false,
preload: function(entityID) {
_this.entityID = entityID;
},
showTidyingButton: function() {
var textureString =
'Texture.001:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Head-Housing-Texture.png",\ntex.face.screen.emit:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/tidy-guy-face-Emit.png",\ntex.face.sceen:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/tidy-guy-face.png",\ntex.button.blanks:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Button-Blanks.png",\ntex.button.blanks.normal:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Button-Blanks-Normal.png",\nbutton.tidy.emit:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidy-Up-Button-Orange-Emit.png",\nbutton.tidy:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidy-Up-Button-Orange.png"'
Entities.editEntity(_this.entityID, {
textures: textureString
});
},
showTidyButton: function() {
var textureString =
'Texture.001:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Head-Housing-Texture.png",\ntex.face.screen.emit:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/tidy-guy-face-Emit.png",\ntex.face.sceen:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/tidy-guy-face.png",\ntex.button.blanks:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Button-Blanks.png",\ntex.button.blanks.normal:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Button-Blanks-Normal.png",\nbutton.tidy.emit:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Tidy-Up-Button-Green-Emit.png",\nbutton.tidy:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Tidy-Up-Button-Green.png"'
Entities.editEntity(_this.entityID, {
textures: textureString
});
},
playTidyingSound: function() {
},
toggleButton: function() {
if (_this.tidying === true) {
return;
} else {
_this.tidying = true;
_this.showTidyingButton();
_this.playTidyingSound();
_this.findAndDeleteHomeEntities();
Script.setTimeout(function() {
_this.showTidyButton();
_this.tidying = false;
}, 2500);
Script.setTimeout(function() {
_this.createKineticEntities();
_this.createDynamicEntities();
_this.createTransformers();
}, 750)
}
},
clickReleaseOnEntity: function(entityID, mouseEvent) {
if (!mouseEvent.isLeftButton) {
return;
}
_this.toggleButton();
},
startNearTrigger: function() {
_this.toggleButton();
},
createDynamicEntities: function() {
return;
print("EBL CREATE DYNAMIC ENTITIES");
var fishTank = new FishTank({
x: 1098.9254,
y: 460.5814,
z: -79.1103
}, {
x: 0,
y: 123,
z: 0
});
var tiltMaze = new TiltMaze({
x: 1105.5768,
y: 460.3298,
z: -80.4891
});
var whiteboard = new Whiteboard({
x: 1104,
y: 460.5,
z: -77
}, {
x: 0,
y: -133,
z: 0
});
// var myPlant = new Plant({
// x: 1099.8785,
// y: 460.3115,
// z: -84.7736
// }, {
// x: 0,
// y: 0,
// z: 0
// });
var pingPongGun = new HomePingPongGun({
x: 1101.2123,
y: 460.2328,
z: -65.8513
}, {
x: 97.3683,
y: 179.0293,
z: 89.9698
});
var cuckooClock = new MyCuckooClock({
x: 1105.267,
y: 461.44,
z: -81.9495
}, {
x: 0,
y: -57,
z: 0
});
//v2.0
// var musicBox = new MusicBox();
// var doppelganger = new Doppelganger();
},
createKineticEntities: function() {
return;
var blocks = new Blocks({
x: 1097.1383,
y: 460.3790,
z: -66.4895
});
var fruitBowl = new FruitBowl({
x: 1105.3185,
y: 460.3221,
z: -81.2452
});
var livingRoomLamp = new LivingRoomLamp({
x: 1104.6732,
y: 460.3326,
z: -81.9710
});
var upperBookShelf = new UpperBookShelf({
x: 1106.2649,
y: 461.5352,
z: -80.3018
});
var lowerBookShelf = new LowerBookShelf({
x: 1106.2725,
y: 460.9600,
z: -80.2837
});
// var rightDeskDrawer = new RightDeskDrawer({
// x: 1105.1735,
// y: 460.0446,
// z: -81.3612
// });
// var leftDeskDrawer = new LeftDeskDrawer({
// x: 1104.6478,
// y: 460.0463,
// z: -82.1095
// });
var chair = new Chair({
x: 1105.2716,
y: 459.7251,
z: -79.8097
});
var trashcan = new Trashcan({
x: 1103.9034,
y: 459.4355,
z: -82.3619
});
var books = new Books({
x: 1106.1553,
y: 461.1,
z: -80.4890
});
var cellPoster = new PosterCell({
x: 1103.78,
y: 461,
z: -70.3
});
var playaPoster = new PosterPlaya({
x: 1101.8,
y: 461,
z: -73.3
});
var livingRoomLampTriggerBoxName = "hifi-home-living-room-desk-lamp-trigger";
var livingRoomLampModelName = "hifi-home-model-bulldog-base";
Script.setTimeout(function() {
attachChildToParent(livingRoomLampTriggerBoxName, livingRoomLampModelName, MyAvatar.position, 20);
}, 1000);
},
createTransformers: function() {
print('CREATING TRANSFORMERS!')
var firstDollPosition = {
x: 1108.2123,
y: 460.7516,
z: -80.9387
}
var dollRotation = {
x: 0,
y: 28,
z: 0,
}
var dolls = [
TRANSFORMER_URL_ARTEMIS,
TRANSFORMER_URL_ALBERT,
TRANSFORMER_URL_BEING_OF_LIGHT,
TRANSFORMER_URL_KATE,
TRANSFORMER_URL_WILL
];
var dollLateralSeparation = 0.5;
dolls.forEach(function(doll, index) {
print('CREATE TRANSFORMER:: ' + doll)
var separation = index * dollLateralSeparation;
var right = Quat.getRight(dollRotation);
var left = Vec3.multiply(-1, right);
var howFarLeft = Vec3.multiply(separation, left);
var distanceToLeft = Vec3.sum(firstDollPosition, howFarLeft);
print('PARAMS AT CREATE')
print('distanceToLeft : ' + JSON.stringify(distanceToLeft))
print('dollRotation : ' + JSON.stringify(dollRotation))
var transformer = new TransformerDoll(doll, distanceToLeft, dollRotation);
});
},
findAndDeleteHomeEntities: function() {
print('JBP trying to find home entities to delete')
var resetProperties = Entities.getEntityProperties(_this.entityID);
var results = Entities.findEntities(resetProperties.position, 1000);
var found = [];
results.forEach(function(result) {
var properties = Entities.getEntityProperties(result);
if (properties.userData === "" || properties.userData === undefined) {
print('no userdata -- its blank or undefined')
return;
}
var userData = null;
try {
userData = JSON.parse(properties.userData);
} catch (err) {
print('error parsing json in resetscript for: ' + properties.name);
//print('properties are:' + properties.userData);
return;
}
if (userData.hasOwnProperty('hifiHomeKey')) {
if (userData.hifiHomeKey.reset === true) {
Entities.deleteEntity(result);
}
}
})
print('JBP after deleting home entities')
},
unload: function() {
// this.findAndDeleteHomeEntities();
}
}
return new Reset();
});