Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
fixed fucked pico speaker notes
improved cam offsets for flipped chars
some small quad rendering optimizations
  • Loading branch information
MaybeMaru committed Nov 6, 2024
1 parent 4b67d7b commit f8d18e7
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 227 deletions.
25 changes: 15 additions & 10 deletions assets/preload/data/characters/pico-speaker.hx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import funkin.util.song.Song;

var speaker;
var picoNotes_ = [];
var hasLayer = false;
var layer;

var picoIndex = 0;
var picoNotes = [];

function createChar() {
ScriptChar.x += 120;
speaker = new FlxSpriteExt(ScriptChar.x - 190, ScriptChar.y + 305.5);
Expand All @@ -21,8 +23,8 @@ function createChar() {
}

function createPost() {
if (Paths.exists(Paths.chart(PlayState.SONG.song, 'picospeaker'), "TEXT")) {
picoNotes_ = Song.getSongNotes('picospeaker', PlayState.SONG.song);
if (Song.existsChart('picospeaker', PlayState.SONG.song)) {
picoNotes = Song.getSongNotes('picospeaker', PlayState.SONG.song);
initTankmen();
}
}
Expand All @@ -33,9 +35,12 @@ function beatHit()
function startTimer()
speaker.playAnim('speakers', true);

function stepHit() {
if (picoNotes_.length <= 0) return;
var topNote = picoNotes_[0];
function stepHit()
{
if (picoIndex >= picoNotes.length)
return;

var topNote = picoNotes[picoIndex];
if(Conductor.songPosition > topNote[0]) {
var shootAnim = 1;
if (topNote[1] >= 2) shootAnim = 3;
Expand All @@ -44,7 +49,7 @@ function stepHit() {
ScriptChar.playAnim('shoot' + shootAnim, true);
ScriptChar.specialAnim = true;
ScriptChar.forceDance = false;
picoNotes_.shift();
picoIndex++;
}
}

Expand All @@ -58,12 +63,12 @@ function initTankmen() {
if (hasLayer) {
layer = getLayer("tankmenRun");

for (i in 0...picoNotes_.length) {
for (i in 0...picoNotes.length) {
if (FlxG.random.bool(16)) {
var spritePath = 'stress/tankmenShot' + (getPref('naughty') ? '' : '-censor');

var tankman = new FlxSpriteExt(500, 180 + FlxG.random.int(50, 100)).loadImage(spritePath);
tankman.flipX = picoNotes_[i][1] > 2;
tankman.flipX = picoNotes[i][1] > 2;
tankman.scrollFactor.set(0.9, 0.9);
tankman.setScale(0.8);

Expand All @@ -72,7 +77,7 @@ function initTankmen() {
tankman.playAnim('run', true, false, FlxG.random.int(0, 10));

var tankClass = tankman._dynamic;
tankClass.strumTime = picoNotes_[i][0];
tankClass.strumTime = picoNotes[i][0];
tankClass.endingOffset = FlxG.random.float(50, 200);
tankClass.tankSpeed = FlxG.random.float(0.6, 1);
layer.add(tankman);
Expand Down
12 changes: 8 additions & 4 deletions source/funkin/objects/Character.hx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ class Character extends FlxSpriteExt

public function flipCharOffsets():Void {
flippedOffsets = true;
camOffsets.x = -camOffsets.x;
if (!debugMode) { // Switch anims
switchAnim('danceLeft', 'danceRight');
for (i in animOffsets.keys()) {
Expand Down Expand Up @@ -231,10 +230,15 @@ class Character extends FlxSpriteExt
__superUpdate(elapsed);
}

public function prepareCamPoint(?point:Null<FlxPoint>, ?bounds:Array<Float>) {
public function prepareCamPoint(?point:Null<FlxPoint>, ?bounds:Array<Float>)
{
point = getMidpoint(point);
point.subtract(camOffsets.x, camOffsets.y);
point.subtract(flippedOffsets ? -stageCamOffsets.x : stageCamOffsets.x, stageCamOffsets.y);

point.subtract(camOffsets.x * (flippedOffsets ? -1 : 1), camOffsets.y);
point.subtract(stageCamOffsets.x, stageCamOffsets.y);

if (flippedOffsets)
point.add((width * (isPlayerJson ? 0.25 : -(0.25 / 2))), 0);

if (bounds != null) {
point.x = FlxMath.bound(point.x, bounds[0], bounds[2]);
Expand Down
34 changes: 28 additions & 6 deletions source/funkin/objects/RatingGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,37 @@ package funkin.objects;

class RatingGroup extends TypedSpriteGroup<RemoveRating>
{
public var targetSpr:FlxObject = null;
public var targetSpr(default, set):FlxObject;
public var _offset:FlxPoint;

public function new(?targetSpr:FlxSprite):Void {
function set_targetSpr(obj:FlxObject)
{
if (obj != null)
{
if (obj is FlxSprite)
{
if (obj is Character)
{
var char = cast(obj, Character);
char.prepareCamPoint(_offset).subtract(char.x, char.y);
}
else
{
var spr = cast(obj, FlxSprite);
_offset.set(spr.frameWidth * spr.scale.x * 0.5, spr.frameHeight * spr.scale.y * 0.5);
}
}
}

return targetSpr = obj;
}

public function new(?targetSpr:FlxObject):Void
{
super();
this.targetSpr = targetSpr;

_offset = FlxPoint.get();
if (targetSpr is FlxSprite)
_offset.set(targetSpr.frameWidth * targetSpr.scale.x, targetSpr.frameHeight * targetSpr.scale.y);
this.targetSpr = targetSpr;

// Cache default ratings
add(new JudgeRating());
Expand All @@ -31,7 +53,7 @@ class RatingGroup extends TypedSpriteGroup<RemoveRating>
override public function update(elapsed:Float):Void {
super.update(elapsed);
if (targetSpr != null) {
setPosition(targetSpr.x - _offset.x * 0.5, targetSpr.y - _offset.y * 0.5);
setPosition(targetSpr.x - _offset.x, targetSpr.y - _offset.y);
}
}

Expand Down
12 changes: 9 additions & 3 deletions source/funkin/util/Paths.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package funkin.util;

import moonchart.formats.fnf.FNFMaru;
import openfl.media.Sound;
import haxe.io.Path;
import flixel.graphics.frames.FlxAtlasFrames;
Expand Down Expand Up @@ -174,7 +175,7 @@ class Paths
**/

inline static public function songAudioAssetPath(song:String, asset:String, ?globalAsset:Bool):String {
var songKey = Song.formatSongFolder(song) + '/audio/$asset';
var songKey = FNFMaru.formatTitle(song) + '/audio/$asset';

var diffPath = getPath('$songKey-${PlayState.curDifficulty}.$SOUND_EXT', MUSIC, 'songs', globalAsset);
if (exists(diffPath, MUSIC)) return diffPath;
Expand All @@ -200,7 +201,12 @@ class Paths
return AssetManager.cacheSoundPath(instPath, false, null, stream);
}

inline static public function chart(song:String, diff:String, ext:String = 'json'):String {
inline static public function chartFolder(title:String, ?allowMods:Bool):String
{
return getPath(title + "/charts", BINARY, "songs", false, allowMods);
}

/*inline static public function chart(song:String, diff:String, ext:String = 'json'):String {
if (!ext.startsWith('/'))
ext = '.$ext';
Expand All @@ -209,7 +215,7 @@ class Paths
inline static public function songMeta(song:String) {
return getPath(Song.formatSongFolder(song) + '/charts/songMeta.json', TEXT, 'songs');
}
}*/

/*
* GRAPHICS
Expand Down
8 changes: 4 additions & 4 deletions source/funkin/util/song/Highscore.hx
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class Highscore {
}

public static final ratingMap:Map<String, Rating> = [
"sick" => new Rating(350, 1, 0),
"good" => new Rating(200, 0.8, 0),
"bad" => new Rating(100, 0.5, 0.06),
"shit" => new Rating(50, 0.25, 0.1)
"sick" => new Rating(350, 1, 0),
"good" => new Rating(200, 0.8, 0),
"bad" => new Rating(100, 0.5, 0.06),
"shit" => new Rating(50, 0.25, 0.1)
];
}

Expand Down
121 changes: 69 additions & 52 deletions source/funkin/util/song/Song.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package funkin.util.song;

import moonchart.backend.Optimizer;
import haxe.Json;
import flixel.util.FlxSort;

import moonchart.backend.FormatDetector;
Expand All @@ -16,59 +15,81 @@ typedef EventJson = FNFMaruEvent;

class Song
{
public static function loadFromFile(diff:String, folder:String):SongJson
public static function existsChart(diff:String, title:String):Bool
{
folder = formatSongFolder(folder);
title = FNFMaru.formatTitle(title);

var formats:Array<String> = [];

@:privateAccess
for (format => data in FormatDetector.formatMap)
try
{
if (formats.indexOf(data.extension) == -1)
formats.push(data.extension);
FormatDetector.findInFolder(Paths.chartFolder(title), title, diff);
return true;
}

formats.fastForEach((format, i) ->
catch (e)
{
var chartPath:String = Paths.chart(folder, diff, format);
return false;
}

if (Paths.exists(chartPath, TEXT)) {
return false;
}

var format = FormatDetector.findFormat([chartPath]);
var maru:FNFMaru = new FNFMaru();
public static function loadFromFile(diff:String, title:String):SongJson
{
title = FNFMaru.formatTitle(title);

var folder:String = "";
var foundFormat:DetectedFormatFiles = null;

switch (format)
try // Try finding in the current mod folder
{
folder = Paths.chartFolder(title, true);
foundFormat = FormatDetector.findInFolder(folder, title, diff);
}
catch (e)
{
try // If that failed then force it to be on assets
{
folder = Paths.chartFolder(title, false);
foundFormat = FormatDetector.findInFolder(folder, title, diff);
}
catch (e)
{
if (title == "tutorial" && diff == "hard") // Couldnt even find tutorial
{
case FNF_MARU:
maru.fromFile(chartPath);
case _:
var chart = FormatDetector.createFormatInstance(format);
chart.fromFile(chartPath);
maru.fromFormat(chart);
throw 'Failed loading chart: ' + Std.string(e);
return null;
}
else // Fail safe to tutorial
{
trace('$folder$title-$diff CHART NOT FOUND');
return loadFromFile('hard', 'tutorial');
}

trace("LOADED CHART FROM FORMAT: " + format);
return maru.data.song;
}
});

// Couldnt even find tutorial safe fail
if (folder == "tutorial") if (diff == "hard")
}

var format = foundFormat.format;
var files = foundFormat.files;
var maru:FNFMaru = new FNFMaru();

switch (format)
{
throw 'Failed loading chart.';
return null;
case FNF_MARU:
maru.fromFile(files[0], files[1]);
case _:
var chart = FormatDetector.createFormatInstance(format);
chart.fromFile(files[0], files[1]);
maru.fromFormat(chart);
}

trace('$folder-$diff CHART NOT FOUND');
return loadFromFile('hard', 'tutorial');
}

public static function getSongMeta(song:String):Null<SongMeta> {
var meta = CoolUtil.getFileContent(Paths.songMeta(song));
return meta.length > 0 ? cast Json.parse(meta) : null;
trace('\nLOADED CHART SUCCESSFULLY.\nFROM FORMAT: $format\nFROM FILES: $files');
return maru.data.song;
}

//public static function getSongMeta(song:String):Null<SongMeta> {
//var meta = CoolUtil.getFileContent(Paths.songMeta(song));
//return meta.length > 0 ? cast Json.parse(meta) : null;
// return null;
//}

public static function getSectionTime(song:SongJson, section:Int = 0):Float {
var crochet:Float = (60000 / song.bpm);
var time:Float = 0;
Expand Down Expand Up @@ -166,7 +187,7 @@ class Song
final notes:Array<NoteJson> = [];

loadFromFile(diff, song).notes.fastForEach((s, i) -> {
if (s.sectionNotes != null) {
if (s.sectionNotes != null) if (s.sectionNotes.length > 0) {
s.sectionNotes.fastForEach((n, i) -> {
notes.push(n);
});
Expand All @@ -177,24 +198,20 @@ class Song
return notes;
}

private static inline function sortNotes(note1:NoteJson, note2:NoteJson):Int {
private static inline function sortNotes(note1:NoteJson, note2:NoteJson):Int
{
return FlxSort.byValues(FlxSort.ASCENDING, note1.time, note2.time);
}

public static function formatSongFolder(songName:String):String {
var folder:String = "";
songName.split("").fastForEach((char, i) -> {
switch (char) {
case "." | "?" | "*" | '"' | "'":
case " " | ":": folder = (folder + "-");
default: folder = (folder + char.toLowerCase());
}
});
return folder;
public static inline function formatSongFolder(title:String):String
{
return FNFMaru.formatTitle(title);
}

inline public static function getDefaultSong():SongJson {
return {
inline public static function getDefaultSong():SongJson
{
return
{
song: 'Test',
notes: [],
bpm: 150,
Expand Down
Loading

0 comments on commit f8d18e7

Please sign in to comment.