Skip to content

Commit

Permalink
v0.5.0
Browse files Browse the repository at this point in the history
v0.5.0

Many UI Elements and visual Animations are now not sped up.
Fixed ThoughtBubble disappearing to fast
Fixed EnemyIntents sometimes not initializing
Added visual Indicator on how fast the game is.
Added option to not speed up Creatures(Player and Monsters)
Some Refactoring
  • Loading branch information
Skrelpoid authored Jun 4, 2018
2 parents 780b94c + 13dc0d5 commit 106d190
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 18 deletions.
2 changes: 1 addition & 1 deletion assets/ModTheSpire.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "SuperFastMode",
"author_list": ["Skrelpoid"],
"description": "Artificially speeds up the Game. Ingame, go to Mods>SuperFastMode>Config to change Settings. WARNING: Very high values can cause screen flickering. Be careful if you're photo sensitive!",
"version": "0.4.0",
"version": "0.5.0",
"sts_version": "05-31-2018",
"mts_version": "2.6.0"
}
Binary file removed assets/img/BlankButton.png
Binary file not shown.
Binary file added assets/img/progress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions src/skrelpoid/superfastmode/ProgressBar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package skrelpoid.superfastmode;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.megacrit.cardcrawl.core.Settings;

import basemod.IUIElement;
import basemod.ModPanel;

public class ProgressBar implements IUIElement {

public ModPanel parent;
public float x, y, width, height, progress;
public Texture texture;
public boolean multiplied;
public float multiplier = 0.2f;
public float start = 0.05f;

public ProgressBar(ModPanel parent, float x, float y, float width, float height, Texture texture,
boolean multiplied) {
this.parent = parent;
this.x = Settings.scale * x;
this.y = Settings.scale * y;
this.width = Settings.scale * width;
this.height = Settings.scale * height;
this.texture = texture;
this.multiplied = multiplied;
resetProgress();
}

public void resetProgress() {
progress = start;
}

@Override
public void render(SpriteBatch sb) {
sb.setColor(Color.WHITE);
sb.draw(texture, x, y, width * progress, height);
}

@Override
public void update() {
float updateBy = multiplied ? SuperFastMode.getMultDelta() : SuperFastMode.getDelta();
progress += updateBy * multiplier;
if (progress > 1f) {
resetProgress();
}
}

@Override
public int renderLayer() {
return ModPanel.MIDDLE_LAYER;
}

@Override
public int updateOrder() {
return ModPanel.DEFAULT_UPDATE;
}

}
30 changes: 22 additions & 8 deletions src/skrelpoid/superfastmode/SuperFastMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
import org.apache.logging.log4j.Logger;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics;
import com.badlogic.gdx.backends.lwjgl.LwjglGraphics;
import com.badlogic.gdx.graphics.Color;
import com.evacipated.cardcrawl.modthespire.lib.SpireConfig;
import com.evacipated.cardcrawl.modthespire.lib.SpireInitializer;
import com.megacrit.cardcrawl.vfx.AbstractGameEffect;

import basemod.BaseMod;
import basemod.ReflectionHacks;

