Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
kiooeht committed Jun 29, 2018
2 parents 978fb8d + ad7244a commit 8a2d552
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 117 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,8 @@ This is a fast forward to v1.6.3 of daviscook477's fork with a few additional ch
* Support for week 30 (kiooeht)
* Deprecate starting deck and relic hooks (kiooeht)

#### v2.15.0 ####
* Support for week 31 (kobting)
* Add modded characters to the Custom mode screen (kiooeht)

#### dev ####
10 changes: 10 additions & 0 deletions src/main/java/basemod/BaseMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Set;
import java.util.function.Consumer;

import com.megacrit.cardcrawl.screens.custom.CustomModeCharacterButton;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.clapper.util.classutil.AbstractClassFilter;
Expand Down Expand Up @@ -1429,6 +1430,15 @@ public static ArrayList<CharacterOption> generateCharacterOptions() {
return options;
}

// generate character options for CustomModeScreen based on added players
public static ArrayList<CustomModeCharacterButton> generateCustomCharacterOptions() {
ArrayList<CustomModeCharacterButton> options = new ArrayList<>();
for (String character : playerClassMap.keySet()) {
options.add(new CustomModeCharacterButton(AbstractPlayer.PlayerClass.valueOf(character), false));
}
return options;
}

// generate stats for StatsScreen based on added players
public static ArrayList<CharStat> generateCharacterStats() {
ArrayList<CharStat> stats = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package basemod.patches.com.megacrit.cardcrawl.cards.CardGroup;

import basemod.BaseMod;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardGroup;
import javassist.CannotCompileException;
import javassist.CtBehavior;

@SpirePatch(
cls="com.megacrit.cardcrawl.cards.CardGroup",
method="moveToExhaustPile"
)
public class ModalExhaustFix
{
public static void Raw(CtBehavior ctMethodToPatch) throws CannotCompileException
{
String src =
"if (basemod.BaseMod.modalChoiceScreen.isOpen) {" +
"basemod.patches.com.megacrit.cardcrawl.cards.CardGroup.ModalExhaustFix.Nested.Delay($0, $1);" +
"return;" +
"}";
ctMethodToPatch.insertBefore(src);
}

public static class Nested {
public static void Delay(CardGroup __instance, AbstractCard card) {
BaseMod.modalChoiceScreen.delayExhaust(__instance, card);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.megacrit.cardcrawl.screens.SingleCardViewPopup;

import basemod.abstracts.CustomCard;
import basemod.patches.com.megacrit.cardcrawl.screens.mainMenu.CardLibraryScreen.EverythingFix;
import basemod.patches.com.megacrit.cardcrawl.screens.compendium.CardLibraryScreen.EverythingFix;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void Insert(Object __obj_instance, String optionName, Object cObj,
if (!BaseMod.isBaseGameCharacter(chosenClass)) {
try {
Field charInfoField;
charInfoField = option.getClass().getDeclaredField("charInfo");
charInfoField = CharacterOption.class.getDeclaredField("charInfo");
charInfoField.setAccessible(true);
@SuppressWarnings("rawtypes")
Class characterClass = BaseMod.getPlayerClass(chosenClass.toString());
Expand All @@ -44,7 +44,7 @@ public static void Insert(Object __obj_instance, String optionName, Object cObj,
try {
// fix texture loading
Field buttonImgField;
buttonImgField = option.getClass().getDeclaredField("buttonImg");
buttonImgField = CharacterOption.class.getDeclaredField("buttonImg");
buttonImgField.setAccessible(true);
buttonImgField.set(option, new Texture(BaseMod.getPlayerButton(chosenClass.toString())));
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,112 +1,112 @@
package basemod.patches.com.megacrit.cardcrawl.screens.mainMenu.CardLibraryScreen;

import basemod.patches.com.megacrit.cardcrawl.screens.mainMenu.ColorTabBar.ColorTabBarFix;
import com.evacipated.cardcrawl.modthespire.lib.*;
import com.evacipated.cardcrawl.modthespire.patcher.PatchingException;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardGroup;
import com.megacrit.cardcrawl.helpers.CardLibrary;
import com.megacrit.cardcrawl.screens.mainMenu.CardLibraryScreen;
import com.megacrit.cardcrawl.screens.mainMenu.ColorTabBar;
import javassist.CannotCompileException;
import javassist.CtBehavior;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
*
* @author kioeeht from branch custom-content on ModTheSpire
* https://github.com/kiooeht/ModTheSpire/tree/custom-content
*
*/
public class EverythingFix
{
public static class Fields
{
public static Map<AbstractCard.CardColor, CardGroup> cardGroupMap = new HashMap<>();
}

@SpirePatch(
cls="com.megacrit.cardcrawl.screens.mainMenu.CardLibraryScreen",
method="initialize"
)
public static class Initialize
{
@SpireInsertPatch
public static void Insert(Object __obj_instance)
{
try {
AbstractCard.CardColor[] colors = AbstractCard.CardColor.values();
for (int icolor = AbstractCard.CardColor.CURSE.ordinal() + 1; icolor < colors.length; ++icolor) {
CardGroup group = new CardGroup(CardGroup.CardGroupType.UNSPECIFIED);
group.group = CardLibrary.getCardList(CardLibrary.LibraryType.valueOf(colors[icolor].name()));
Fields.cardGroupMap.put(colors[icolor], group);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static class Locator extends SpireInsertLocator
{
@Override
public int[] Locate(CtBehavior ctMethodToPatch) throws CannotCompileException, PatchingException
{
Matcher finalMatcher = new Matcher.MethodCallMatcher("com.megacrit.cardcrawl.screens.mainMenu.CardLibraryScreen", "calculateScrollBounds");

return LineFinder.findInOrder(ctMethodToPatch, new ArrayList<Matcher>(), finalMatcher);
}
}
}
@SpirePatch(
cls="com.megacrit.cardcrawl.screens.mainMenu.CardLibraryScreen",
method="setLockStatus"
)
public static class setLockStatus
{
public static void Postfix(Object __obj_instance)
{
try {
CardLibraryScreen screen = (CardLibraryScreen) __obj_instance;

AbstractCard.CardColor[] colors = AbstractCard.CardColor.values();
for (int icolor = AbstractCard.CardColor.CURSE.ordinal() + 1; icolor < colors.length; ++icolor) {
CardGroup group = new CardGroup(CardGroup.CardGroupType.UNSPECIFIED);
group.group = CardLibrary.getCardList(CardLibrary.LibraryType.valueOf(colors[icolor].name()));
@SuppressWarnings("rawtypes")
Class[] cArg = new Class[1];
cArg[0] = CardGroup.class;
Method lockStatusHelper = screen.getClass().getDeclaredMethod("lockStatusHelper", cArg);
lockStatusHelper.setAccessible(true);
lockStatusHelper.invoke(screen, group);
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
}
}

@SpirePatch(
cls="com.megacrit.cardcrawl.screens.mainMenu.CardLibraryScreen",
method="didChangeTab"
)
public static class DidChangeTab
{
@SpireInsertPatch(
rloc=1,
localvars={"visibleCards"}
)
public static void Insert(CardLibraryScreen __instance, ColorTabBar tabBar, ColorTabBar.CurrentTab newSelection, @ByRef CardGroup[] visibleCards)
{
if (newSelection == ColorTabBarFix.Enums.MOD) {
visibleCards[0] = Fields.cardGroupMap.get(AbstractCard.CardColor.values()[AbstractCard.CardColor.CURSE.ordinal() + 1 + ColorTabBarFix.Fields.modTabIndex]);
}
}
}
package basemod.patches.com.megacrit.cardcrawl.screens.compendium.CardLibraryScreen;

import basemod.patches.com.megacrit.cardcrawl.screens.mainMenu.ColorTabBar.ColorTabBarFix;
import com.evacipated.cardcrawl.modthespire.lib.*;
import com.evacipated.cardcrawl.modthespire.patcher.PatchingException;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardGroup;
import com.megacrit.cardcrawl.helpers.CardLibrary;
import com.megacrit.cardcrawl.screens.compendium.CardLibraryScreen;
import com.megacrit.cardcrawl.screens.mainMenu.ColorTabBar;
import javassist.CannotCompileException;
import javassist.CtBehavior;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
*
* @author kioeeht from branch custom-content on ModTheSpire
* https://github.com/kiooeht/ModTheSpire/tree/custom-content
*
*/
public class EverythingFix
{
public static class Fields
{
public static Map<AbstractCard.CardColor, CardGroup> cardGroupMap = new HashMap<>();
}

@SpirePatch(
cls="com.megacrit.cardcrawl.screens.compendium.CardLibraryScreen",
method="initialize"
)
public static class Initialize
{
@SpireInsertPatch
public static void Insert(Object __obj_instance)
{
try {
AbstractCard.CardColor[] colors = AbstractCard.CardColor.values();
for (int icolor = AbstractCard.CardColor.CURSE.ordinal() + 1; icolor < colors.length; ++icolor) {
CardGroup group = new CardGroup(CardGroup.CardGroupType.UNSPECIFIED);
group.group = CardLibrary.getCardList(CardLibrary.LibraryType.valueOf(colors[icolor].name()));
Fields.cardGroupMap.put(colors[icolor], group);
}
} catch (Exception e) {
e.printStackTrace();
}
}

public static class Locator extends SpireInsertLocator
{
@Override
public int[] Locate(CtBehavior ctMethodToPatch) throws CannotCompileException, PatchingException
{
Matcher finalMatcher = new Matcher.MethodCallMatcher("com.megacrit.cardcrawl.screens.compendium.CardLibraryScreen", "calculateScrollBounds");

return LineFinder.findInOrder(ctMethodToPatch, new ArrayList<Matcher>(), finalMatcher);
}
}
}

@SpirePatch(
cls="com.megacrit.cardcrawl.screens.compendium.CardLibraryScreen",
method="setLockStatus"
)
public static class setLockStatus
{
public static void Postfix(Object __obj_instance)
{
try {
CardLibraryScreen screen = (CardLibraryScreen) __obj_instance;

AbstractCard.CardColor[] colors = AbstractCard.CardColor.values();
for (int icolor = AbstractCard.CardColor.CURSE.ordinal() + 1; icolor < colors.length; ++icolor) {
CardGroup group = new CardGroup(CardGroup.CardGroupType.UNSPECIFIED);
group.group = CardLibrary.getCardList(CardLibrary.LibraryType.valueOf(colors[icolor].name()));

@SuppressWarnings("rawtypes")
Class[] cArg = new Class[1];
cArg[0] = CardGroup.class;
Method lockStatusHelper = screen.getClass().getDeclaredMethod("lockStatusHelper", cArg);
lockStatusHelper.setAccessible(true);
lockStatusHelper.invoke(screen, group);
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
}
}

@SpirePatch(
cls="com.megacrit.cardcrawl.screens.compendium.CardLibraryScreen",
method="didChangeTab"
)
public static class DidChangeTab
{
@SpireInsertPatch(
rloc=1,
localvars={"visibleCards"}
)
public static void Insert(CardLibraryScreen __instance, ColorTabBar tabBar, ColorTabBar.CurrentTab newSelection, @ByRef CardGroup[] visibleCards)
{
if (newSelection == ColorTabBarFix.Enums.MOD) {
visibleCards[0] = Fields.cardGroupMap.get(AbstractCard.CardColor.values()[AbstractCard.CardColor.CURSE.ordinal() + 1 + ColorTabBarFix.Fields.modTabIndex]);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package basemod.patches.com.megacrit.cardcrawl.screens.custom.CustomModeCharacterButton;

import basemod.BaseMod;
import com.badlogic.gdx.graphics.Texture;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.localization.CharacterStrings;
import com.megacrit.cardcrawl.screens.CharSelectInfo;
import com.megacrit.cardcrawl.screens.charSelect.CharacterOption;
import com.megacrit.cardcrawl.screens.custom.CustomModeCharacterButton;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@SpirePatch(
cls="com.megacrit.cardcrawl.screens.custom.CustomModeCharacterButton",
method=SpirePatch.CONSTRUCTOR
)
public class CtorSwitch
{
public static final Logger logger = LogManager.getLogger(BaseMod.class.getName());

public static void Postfix(CustomModeCharacterButton __instance, AbstractPlayer.PlayerClass c, boolean locked)
{
if (!BaseMod.isBaseGameCharacter(c)) {
try {
Field charStringsField = CustomModeCharacterButton.class.getDeclaredField("charStrings");
charStringsField.setAccessible(true);

Class characterClass = BaseMod.getPlayerClass(c.toString());
Method getLoadout = characterClass.getMethod("getLoadout");
CharSelectInfo charInfo = (CharSelectInfo) getLoadout.invoke(null);

CharacterStrings charStrings = new CharacterStrings();
charStrings.NAMES = new String[]{charInfo.name};
charStrings.TEXT = new String[]{charInfo.flavorText};

charStringsField.set(__instance, charStrings);
} catch (NoSuchFieldException | SecurityException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
logger.error("could not create character loadout for " + c.toString());
logger.error("with exception: " + e.getMessage());
e.printStackTrace();
}

try {
// fix texture loading
Field buttonImgField = CustomModeCharacterButton.class.getDeclaredField("buttonImg");
buttonImgField.setAccessible(true);
buttonImgField.set(__instance, new Texture(BaseMod.getPlayerButton(c.toString())));
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
logger.error("could not create character select button for " + c.toString());
logger.error("with exception: " + e.getMessage());
e.printStackTrace();
}
}
}
}
Loading

0 comments on commit 8a2d552

Please sign in to comment.