2019-04-19 01:15:05 +00:00
|
|
|
function main() {
|
|
|
|
console.log("%s initialized!", Self.Doodad.Title);
|
|
|
|
|
2019-05-07 05:57:32 +00:00
|
|
|
Self.AddAnimation("open", 100, [0, 1, 2, 3]);
|
|
|
|
Self.AddAnimation("close", 100, [3, 2, 1, 0]);
|
2019-05-05 23:32:30 +00:00
|
|
|
var animating = false;
|
2019-05-07 05:57:32 +00:00
|
|
|
var opened = false;
|
2019-04-19 01:15:05 +00:00
|
|
|
|
2019-06-24 00:30:12 +00:00
|
|
|
Self.SetHitbox(16, 0, 32, 64);
|
|
|
|
|
|
|
|
Message.Subscribe("power", function(powered) {
|
|
|
|
console.log("%s got power=%+v", Self.Doodad.Title, powered);
|
|
|
|
|
|
|
|
if (powered) {
|
|
|
|
if (animating || opened) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-19 01:15:05 +00:00
|
|
|
|
2019-05-07 05:57:32 +00:00
|
|
|
animating = true;
|
|
|
|
Self.PlayAnimation("open", function() {
|
|
|
|
opened = true;
|
|
|
|
animating = false;
|
|
|
|
});
|
2019-06-24 00:30:12 +00:00
|
|
|
} else {
|
|
|
|
animating = true;
|
2019-05-07 05:57:32 +00:00
|
|
|
Self.PlayAnimation("close", function() {
|
|
|
|
opened = false;
|
2019-06-24 00:30:12 +00:00
|
|
|
animating = false;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Events.OnCollide(function(e) {
|
|
|
|
if (e.InHitbox) {
|
|
|
|
if (!opened) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-07 05:57:32 +00:00
|
|
|
}
|
2019-06-24 00:30:12 +00:00
|
|
|
});
|
|
|
|
Events.OnLeave(function() {
|
|
|
|
// if (opened) {
|
|
|
|
// Self.PlayAnimation("close", function() {
|
|
|
|
// opened = false;
|
|
|
|
// });
|
|
|
|
// }
|
2019-05-07 05:57:32 +00:00
|
|
|
})
|
2019-04-19 01:15:05 +00:00
|
|
|
}
|