|
@@ -9,7 +9,7 @@
|
|
// The idea is to have the base animation look "ok" without anything going on, but to also have things going on just fit mathmagically.
|
|
// The idea is to have the base animation look "ok" without anything going on, but to also have things going on just fit mathmagically.
|
|
// Support to animations that contain the WHOLE of the events should be possible as to make it so we can make special animations for special circumstances. e.g. only encounter with the ogre
|
|
// Support to animations that contain the WHOLE of the events should be possible as to make it so we can make special animations for special circumstances. e.g. only encounter with the ogre
|
|
enum AnimationLayerLevel {
|
|
enum AnimationLayerLevel {
|
|
- BACKGROUND = 0,
|
|
|
|
|
|
+ BACKGROUND = 1,
|
|
MIDDLE = 150,
|
|
MIDDLE = 150,
|
|
FRONT = 300
|
|
FRONT = 300
|
|
}
|
|
}
|
|
@@ -21,6 +21,7 @@ interface AnimationInstruction {
|
|
|
|
|
|
module Elements.AnimationHandler {
|
|
module Elements.AnimationHandler {
|
|
var container = document.getElementById("sceneAnimation");
|
|
var container = document.getElementById("sceneAnimation");
|
|
|
|
+ var background = document.createElement("a");
|
|
var stop = true;
|
|
var stop = true;
|
|
export var spriteSize = 200;
|
|
export var spriteSize = 200;
|
|
export var animations : Array<AnimationLayer> = [];
|
|
export var animations : Array<AnimationLayer> = [];
|
|
@@ -42,20 +43,30 @@ module Elements.AnimationHandler {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- export function addAnimation (name : string, layer = 0) {
|
|
|
|
|
|
+ export function addAnimation (name : string, layer = 1) {
|
|
let newAnim = new AnimationLayer(name, layer);
|
|
let newAnim = new AnimationLayer(name, layer);
|
|
container.appendChild(newAnim.getElement());
|
|
container.appendChild(newAnim.getElement());
|
|
animations.push(newAnim);
|
|
animations.push(newAnim);
|
|
return newAnim;
|
|
return newAnim;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ export function setBackground (name : string) {
|
|
|
|
+ background.className = "";
|
|
|
|
+
|
|
|
|
+ background.classList.add("bg-" + name);
|
|
|
|
+ background.classList.add("sceneAnimation");
|
|
|
|
+ background.style.zIndex = "0";
|
|
|
|
+
|
|
|
|
+ container.appendChild(background);
|
|
|
|
+ }
|
|
|
|
+
|
|
export function beginAnimate (targetAnimationSpeed? : number) {
|
|
export function beginAnimate (targetAnimationSpeed? : number) {
|
|
animationSpeed = targetAnimationSpeed == undefined ? 1500 : targetAnimationSpeed;
|
|
animationSpeed = targetAnimationSpeed == undefined ? 1500 : targetAnimationSpeed;
|
|
lastTime = (new Date()).getTime();
|
|
lastTime = (new Date()).getTime();
|
|
percentage = 0;
|
|
percentage = 0;
|
|
- fixVerticalPosition();
|
|
|
|
-
|
|
|
|
container.style.display = "";
|
|
container.style.display = "";
|
|
|
|
+
|
|
|
|
+ fixVerticalPosition();
|
|
stop = false;
|
|
stop = false;
|
|
animate();
|
|
animate();
|
|
}
|
|
}
|
|
@@ -76,7 +87,7 @@ module Elements.AnimationHandler {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- function fixVerticalPosition () {
|
|
|
|
|
|
+ export function fixVerticalPosition () {
|
|
spriteSize = getSize(true);
|
|
spriteSize = getSize(true);
|
|
//container.style.marginBottom = (availHeight - 200) + "px";
|
|
//container.style.marginBottom = (availHeight - 200) + "px";
|
|
container.style.width = spriteSize + "px";
|
|
container.style.width = spriteSize + "px";
|
|
@@ -85,7 +96,18 @@ module Elements.AnimationHandler {
|
|
|
|
|
|
animations.forEach((anim) => {
|
|
animations.forEach((anim) => {
|
|
anim.updateSize();
|
|
anim.updateSize();
|
|
- })
|
|
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (background.parentElement == container) {
|
|
|
|
+ background.style.transform = "";
|
|
|
|
+ let height = background.offsetHeight;
|
|
|
|
+ let width = background.offsetWidth;
|
|
|
|
+ if (height != 0 && width != 0) {
|
|
|
|
+ background.style.transform = "scale(" + (spriteSize / height) + ")";
|
|
|
|
+ background.style.marginLeft = (-width / 2) + "px";
|
|
|
|
+ background.style.marginTop = (-height / 2) + "px";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
export function getSize (fixMin = true) {
|
|
export function getSize (fixMin = true) {
|
|
@@ -103,4 +125,6 @@ module Elements.AnimationHandler {
|
|
getSize(false);
|
|
getSize(false);
|
|
}
|
|
}
|
|
stopAnimate();
|
|
stopAnimate();
|
|
-}
|
|
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+window.addEventListener("resize", () => { Elements.AnimationHandler.fixVerticalPosition(); });
|