1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-09-20 01:00:53 +00:00
Funkin/source/funkin/ui/StickerSubState.hx

163 lines
4.2 KiB
Haxe
Raw Normal View History

2023-04-05 02:24:00 +00:00
package funkin.ui;
2023-04-05 02:38:45 +00:00
import flixel.FlxSprite;
2023-04-05 02:24:00 +00:00
import haxe.Json;
2023-04-05 04:56:02 +00:00
import lime.utils.Assets;
2023-04-05 21:35:19 +00:00
// import flxtyped group
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.util.FlxTimer;
import flixel.FlxG;
import flixel.util.FlxSort;
2023-04-05 02:24:00 +00:00
class StickerSubState extends MusicBeatSubstate
{
2023-04-05 21:35:19 +00:00
var grpStickers:FlxTypedGroup<StickerSprite>;
2023-04-05 02:24:00 +00:00
public function new():Void
{
super();
2023-04-05 21:35:19 +00:00
grpStickers = new FlxTypedGroup<StickerSprite>();
add(grpStickers);
2023-04-05 04:56:02 +00:00
var stickerInfo:StickerInfo = new StickerInfo('stickers-set-1');
2023-04-05 02:38:45 +00:00
for (stickerSets in stickerInfo.getPack("all"))
{
2023-04-05 04:56:02 +00:00
for (stickerShit in stickerInfo.getStickers(stickerSets))
{
2023-04-05 21:35:19 +00:00
// for loop jus to repeat it easy easy easy
for (i in 0...FlxG.random.int(1, 4))
{
var sticky:StickerSprite = new StickerSprite(0, 0, stickerInfo.name, stickerShit);
sticky.x -= sticky.width / 2;
sticky.y -= sticky.height / 2;
sticky.visible = false;
sticky.angle = FlxG.random.int(-60, 70);
// sticky.flipX = FlxG.random.bool();
grpStickers.add(sticky);
sticky.timing = FlxG.random.float(0, 1.5);
new FlxTimer().start(sticky.timing, function(_) {
sticky.visible = true;
new FlxTimer().start((1 / 24) * 2, _ -> {
sticky.scale.x = sticky.scale.y = FlxG.random.float(0.97, 1.02);
// sticky.angle *= FlxG.random.float(0, 0.05);
});
});
}
2023-04-05 04:56:02 +00:00
}
2023-04-05 02:38:45 +00:00
}
2023-04-05 21:35:19 +00:00
FlxG.random.shuffle(grpStickers.members);
for (ind => sticker in grpStickers.members)
{
sticker.x += (ind % 7) * sticker.width;
sticker.y += Math.floor(ind / 6) * sticker.height;
}
grpStickers.sort((ord, a, b) -> {
return FlxSort.byValues(ord, a.timing, b.timing);
});
2023-04-05 02:38:45 +00:00
}
}
class StickerSprite extends FlxSprite
{
2023-04-05 21:35:19 +00:00
public var timing:Float = 0;
2023-04-05 02:38:45 +00:00
public function new(x:Float, y:Float, stickerSet:String, stickerName:String):Void
{
2023-04-05 04:56:02 +00:00
super(x, y, Paths.image('transitionSwag/' + stickerSet + '/' + stickerName));
2023-04-05 21:35:19 +00:00
height = 100;
width = 190;
antialiasing = true;
2023-04-05 02:24:00 +00:00
}
}
class StickerInfo
{
public var name:String;
public var artist:String;
2023-04-05 02:38:45 +00:00
public var stickers:Map<String, Array<String>>;
public var stickerPacks:Map<String, Array<String>>;
2023-04-05 02:24:00 +00:00
public function new(stickerSet:String):Void
{
2023-04-05 04:56:02 +00:00
var path = Paths.file('images/transitionSwag/' + stickerSet + '/stickers.json');
var json = Json.parse(Assets.getText(path));
trace(json);
// doin this dipshit nonsense cuz i dunno how to deal with casting a json object with
// a dash in its name (sticker-packs)
var jsonInfo:StickerShit = cast json;
2023-04-05 02:38:45 +00:00
this.name = jsonInfo.name;
this.artist = jsonInfo.artist;
2023-04-05 04:56:02 +00:00
stickerPacks = new Map<String, Array<String>>();
for (field in Reflect.fields(json.stickerPacks))
{
var stickerFunny = json.stickerPacks;
var stickerStuff = Reflect.field(stickerFunny, field);
stickerPacks.set(field, cast stickerStuff);
trace(field);
trace(Reflect.field(stickerFunny, field));
}
trace(stickerPacks);
// creates a similar for loop as before but for the stickers
stickers = new Map<String, Array<String>>();
for (field in Reflect.fields(json.stickers))
{
var stickerFunny = json.stickers;
var stickerStuff = Reflect.field(stickerFunny, field);
stickers.set(field, cast stickerStuff);
trace(field);
trace(Reflect.field(stickerFunny, field));
}
trace(stickers);
// this.stickerPacks = cast jsonInfo.stickerPacks;
// this.stickers = cast jsonInfo.stickers;
// trace(stickerPacks);
// trace(stickers);
// for (packs in stickers)
// {
// // this.stickers.set(packs, Reflect.field(json, "sticker-packs"));
// trace(packs);
// }
}
public function getStickers(stickerName:String):Array<String>
{
return this.stickers[stickerName];
2023-04-05 02:24:00 +00:00
}
2023-04-05 02:38:45 +00:00
public function getPack(packName:String):Array<String>
{
return this.stickerPacks[packName];
}
2023-04-05 02:24:00 +00:00
}
2023-04-05 02:38:45 +00:00
// somethin damn cute just for the json to cast to!
typedef StickerShit =
2023-04-05 02:24:00 +00:00
{
2023-04-05 02:38:45 +00:00
name:String,
artist:String,
stickers:Map<String, Array<String>>,
stickerPacks:Map<String, Array<String>>
2023-04-05 02:24:00 +00:00
}