Skip to content

Commit

Permalink
Fix broken things, move config file
Browse files Browse the repository at this point in the history
  • Loading branch information
gardenappl committed Jun 25, 2017
1 parent 1415903 commit 689852b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 56 deletions.
63 changes: 25 additions & 38 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,41 @@ public static class Config
public static bool BoneBlockFix = true;
public static bool GoldCritterDropTweak = true;

static int ConfigVersion;
const int LatestVersion = 1;
static string ConfigFolderPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks");
static string ConfigPath = Path.Combine(ConfigFolderPath, "config.json");
static string ConfigVersionPath = Path.Combine(ConfigFolderPath, "config.version");
static string ConfigPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks.json");

static string OldConfigFolderPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks");
static string OldConfigPath = Path.Combine(OldConfigFolderPath, "config.json");
static string OldConfigVersionPath = Path.Combine(OldConfigFolderPath, "config.version");

static readonly Preferences Configuration = new Preferences(ConfigPath);

public static void Load()
{
if(File.Exists(ConfigVersionPath))
{
try
{
int.TryParse(File.ReadAllText(ConfigVersionPath), out ConfigVersion);
}
catch(Exception e)
{
VanillaTweaks.Log("Unable to read config version!");
VanillaTweaks.Log(e.ToString());
ConfigVersion = 0;
}
}
else
{
ConfigVersion = 0;
}

if(ConfigVersion < LatestVersion)
{
VanillaTweaks.Log("Config is outdated! Current version: {0} Latest version: {1}", ConfigVersion, LatestVersion);
}
if(ConfigVersion > LatestVersion)
{
VanillaTweaks.Log("Config is from the future?! Current version: {0} Latest version: {1}", ConfigVersion, LatestVersion);
}
// BossExpertise.Log("Reading config...");
if(Directory.Exists(OldConfigFolderPath))
{
if(File.Exists(OldConfigPath))
{
VanillaTweaks.Log("Found config file in old folder! Moving config...");
File.Move(OldConfigPath, ConfigPath);
}
if(File.Exists(OldConfigVersionPath))
{
File.Delete(OldConfigVersionPath);
}
if(Directory.GetFiles(OldConfigFolderPath).Length == 0 && Directory.GetDirectories(OldConfigFolderPath).Length == 0)
{
Directory.Delete(OldConfigFolderPath);
}
else
{
VanillaTweaks.Log("Old config folder still cotains some files/directories. They will not get deleted.");
}
}
if(!ReadConfig())
{
VanillaTweaks.Log("Failed to read config file! Recreating config...");
SaveConfig();
}
else if(ConfigVersion != LatestVersion)
{
VanillaTweaks.Log("Replacing config with newest version...");
File.WriteAllText(ConfigVersionPath, LatestVersion.ToString());
SaveConfig();
}
}

static bool ReadConfig()
Expand Down
5 changes: 3 additions & 2 deletions ItemTweaks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ID;
using Terraria.UI;

namespace VanillaTweaks
{
Expand Down Expand Up @@ -198,7 +199,7 @@ public override void UpdateArmorSet(Player player, string armorSet)
}
else if(armorSet == ObsidianSet && Config.ObsidianArmorTweak)
{
player.setBonus = Language.GetTextValue("Mods.VanillaTweaks.ArmorSet.Obsidian")
player.setBonus = Language.GetTextValue("Mods.VanillaTweaks.ArmorSet.Obsidian");
player.moveSpeed += 0.1f;
}
else if(armorSet == RainSet && Config.RainArmorTweak)
Expand All @@ -209,7 +210,7 @@ public override void UpdateArmorSet(Player player, string armorSet)
}
else if(armorSet == SWATSet && Config.SwatHelmetTweak)
{
player.setBonus = Language.GetTextValue("Mods.VanillaTweaks.ArmorSet.Swat")
player.setBonus = Language.GetTextValue("Mods.VanillaTweaks.ArmorSet.Swat");
player.endurance += 0.25f;
player.rangedDamage += 0.2f;
player.ammoCost80 = true;
Expand Down
23 changes: 10 additions & 13 deletions LangTweaks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,17 @@ public static void EditTooltips(LanguageManager manager)
var bindFlags = BindingFlags.Static | BindingFlags.NonPublic;
var tooltipsField = typeof(Lang).GetField("_itemTooltipCache", bindFlags);
var tooltips = (ItemTooltip[])tooltipsField.GetValue(null);
if(manager.ActiveCulture == GameCulture.English)
if(Config.ObsidianArmorTweak)
{
if(Config.ObsidianArmorTweak)
{
tooltips[ItemID.ObsidianHelm] = ItemTooltip.FromLanguageKey("Mods.VanillaTweaks.ItemTooltip.ObsidianArmor");
tooltips[ItemID.ObsidianSink] = ItemTooltip.FromLanguageKey("Mods.VanillaTweaks.ItemTooltip.ObsidianArmor");
tooltips[ItemID.ObsidianPants] = ItemTooltip.FromLanguageKey("Mods.VanillaTweaks.ItemTooltip.ObsidianArmor");
}
if(Config.MeteorArmorTweak)
{
tooltips[ItemID.MeteorHelmet] = null;
tooltips[ItemID.MeteorSuit] = null;
tooltips[ItemID.MeteorLeggings] = null;
}
tooltips[ItemID.ObsidianHelm] = ItemTooltip.FromLanguageKey("Mods.VanillaTweaks.ItemTooltip.ObsidianArmor");
tooltips[ItemID.ObsidianShirt] = ItemTooltip.FromLanguageKey("Mods.VanillaTweaks.ItemTooltip.ObsidianArmor");
tooltips[ItemID.ObsidianPants] = ItemTooltip.FromLanguageKey("Mods.VanillaTweaks.ItemTooltip.ObsidianArmor");
}
if(Config.MeteorArmorTweak)
{
tooltips[ItemID.MeteorHelmet] = null;
tooltips[ItemID.MeteorSuit] = null;
tooltips[ItemID.MeteorLeggings] = null;
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions VanillaTweaks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="Terraria">
<HintPath>..\..\..\..\Steam\SteamApps\common\Terraria\Terraria.exe</HintPath>
</Reference>
<Reference Include="tModLoader">
<HintPath>..\..\..\..\..\..\..\Yurik\Steam\SteamApps\common\Terraria\tModLoader.exe</HintPath>
</Reference>
Expand Down

0 comments on commit 689852b

Please sign in to comment.