@SpireInitializer
public class SuperFastMode {
Expand All @@ -29,10 +33,7 @@ public class SuperFastMode {
public static boolean dontSpeedUpCreatures = true;
public static SpireConfig config;

// TODO Enemy intentions are sometimes not seen, seems to happen when
// continuing a save on the first turn

// TODO UI rendering should not be affected by multiplied delta
// TODO UI rendering should not be affected by multiplied delta. WIP

public static void initialize() {
logger.info("Initializing SuperFastMode");
Expand Down Expand Up @@ -76,7 +77,7 @@ public static void writeConfig() {
config.setFloat("deltaMultiplier", deltaMultiplier);
}

public static float getMultDelta(Object graphics) {
public static float getMultDelta(Graphics graphics) {
float mult = isDeltaMultiplied ? SuperFastMode.deltaMultiplier : 1;
return mult * getDelta(graphics);
}
Expand All @@ -86,7 +87,7 @@ public static float getMultDelta() {
}

// Gets multiplied delta but can't be higher than max
public static float getMultDeltaDelta(float max) {
public static float getMultDelta(float max) {
return Math.min(max, getMultDelta());
}

Expand All @@ -95,7 +96,7 @@ public static float getDelta(float max) {
return Math.min(max, getDelta());
}

public static float getDelta(Object graphics) {
public static float getDelta(Graphics graphics) {
float delta = 0.016f;
try {
delta = deltaField.getFloat(graphics);
Expand All @@ -109,10 +110,23 @@ public static float getDelta() {
return getDelta(Gdx.graphics);
}

public static void lerp(float[] start, float target) {
public static void instantLerp(float[] start, float target) {
if (isInstantLerp) {
start[0] = target;
}
}

public static void updateVFX(AbstractGameEffect effect) {
// Copied from AbstractGameEffect.update()
effect.duration -= getDelta();
Color c = (Color) (ReflectionHacks.getPrivate(effect, AbstractGameEffect.class, "color"));
if (effect.duration < effect.startingDuration / 2.0F) {
c.a = (effect.duration / (effect.startingDuration / 2.0F));
}

if (effect.duration < 0.0F) {
effect.isDone = true;
c.a = 0.0F;
}
}
}
47 changes: 43 additions & 4 deletions src/skrelpoid/superfastmode/UIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ public class UIManager implements PostInitializeSubscriber {
public static ModPanel panel;
public static ModLabel saveFeedback;
public static boolean speedUpdated;

// TODO show comparison of speed
public static Texture progressTexture;
public static ProgressBar progressBar, multProgressBar;

@Override
public void receivePostInitialize() {
speedUpdated = true;
progressTexture = new Texture("img/progress.png");
buildUI();
BaseMod.registerModBadge(new Texture("img/modBadge.png"), SuperFastMode.MOD_NAME, SuperFastMode.AUTHOR,
SuperFastMode.DESCRIPTION, panel);
Expand All @@ -46,6 +47,10 @@ public static void buildUI() {
panel.addUIElement(skipInfo());
panel.addUIElement(deltaInfo());
panel.addUIElement(speedInfo());
panel.addUIElement(progress());
panel.addUIElement(multProgress());
panel.addUIElement(progressInfo());
panel.addUIElement(multProgressInfo());
}

private static ModLabeledToggleButton deltaToggle() {
Expand All @@ -65,7 +70,7 @@ private static void updateDeltaToggle(ModToggleButton b) {
private static ModLabeledToggleButton skipToggle() {
final float x = 350;
final float y = 690;
return new ModLabeledToggleButton("Skip Some Animations", x, y, Color.WHITE, FontHelper.tipBodyFont,
return new ModLabeledToggleButton("Skip Some Actions", x, y, Color.WHITE, FontHelper.tipBodyFont,
SuperFastMode.isInstantLerp, panel, l -> {
}, UIManager::updateSkipToggle);
}
Expand Down Expand Up @@ -132,7 +137,7 @@ private static ModLabel saveFeedback() {
private static ModLabel skipInfo() {
final float x = 350;
final float y = 750;
return new ModLabel("Makes some Animations instant", x, y, FontHelper.tipBodyFont, panel, l -> {
return new ModLabel("Makes some Actions instant", x, y, FontHelper.tipBodyFont, panel, l -> {
});
}

Expand All @@ -155,11 +160,45 @@ private static void updateSpeedInfo(ModLabel l) {
speedUpdated = false;
saveFeedback.text = UNSAVED_SETTINGS;
l.text = "Game Speed is " + (int) (calculateSpeed() * 100 + 0.5f) + "%";
progressBar.resetProgress();
multProgressBar.resetProgress();
}
}

private static float calculateSpeed() {
return SuperFastMode.isDeltaMultiplied ? SuperFastMode.deltaMultiplier : 1;
}

private static ProgressBar progress() {
final float x = 600;
final float y = 460;
final float width = 600;
final float height = 32;
progressBar = new ProgressBar(panel, x, y, width, height, progressTexture, false);
return progressBar;
}

private static ProgressBar multProgress() {
final float x = 600;
final float y = 390;
final float width = 600;
final float height = 32;
multProgressBar = new ProgressBar(panel, x, y, width, height, progressTexture, true);
return multProgressBar;
}

private static ModLabel progressInfo() {
final float x = 450;
final float y = 471;
return new ModLabel("Normal Speed:", x, y, FontHelper.tipBodyFont, panel, l -> {
});
}

private static ModLabel multProgressInfo() {
final float x = 450;
final float y = 401;
return new ModLabel("Accelerated:", x, y, FontHelper.tipBodyFont, panel, l -> {
});
}

}
53 changes: 50 additions & 3 deletions src/skrelpoid/superfastmode/patches/DefaultDeltaPatches.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package skrelpoid.superfastmode.patches;

import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.monsters.AbstractMonster.Intent;
import com.megacrit.cardcrawl.vfx.combat.BattleStartEffect;

import javassist.CannotCompileException;
import javassist.expr.ExprEditor;
import javassist.expr.MethodCall;

//All methods patched in this class should always get the real delta time

//TODO add to this patch: icons on the top right + energy display, draw pile, discard pile, enemy intents
public class DefaultDeltaPatches {
//@formatter:off

Expand All @@ -17,10 +21,11 @@ public class DefaultDeltaPatches {
// Fixes mouse events not registering on map
@SpirePatch(cls = "com.megacrit.cardcrawl.screens.DungeonMapScreen", method = "updateMouse")
// Display SpeechBubbles long enough to read
// Known issue: text stays longer than bubble. Probably leave it like that
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.SpeechWord", method = "applyEffects")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.SpeechBubble", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.SpeechBubble", method = "updateScale")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.CloudBubble", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.ThoughtBubble", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.InfiniteSpeechBubble", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.InfiniteSpeechBubble", method = "updateScale")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.ShopSpeechBubble", method = "update")
Expand All @@ -39,14 +44,43 @@ public class DefaultDeltaPatches {
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.buttons.GridSelectConfirmButton", method = "updateGlow")
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.buttons.ProceedButton", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.map.MapRoomNode", method = "oscillateColor")
// Fixes Intents
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.panels.TopPanel", method = "updateSettingsButtonLogic")
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.panels.TopPanel", method = "updateDeckViewButtonLogic")
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.panels.TopPanel", method = "updateMapButtonLogic")
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.panels.TopPanel", method = "updatePotions")
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.panels.EnergyPanel", method = "updateRed")
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.panels.EnergyPanel", method = "updateVfx")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.DiscardGlowEffect", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.panels.DiscardPilePanel", method = "updatePositions")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.ExhaustPileParticle", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.panels.ExhaustPanel", method = "updatePositions")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.GameDeckGlowEffect", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.panels.DrawPilePanel", method = "updatePositions")
@SpirePatch(cls = "com.megacrit.cardcrawl.ui.panels.EnergyPanel", method = "updateVfx")
@SpirePatch(cls = "com.megacrit.cardcrawl.cards.AbstractCard", method = "updateGlow")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.cardManip.CardGlowBorder", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.rewards.RewardItem", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.RewardGlowEffect", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.orbs.EmptyOrbSlot", method = "updateAnimation")
// Intents
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.BobEffect", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.monsters.AbstractMonster", method = "updateIntentVFX")
@SpirePatch(cls = "com.megacrit.cardcrawl.monsters.AbstractMonster", method = "updateIntent")
@SpirePatch(cls = "com.megacrit.cardcrawl.monsters.AbstractMonster", method = "render")
@SpirePatch(cls = "com.megacrit.cardcrawl.monsters.AbstractMonster", method = "renderName")
@SpirePatch(cls = "com.megacrit.cardcrawl.monsters.AbstractMonster", method = "renderIntent")
@SpirePatch(cls = "com.megacrit.cardcrawl.monsters.AbstractMonster", method = "updateDeathAnimation")
@SpirePatch(cls = "com.megacrit.cardcrawl.monsters.AbstractMonster", method = "updateEscapeAnimation")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.combat.StunStarEffect", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.combat.UnknownParticleEffect", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.ShieldParticleEffect", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.combat.BuffParticleEffect", method = "update")
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.DebuffParticleEffect", method = "update")
// Orbs
@SpirePatch(cls = "com.megacrit.cardcrawl.orbs.Dark", method = "updateAnimation")
@SpirePatch(cls = "com.megacrit.cardcrawl.orbs.Frost", method = "updateAnimation")
@SpirePatch(cls = "com.megacrit.cardcrawl.orbs.Lightning", method = "updateAnimation")
@SpirePatch(cls = "com.megacrit.cardcrawl.orbs.Plasma", method = "updateAnimation")
public static class DeltaPatch {
public static ExprEditor Instrument() {
return new ExprEditor() {
Expand All @@ -59,4 +93,17 @@ public void edit(MethodCall m) throws CannotCompileException {
};
}
}

// Fixes Intents sometimes not being visible
@SpirePatch(cls = "com.megacrit.cardcrawl.vfx.combat.BattleStartEffect", method = "update")
public static class IntentFix {
@SpireInsertPatch(rloc = 10)
public static void Insert(BattleStartEffect effect) {
for (AbstractMonster m : AbstractDungeon.getMonsters().monsters) {
if (m.intent == Intent.DEBUG) {
m.createIntent();
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/skrelpoid/superfastmode/patches/MathHelperPatches.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MathHelperPatches {
@SpirePatch(cls = "com.megacrit.cardcrawl.helpers.MathHelper", method = "scrollSnapLerpSpeed")
public static class InstantLerp {
public static void Prefix(@ByRef float[] start, float target) {
SuperFastMode.lerp(start, target);
SuperFastMode.instantLerp(start, target);
}
}
}
6 changes: 5 additions & 1 deletion src/skrelpoid/superfastmode/patches/MathUtilsPatches.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ public class MathUtilsPatches {
@SpirePatch(cls = "com.badlogic.gdx.math.MathUtils", method = "lerp")
public static class LerpPatch {
public static float Replace(float fromValue, float toValue, float progress) {
float result = fromValue + (toValue - fromValue) * progress;
float result = lerp(fromValue, toValue, progress);
// result should never be higher than toValue
if (result > toValue || SuperFastMode.isInstantLerp) {
result = toValue;
}
return result;
}
}

public static float lerp(float from, float to, float progress) {
return from + (to - from) * progress;
}
}

0 comments on commit 106d190

Please sign in to comment.