2023-05-16 22:09:53 -04:00
|
|
|
package funkin.ui.story;
|
|
|
|
|
2023-05-17 16:42:58 -04:00
|
|
|
import funkin.play.stage.Bopper;
|
|
|
|
import funkin.util.assets.FlxAnimationUtil;
|
|
|
|
import funkin.data.level.LevelData;
|
|
|
|
|
2023-05-16 22:09:53 -04:00
|
|
|
class LevelProp extends Bopper
|
|
|
|
{
|
2024-01-15 23:43:05 -05:00
|
|
|
public var propData(default, set):Null<LevelPropData> = null;
|
|
|
|
|
|
|
|
function set_propData(value:LevelPropData):LevelPropData
|
|
|
|
{
|
|
|
|
// Only reset the prop if the asset path has changed.
|
2024-03-05 00:22:29 -05:00
|
|
|
if (propData == null || value?.assetPath != propData?.assetPath)
|
2024-01-15 23:43:05 -05:00
|
|
|
{
|
|
|
|
this.visible = (value != null);
|
|
|
|
this.propData = value;
|
2024-03-05 00:22:29 -05:00
|
|
|
danceEvery = this.propData?.danceEvery ?? 0;
|
2024-01-15 23:43:05 -05:00
|
|
|
applyData();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.propData;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function new(propData:LevelPropData)
|
2023-05-16 22:09:53 -04:00
|
|
|
{
|
2024-01-15 23:43:05 -05:00
|
|
|
super(propData.danceEvery);
|
|
|
|
this.propData = propData;
|
2023-05-16 22:09:53 -04:00
|
|
|
}
|
|
|
|
|
2023-05-17 16:42:58 -04:00
|
|
|
public function playConfirm():Void
|
|
|
|
{
|
|
|
|
playAnimation('confirm', true, true);
|
|
|
|
}
|
|
|
|
|
2024-01-15 23:43:05 -05:00
|
|
|
function applyData():Void
|
2023-05-16 22:09:53 -04:00
|
|
|
{
|
2024-03-05 00:22:29 -05:00
|
|
|
if (propData == null)
|
|
|
|
{
|
|
|
|
this.visible = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.visible = true;
|
|
|
|
}
|
|
|
|
|
2024-03-08 21:33:06 -05:00
|
|
|
// Reset animation state.
|
|
|
|
this.shouldAlternate = null;
|
|
|
|
|
2023-05-16 22:09:53 -04:00
|
|
|
var isAnimated:Bool = propData.animations.length > 0;
|
|
|
|
if (isAnimated)
|
|
|
|
{
|
|
|
|
// Initalize sprite frames.
|
|
|
|
// Sparrow atlas only LEL.
|
2024-01-15 23:43:05 -05:00
|
|
|
this.frames = Paths.getSparrowAtlas(propData.assetPath);
|
2023-05-16 22:09:53 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Initalize static sprite.
|
2024-01-15 23:43:05 -05:00
|
|
|
this.loadGraphic(Paths.image(propData.assetPath));
|
2023-05-16 22:09:53 -04:00
|
|
|
|
|
|
|
// Disables calls to update() for a performance boost.
|
2024-01-15 23:43:05 -05:00
|
|
|
this.active = false;
|
2023-05-16 22:09:53 -04:00
|
|
|
}
|
|
|
|
|
2024-01-15 23:43:05 -05:00
|
|
|
if (this.frames == null || this.frames.numFrames == 0)
|
2023-05-16 22:09:53 -04:00
|
|
|
{
|
|
|
|
trace('ERROR: Could not build texture for level prop (${propData.assetPath}).');
|
2024-01-15 23:43:05 -05:00
|
|
|
return;
|
2023-05-16 22:09:53 -04:00
|
|
|
}
|
|
|
|
|
2023-05-17 16:42:58 -04:00
|
|
|
var scale:Float = propData.scale * (propData.isPixel ? 6 : 1);
|
2024-01-15 23:43:05 -05:00
|
|
|
this.scale.set(scale, scale);
|
|
|
|
this.antialiasing = !propData.isPixel;
|
|
|
|
this.alpha = propData.alpha;
|
|
|
|
this.x = propData.offsets[0];
|
|
|
|
this.y = propData.offsets[1];
|
2023-05-16 22:09:53 -04:00
|
|
|
|
2024-01-15 23:43:05 -05:00
|
|
|
FlxAnimationUtil.addAtlasAnimations(this, propData.animations);
|
2023-05-16 22:09:53 -04:00
|
|
|
for (propAnim in propData.animations)
|
|
|
|
{
|
2024-01-15 23:43:05 -05:00
|
|
|
this.setAnimationOffsets(propAnim.name, propAnim.offsets[0], propAnim.offsets[1]);
|
2023-05-16 22:09:53 -04:00
|
|
|
}
|
|
|
|
|
2024-01-15 23:43:05 -05:00
|
|
|
this.dance();
|
|
|
|
this.animation.paused = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function build(propData:Null<LevelPropData>):Null<LevelProp>
|
|
|
|
{
|
|
|
|
if (propData == null) return null;
|
2023-05-17 16:42:58 -04:00
|
|
|
|
2024-01-15 23:43:05 -05:00
|
|
|
return new LevelProp(propData);
|
2023-05-16 22:09:53 -04:00
|
|
|
}
|
|
|
|
}
|