Skip to content

Commit

Permalink
disable lod for pixel dialogue
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Apr 24, 2024
1 parent 8d3783a commit d18a1d2
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 101 deletions.
8 changes: 4 additions & 4 deletions assets/preload/data/events/changeStage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function changeStage(stageName)
State.stage.active = false;

if (State.stage.script != null)
State.stage.script.callback("hideStage");
State.stage.script.safeCall("hideStage");

stage.visible = true;
stage.active = true;
Expand All @@ -31,7 +31,7 @@ function changeStage(stageName)
repositionChar(State.gf, 400, 360);

if (stage.script != null)
stage.script.callback("changeStage");
stage.script.safeCall("changeStage");

State.defaultCamZoom = stage.data.zoom;
State.stageData = stage.data;
Expand Down Expand Up @@ -85,8 +85,8 @@ function createPost() {

if (stageScript != null) {
stageScript.set("ScriptStage", stageObject);
stageScript.callback("create");
stageScript.callback("createPost");
stageScript.safeCall("create");
stageScript.safeCall("createPost");
}

cachedStages.set(stage, stageObject);
Expand Down
16 changes: 11 additions & 5 deletions assets/preload/data/stages/school.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ function createPost()
setSpriteShader(trees, 'senpaiTrees');

for (i in 0...4) {
var freak = new FunkinSprite(freaksPath, [i * 500, 425 + switch (i) {
case 0: 25;
case 3: 25;
}], [0.95, 0.95]);
var freak = new FunkinSprite("", [i * 500, 425], [0.95, 0.95]);

switch (i) {
case 0: freak.y += 25;
case 3: freak.y += 25;
}

freak.loadImage(freaksPath, false, null, null, 0);
freak.setScale(6, false);

freak.addAnim('danceLeft', freaksAnim, 24, false, CoolUtil.numberArray(14));
freak.addAnim('danceRight', freaksAnim, 24, false, CoolUtil.numberArray(30,15));
freak.setScale(6, false);

addSpr(freak, "freak-" + i, "freaks");
freaks.push(freak);
}
Expand Down
3 changes: 2 additions & 1 deletion source/funkin/Preferences.hx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class Preferences
#if !(hl || web) AssetManager.gpuTextures = getPref('gpu-textures'); #else {} #end

public static inline function updateAntialiasing():Void {
var anti:Bool = FlxSprite.defaultAntialiasing = getPref('antialiasing');
var anti:Bool = getPref('antialiasing');
FlxSprite.defaultAntialiasing = anti;
for (key => data in NoteUtil.skinSpriteMap) {
data.baseSprite.antialiasing = data.skinJson.antialiasing ? anti : false;
}
Expand Down
6 changes: 3 additions & 3 deletions source/funkin/graphics/FlxRepeatSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import flixel.graphics.frames.FlxFrame;

using flixel.util.FlxColorTransformUtil;

enum abstract RepeatDrawStyle(Int) from Int to Int {
var TOP_BOTTOM = 0;
var BOTTOM_TOP = 1;
enum abstract RepeatDrawStyle(Bool) from Bool {
var TOP_BOTTOM = true;
var BOTTOM_TOP = false;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions source/funkin/graphics/FlxSkewRepeatSprite.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package funkin.graphics;

import flixel.graphics.tile.FlxDrawQuadsItem;
import flixel.math.FlxMatrix;
import flixel.graphics.frames.FlxFrame;
import openfl.display.BitmapData;

/*
TODO:
Expand Down
40 changes: 24 additions & 16 deletions source/funkin/graphics/FunkinSprite.hx
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
package funkin.graphics;

class FunkinSprite extends FlxSpriteExt {
// Simple FlxSpriteExt wrapper class mainly for use in hscript
class FunkinSprite extends FlxSpriteExt
{
public var jsonData:SpriteJson;
public var tag:String = "";
public var animated:Bool = true;
public var danced:Bool = false;

public function new(?image:FlxGraphicAsset, ?coords:Array<Float>, ?scrolls:Array<Float>, useJson:Bool = false):Void {
super();
coords = coords ?? [0,0];
scrolls = scrolls ?? [1,1];
x = coords[0]; y = coords[1];
scrollFactor.set(scrolls[0], scrolls[1]);

coords = null;
scrolls = null;
if (coords == null) setPosition(0,0);
else setPosition(coords[0], coords[1]);

if (scrolls == null) scrollFactor.set(1,1);
else scrollFactor.set(scrolls[0], scrolls[1]);

if (image != null) {
if (image is String) {
if (image != null)
{
if (image is String)
{
final path:String = cast(image, String);
if (path.length > 0) {
if (path.length > 0)
{
loadImage(path);
animated = packer != IMAGE;

final jsonPath:String = Paths.getPath('images/$path-data.json', TEXT, null);
if (useJson && Paths.exists(jsonPath, TEXT)) loadSpriteJson(jsonPath, '');
else {
antialiasing = SkinUtil.curSkinData.antialiasing ? Preferences.getPref('antialiasing') : false;
if (useJson) {
var jsonPath:String = Paths.getPath('images/$path-data.json', TEXT, null);
if (Paths.exists(jsonPath, TEXT)) {
loadSpriteJson(jsonPath, "");
return;
}
}
}
}
else {
else
{
loadGraphic(image);
antialiasing = SkinUtil.curSkinData.antialiasing ? Preferences.getPref('antialiasing') : false;
}
}

antialiasing = SkinUtil.curSkinData.antialiasing ? FlxSprite.defaultAntialiasing : false;
}

public function dance(forced:Bool = false):Void {
Expand Down
25 changes: 10 additions & 15 deletions source/funkin/graphics/SmartSprite.hx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package funkin.graphics;

enum abstract RenderMode(Int) from Int to Int {
var QUAD = 0;
var REPEAT = 1;
// Makin this a bool cause its easier to store
// If i add more render modes will turn it back into integers lol
enum abstract RenderMode(Bool) from Bool {
var QUAD = true;
var REPEAT = false;
}

// Internal class to switch between render modes in BasicNote

abstract class SmartSprite extends FlxSkewRepeatSprite
{
public var renderMode:RenderMode = QUAD;

// For hscript mainly lmao
public function setRenderMode(value:String) {
renderMode = switch (value.toLowerCase().trim()) {
case "quad" | "q" | "1": QUAD;
case "repeat" | "r" | "2": REPEAT;
case "quad" | "q" | "1" | "true": QUAD;
case "repeat" | "r" | "2" | "false": REPEAT;
default: QUAD; // Ill maybe add more render modes over time idk
}
}
Expand All @@ -32,15 +35,7 @@ abstract class SmartSprite extends FlxSkewRepeatSprite
override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect {
switch (renderMode) {
case REPEAT: return super.getScreenBounds(newRect, camera);
case QUAD:
if (newRect == null) newRect = CoolUtil.rect;
if (camera == null) camera = FlxG.camera;
newRect.setPosition(x, y);
_scaledOrigin.set(origin.x * scale.x, origin.y * scale.y);
newRect.x += -Std.int(camera.scroll.x * scrollFactor.x) - offset.x + origin.x - _scaledOrigin.x;
newRect.y += -Std.int(camera.scroll.y * scrollFactor.y) - offset.y + origin.y - _scaledOrigin.y;
newRect.setSize(frameWidth * Math.abs(scale.x), frameHeight * Math.abs(scale.y));
return newRect.getRotatedBounds(angle, _scaledOrigin, newRect);
case QUAD: return __superGetScreenBounds(newRect, camera);
}
}

Expand Down
7 changes: 1 addition & 6 deletions source/funkin/graphics/TypedGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ class TypedGroup<T:FlxBasic> extends #if (flixel >= "5.7.0") FlxTypedContainer<T
{
public inline function setNull(object:T) {
var index:Int = members.indexOf(object);
if (index != -1) {
#if cpp // skip hxcpp creating a dynamic for null
untyped __cpp__("{0}->__unsafe_set({1}, null())", members, index);
#else
if (index != -1)
members.unsafeSet(index, null);
#end
}
}

public function insertTop(object:T) {
Expand Down
16 changes: 9 additions & 7 deletions source/funkin/objects/dialogue/DialogueBoxBase.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ typedef DialogueJson = {
var ?gf:String;
}

class DialogueBoxBase extends Group {
class DialogueBoxBase extends Group
{
public var skipIntro:Bool = false;
public var dialogueChars:Array<String> = ['senpai-pixel', 'bf-pixel', 'gf-pixel'];
public var jsonParsed:DialogueJson;
Expand All @@ -44,8 +45,8 @@ class DialogueBoxBase extends Group {
public function new():Void {
super();

final jsonContent:String = CoolUtil.getFileContent(Paths.getPath(Song.formatSongFolder(PlayState.SONG.song) + '/dialogue.json', TEXT, 'songs'));
jsonParsed = Json.parse(jsonContent);
var path = Song.formatSongFolder(PlayState.SONG.song) + '/dialogue.json';
jsonParsed = Json.parse(CoolUtil.getFileContent(Paths.getPath(path, TEXT, 'songs')));

final defaultDialogue:DialogueJson = {
lines: [],
Expand All @@ -69,15 +70,16 @@ class DialogueBoxBase extends Group {
public var dialogueStarted:Bool = false;
public var textFinished:Bool = false;

override function update(elapsed:Float):Void {
if (dialogueOpened && !dialogueStarted) {
override function update(elapsed:Float):Void
{
if (dialogueOpened) if (!dialogueStarted) {
dialogueStarted = true;
startDialogue();
startCallback();
if (startCallback != null) startCallback();
ModdingUtil.addCall('startDialogue');
}

if (#if mobile MobileTouch.justPressed() #else getKey('ACCEPT', JUST_PRESSED) #end && dialogueStarted && !isEnding) {
if (#if mobile MobileTouch.justPressed() #else getKey('ACCEPT', JUST_PRESSED) #end) if (dialogueStarted) if (!isEnding) {
if (!textFinished) {
skipCallback();
ModdingUtil.addCall('skipDialogueLine', [jsonParsed.lines[0]]);
Expand Down
43 changes: 22 additions & 21 deletions source/funkin/objects/dialogue/NormalDialogueBox.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class NormalDialogueBox extends DialogueBoxBase
portraitGf = new NormalPortrait(dialogueChars[2]);
portraitGroup.add(portraitGf);

for (portrait in portraitGroup)
portrait.visible = false;
portraitGroup.members.fastForEach((member, i) -> member.visible = false);

speechBubble = new FunkinSprite('speechBubble', [0, FlxG.height*0.5], [0,0]);
speechBubble.addAnim('open-normal', 'normal-open');
Expand All @@ -48,10 +47,9 @@ class NormalDialogueBox extends DialogueBoxBase
swagDialogue.sounds = ['pixelText'];
add(swagDialogue);

skipCallback = skipDialogue;
skipCallback = () -> swagDialogue.skip();
endCallback = () -> FlxG.sound.play(Paths.sound('clickText'), 0.8);
nextCallback = () -> FlxG.sound.play(Paths.sound('clickText'), 0.8);
startCallback = () -> {};
}

override public function update(elapsed:Float):Void {
Expand All @@ -60,21 +58,16 @@ class NormalDialogueBox extends DialogueBoxBase
if (!isEnding)
portraitGf.screenCenter(X);

if (speechBubble.animation.curAnim != null) {
if (speechBubble.animation.curAnim.name.startsWith('open') && speechBubble.animation.curAnim.finished) {
FlxTween.tween(blackBG, {alpha: 0.4}, 0.5, {ease: FlxEase.circIn,});
speechBubble.playAnim('idle-normal');
dialogueOpened = true;
}
var curAnim = speechBubble.animation.curAnim;
if (curAnim != null) if (curAnim.finished) if (curAnim.name.startsWith("open")) {
FlxTween.tween(blackBG, {alpha: 0.4}, 0.5, {ease: FlxEase.circIn,});
speechBubble.playAnim('idle-normal');
dialogueOpened = true;
}

super.update(elapsed);
}

function skipDialogue():Void {
swagDialogue.skip();
}

override public function startDialogue():Void {
super.startDialogue();

Expand Down Expand Up @@ -120,21 +113,29 @@ typedef PortraitJson = {
var smallScale:Float;
} & SpriteJson;

class NormalPortrait extends FunkinSprite {

class NormalPortrait extends FlxSpriteExt {
public var talkAnim:String = 'talk';
public var talking:Bool = false;
public var faceJsonData:PortraitJson;

public function new(path:String, isPlayer:Bool = false):Void {
super('portraits/$path', [0,0], [0,0]);
faceJsonData = Json.parse(CoolUtil.getFileContent(Paths.getPath('images/portraits/$path.json', TEXT, null)));
faceJsonData.offset[0] -= isPlayer ? FlxG.width*0.7: 0;
super(0, 0);

scrollFactor.set();
loadImage('portraits/$path');

var path = 'images/portraits/$path.json';
faceJsonData = Json.parse(CoolUtil.getFileContent(Paths.getPath(path, TEXT, null)));

x = -faceJsonData.offset[0];
y = -faceJsonData.offset[1];
for (anim in faceJsonData.anims)
addAnim(anim.animName, anim.animFile, anim.framerate, anim.loop, anim.indices, anim.offsets);

if (isPlayer)
x += FlxG.width * 0.7;

faceJsonData.anims.fastForEach((anim, i) ->
addAnim(anim.animName, anim.animFile, anim.framerate, anim.loop, anim.indices, anim.offsets)
);

setScale(faceJsonData.smallScale, false);
color = FlxColor.GRAY;
Expand Down
Loading

0 comments on commit d18a1d2

Please sign in to comment.