mirror of
https://github.com/overte-org/overte.git
synced 2025-06-20 23:20:09 +02:00
added OverlayPreloader and made a bunch of clones
This commit is contained in:
parent
cbb3d463b6
commit
e964741e30
1 changed files with 110 additions and 94 deletions
|
@ -11,6 +11,9 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
const NUM_OF_TREES = 40;
|
||||
const NUM_OF_SANTAS = 20;
|
||||
|
||||
// Image source: https://openclipart.org/detail/447/christmas-tree-by-theresaknott (heavily edited by Maximillian Merlin)
|
||||
const CHRISTMAS_TREE_SPRITES_URL = "http://test.thoys.nl/hifi/images/santa/christmas-tree.svg";
|
||||
|
||||
|
@ -27,13 +30,31 @@ Array.prototype.contains = function(obj) {
|
|||
return false;
|
||||
};
|
||||
|
||||
function getRandomPosAroundMyAvatar(radius) {
|
||||
return {x: MyAvatar.position.x + Math.floor(Math.random() * radius * 2) - radius, y: MyAvatar.position.y, z: MyAvatar.position.z + Math.floor(Math.random() * radius * 2) - radius};
|
||||
function getRandomPosAroundMyAvatar(radius, height_offset) {
|
||||
if (height_offset == undefined) {
|
||||
height_offset = 0;
|
||||
}
|
||||
return {x: MyAvatar.position.x + Math.floor(Math.random() * radius * 2) - radius, y: MyAvatar.position.y + height_offset, z: MyAvatar.position.z + Math.floor(Math.random() * radius * 2) - radius};
|
||||
}
|
||||
|
||||
function SpriteBillboard(sprite_properties) {
|
||||
function OverlayPreloader(overlay_type, overlay_properties, loaded_callback) {
|
||||
var _this = this;
|
||||
this.loaded_callback = loaded_callback;
|
||||
this.overlay = Overlays.addOverlay(overlay_type, overlay_properties);
|
||||
this.timer = null;
|
||||
this.timer = Script.setInterval(function() {
|
||||
if (Overlays.isLoaded(_this.overlay)) {
|
||||
Script.clearInterval(_this.timer);
|
||||
_this.loaded_callback();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function SpriteBillboard(sprite_properties, overlay) {
|
||||
var _this = this;
|
||||
|
||||
// set properties
|
||||
this.overlay = overlay;
|
||||
this.overlay_properties = {};
|
||||
this.sprite_properties = sprite_properties;
|
||||
this.edited_overlay_properties = [];
|
||||
|
@ -67,12 +88,6 @@ function SpriteBillboard(sprite_properties) {
|
|||
return _this;
|
||||
};
|
||||
|
||||
this.setURL = function(url) {
|
||||
this.overlay_properties.url = url;
|
||||
this.editedProperty("url");
|
||||
return _this;
|
||||
}
|
||||
|
||||
this.setAlpha = function(alpha) {
|
||||
this.overlay_properties.alpha = alpha;
|
||||
this.editedProperty("alpha");
|
||||
|
@ -171,7 +186,6 @@ function SpriteBillboard(sprite_properties) {
|
|||
YMoveNext = Math.abs(nextY - _this.sequenceY) == 1;
|
||||
}
|
||||
canMoveToNext = XMoveNext && YMoveNext;
|
||||
|
||||
}
|
||||
if (canMoveToNext) {
|
||||
_this.sequenceIndex = nextIndex;
|
||||
|
@ -223,9 +237,7 @@ function SpriteBillboard(sprite_properties) {
|
|||
this.setPosition(this.sprite_properties.position);
|
||||
}
|
||||
|
||||
// set the overlay
|
||||
this.overlay = Overlays.addOverlay("billboard", this.overlay_properties);
|
||||
this.new_properties = {};
|
||||
_this.commitChanges();
|
||||
|
||||
if (this.sprite_properties.startup_sequence != undefined) {
|
||||
this.start(this.sprite_properties.startup_sequence);
|
||||
|
@ -239,20 +251,30 @@ function SpriteBillboard(sprite_properties) {
|
|||
});
|
||||
}
|
||||
|
||||
var chrismastree = new SpriteBillboard({
|
||||
position: getRandomPosAroundMyAvatar(6),
|
||||
url: CHRISTMAS_TREE_SPRITES_URL,
|
||||
var christmastree_loader = null;
|
||||
christmastree_loader = new OverlayPreloader("billboard",
|
||||
{url: CHRISTMAS_TREE_SPRITES_URL, alpha: 0}, function() {
|
||||
for (var i = 0; i < NUM_OF_TREES; i++) {
|
||||
var clonedOverlay = Overlays.cloneOverlay(christmastree_loader.overlay);
|
||||
new SpriteBillboard({
|
||||
position: getRandomPosAroundMyAvatar(20),
|
||||
sprite_size: {x: 0, y: 0, width: 250.000, height: 357.626},
|
||||
scale: 6,
|
||||
alpha: 1,
|
||||
sequences: {"idle": [{x: 0, y: 0, step_to_next: true, fps: 3}, {x: 3, step_to_next: false}]},
|
||||
startup_sequence: "idle"
|
||||
});
|
||||
}, clonedOverlay);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
var santa = new SpriteBillboard({
|
||||
position: getRandomPosAroundMyAvatar(6),
|
||||
url: SANTA_SPRITES_URL,
|
||||
loop: true,
|
||||
var santa_loader = null;
|
||||
santa_loader = new OverlayPreloader("billboard",
|
||||
{url: SANTA_SPRITES_URL, alpha: 0}, function() {
|
||||
for (var i = 0; i < NUM_OF_SANTAS; i++) {
|
||||
var clonedOverlay = Overlays.cloneOverlay(santa_loader.overlay);
|
||||
new SpriteBillboard({
|
||||
position: getRandomPosAroundMyAvatar(18, -1),
|
||||
sprite_size: {x: 0, y: 0, width: 64, height: 72},
|
||||
scale: 4,
|
||||
alpha: 1,
|
||||
|
@ -260,19 +282,13 @@ var santa = new SpriteBillboard({
|
|||
"walk_left": [{x: 2, y: 0, step_to_next: true, fps: 4}, {x: 10, step_to_next: false}],
|
||||
"walk_right": [{x: 10, y: 1, step_to_next: true, fps: 4}, {x: 2, step_to_next: false}],
|
||||
},
|
||||
startup_sequence: "walk_left"
|
||||
});
|
||||
startup_sequence: (i % 2 == 0) ? "walk_left" : "walk_right"
|
||||
}, clonedOverlay);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
var santa = new SpriteBillboard({
|
||||
position: getRandomPosAroundMyAvatar(6),
|
||||
url: SANTA_SPRITES_URL,
|
||||
loop: true,
|
||||
sprite_size: {x: 0, y: 0, width: 64, height: 72},
|
||||
scale: 4,
|
||||
alpha: 1,
|
||||
sequences: {
|
||||
"walk_left": [{x: 2, y: 0, step_to_next: true, fps: 4}, {x: 10, step_to_next: false}],
|
||||
"walk_right": [{x: 10, y: 1, step_to_next: true, fps: 4}, {x: 2, step_to_next: false}],
|
||||
},
|
||||
startup_sequence: "walk_right"
|
||||
Script.scriptEnding.connect(function () {
|
||||
Overlays.deleteOverlay(christmastree_loader.overlay);
|
||||
Overlays.deleteOverlay(santa_loader.overlay);
|
||||
});
|
Loading…
Reference in a new issue