2023-05-17 02:09:53 +00:00
|
|
|
package funkin.ui.story;
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
import funkin.play.stage.Bopper;
|
|
|
|
import funkin.util.assets.FlxAnimationUtil;
|
|
|
|
import funkin.data.level.LevelData;
|
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
class LevelProp extends Bopper
|
|
|
|
{
|
|
|
|
public function new(danceEvery:Int)
|
|
|
|
{
|
|
|
|
super(danceEvery);
|
|
|
|
}
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
public function playConfirm():Void
|
|
|
|
{
|
|
|
|
playAnimation('confirm', true, true);
|
|
|
|
}
|
|
|
|
|
2023-06-10 06:56:03 +00:00
|
|
|
public static function build(propData:Null<LevelPropData>):Null<LevelProp>
|
2023-05-17 02:09:53 +00:00
|
|
|
{
|
2023-06-10 06:56:03 +00:00
|
|
|
if (propData == null) return null;
|
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
var isAnimated:Bool = propData.animations.length > 0;
|
|
|
|
var prop:LevelProp = new LevelProp(propData.danceEvery);
|
|
|
|
|
|
|
|
if (isAnimated)
|
|
|
|
{
|
|
|
|
// Initalize sprite frames.
|
|
|
|
// Sparrow atlas only LEL.
|
|
|
|
prop.frames = Paths.getSparrowAtlas(propData.assetPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Initalize static sprite.
|
|
|
|
prop.loadGraphic(Paths.image(propData.assetPath));
|
|
|
|
|
|
|
|
// Disables calls to update() for a performance boost.
|
|
|
|
prop.active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop.frames == null || prop.frames.numFrames == 0)
|
|
|
|
{
|
|
|
|
trace('ERROR: Could not build texture for level prop (${propData.assetPath}).');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
var scale:Float = propData.scale * (propData.isPixel ? 6 : 1);
|
|
|
|
prop.scale.set(scale, scale);
|
2023-05-17 02:09:53 +00:00
|
|
|
prop.antialiasing = !propData.isPixel;
|
|
|
|
prop.alpha = propData.alpha;
|
|
|
|
prop.x = propData.offsets[0];
|
|
|
|
prop.y = propData.offsets[1];
|
|
|
|
|
|
|
|
FlxAnimationUtil.addAtlasAnimations(prop, propData.animations);
|
|
|
|
for (propAnim in propData.animations)
|
|
|
|
{
|
|
|
|
prop.setAnimationOffsets(propAnim.name, propAnim.offsets[0], propAnim.offsets[1]);
|
|
|
|
}
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
prop.dance();
|
|
|
|
prop.animation.paused = true;
|
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
}
|