Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
aedenthorn committed Sep 12, 2023
1 parent 84f6368 commit a0a76ef
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 65 deletions.
2 changes: 1 addition & 1 deletion CustomOreNodes/CustomOreNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CustomOreNode
public List<OreLevelRange> oreLevelRanges = new List<OreLevelRange>();
public string nodeDesc;
public string spritePath;
public string spriteType;
public string spriteType = "game";
public int spriteX;
public int spriteY;
public int spriteW;
Expand Down
86 changes: 43 additions & 43 deletions CustomOreNodes/Methods.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Locations;
Expand All @@ -17,7 +18,8 @@ private void ReloadOreData(bool first = false)
{

customOreNodesList.Clear();
CustomOreData data;
Helper.GameContent.InvalidateCache(dictPath);
CustomOreData data = new();
int id = 42424000;
Dictionary<int, int> existingPSIs = new Dictionary<int, int>();
CustomOreConfig conf = Helper.Data.ReadJsonFile<CustomOreConfig>("ore_config.json") ?? new CustomOreConfig();
Expand All @@ -36,9 +38,9 @@ private void ReloadOreData(bool first = false)
}
try
{
int add = 0;
if (File.Exists(Path.Combine(Helper.DirectoryPath, "custom_ore_nodes.json")))
{
int add = 0;
try
{
data = Helper.ModContent.Load<CustomOreData>("custom_ore_nodes.json");
Expand All @@ -58,63 +60,61 @@ private void ReloadOreData(bool first = false)
Helper.Data.WriteJsonFile("custom_ore_nodes.json", data);
}
}
conf = Helper.Data.ReadJsonFile<CustomOreConfig>("ore_config.json") ?? new CustomOreConfig();
var dict = Helper.GameContent.Load<Dictionary<string, CustomOreNode>>(dictPath);
foreach (var kvp in dict)
}

var dict = Helper.GameContent.Load<Dictionary<string, object>>(dictPath);
foreach (var kvp in dict)
{
try
{
try
{
data.nodes.Add(kvp.Value);
}
catch(Exception ex)
{
Monitor.Log($"Exception adding {kvp.Key}: \r\n{ex}");
}
var json = JsonConvert.SerializeObject(kvp.Value);
var node = JsonConvert.DeserializeObject<CustomOreNode>(json);
data.nodes.Add(node);
SMonitor.Log($"Added dictionary node: {kvp.Key}");
}
foreach (object nodeObj in data.nodes)
catch (Exception ex)
{
CustomOreNode node = (CustomOreNode)nodeObj;

if (node.spriteType == "mod")
{
node.texture = Helper.ModContent.Load<Texture2D>(node.spritePath);
}
else
{
node.texture = Helper.ModContent.Load<Texture2D>(node.spritePath);
}
if (conf.parentSheetIndexes.ContainsKey(add))
{
node.parentSheetIndex = conf.parentSheetIndexes[add];
}
else
{
while (existingPSIs.ContainsKey(id))
id++;
node.parentSheetIndex = id++;
}
conf.parentSheetIndexes[add] = node.parentSheetIndex;
Monitor.Log($"Exception adding {kvp.Key}: \r\n{ex}");
}
}
conf = Helper.Data.ReadJsonFile<CustomOreConfig>("ore_config.json") ?? new CustomOreConfig();
foreach (object nodeObj in data.nodes)
{
CustomOreNode node = (CustomOreNode)nodeObj;

customOreNodesList.Add(node);
add++;
if (node.spriteType == "mod")
{
node.texture = Helper.ModContent.Load<Texture2D>(node.spritePath);
}
if (first)
else
{
Monitor.Log($"Got {customOreNodesList.Count} ores from mod", LogLevel.Debug);
Helper.Data.WriteJsonFile("ore_config.json", conf);
node.texture = Helper.GameContent.Load<Texture2D>(node.spritePath);
}
if (conf.parentSheetIndexes.ContainsKey(add))
{
node.parentSheetIndex = conf.parentSheetIndexes[add];
}
else
{
while (existingPSIs.ContainsKey(id))
id++;
node.parentSheetIndex = id++;
}
conf.parentSheetIndexes[add] = node.parentSheetIndex;

customOreNodesList.Add(node);
add++;
}
else
if (first)
{
SMonitor.Log("No custom_ore_nodes.json in mod directory.");
Monitor.Log($"Got {customOreNodesList.Count} ores from mod", LogLevel.Debug);
Helper.Data.WriteJsonFile("ore_config.json", conf);
}
}
catch (Exception ex)
{
SMonitor.Log("Error processing custom_ore_nodes.json: " + ex, LogLevel.Error);
}

foreach (IContentPack contentPack in Helper.ContentPacks.GetOwned())
{
try
Expand Down
2 changes: 1 addition & 1 deletion CustomOreNodes/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void Content_AssetRequested(object sender, StardewModdingAPI.Events.Asse
{
if (e.NameWithoutLocale.IsEquivalentTo(dictPath))
{
e.LoadFrom(() => new Dictionary<string, CustomOreNode>(), StardewModdingAPI.Events.AssetLoadPriority.Exclusive);
e.LoadFrom(() => new Dictionary<string, object>(), StardewModdingAPI.Events.AssetLoadPriority.Exclusive);
}
}

Expand Down
2 changes: 1 addition & 1 deletion CustomOreNodes/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Custom Ore Nodes",
"Author": "aedenthorn",
"Version": "2.3.0",
"Version": "2.3.4",
"Description": "Spawns custom ore nodes in mines.",
"UniqueID": "aedenthorn.CustomOreNodes",
"EntryDll": "CustomOreNodes.dll",
Expand Down
54 changes: 45 additions & 9 deletions DinoForm/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public override void Entry(IModHelper helper)
{
Config = Helper.ReadConfig<ModConfig>();

if (!Config.ModEnabled)
return;

context = this;

SMonitor = Monitor;
Expand Down Expand Up @@ -256,48 +253,87 @@ private void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameL

configMenu.AddBoolOption(
mod: ModManifest,
name: () => "Mod Enabled",
name: () => Helper.Translation.Get("GMCM_Option_ModEnabled_Name"),
getValue: () => Config.ModEnabled,
setValue: value => Config.ModEnabled = value
);

configMenu.AddTextOption(
mod: ModManifest,
name: () => Helper.Translation.Get("GMCM_Option_EatTrigger_Name"),
getValue: () => Config.EatTrigger,
setValue: value => Config.EatTrigger = value
);

configMenu.AddNumberOption(
mod: ModManifest,
name: () => Helper.Translation.Get("GMCM_Option_EatLastSeconds_Name"),
getValue: () => Config.EatLastSeconds,
setValue: value => Config.EatLastSeconds = value
);

configMenu.AddKeybindList(
mod: ModManifest,
name: () => "Transform Key",
name: () => Helper.Translation.Get("GMCM_Option_TransformKey_Name"),
getValue: () => Config.TransformKey,
setValue: value => Config.TransformKey = value
);


configMenu.AddKeybindList(
mod: ModManifest,
name: () => "Fire Key",
name: () => Helper.Translation.Get("GMCM_Option_FireKey_Name"),
getValue: () => Config.FireKey,
setValue: value => Config.FireKey = value
);

configMenu.AddNumberOption(
mod: ModManifest,
name: () => "Move Speed",
name: () => Helper.Translation.Get("GMCM_Option_MoveSpeed_Name"),
getValue: () => Config.MoveSpeed,
setValue: value => Config.MoveSpeed = value
);

configMenu.AddNumberOption(
mod: ModManifest,
name: () => Helper.Translation.Get("GMCM_Option_Defense_Name"),
getValue: () => Config.Defense,
setValue: value => Config.Defense = value
);

configMenu.AddNumberOption(
mod: ModManifest,
name: () => "Stamina Use",
name: () => Helper.Translation.Get("GMCM_Option_StaminaUse_Name"),
getValue: () => Config.StaminaUse,
setValue: value => Config.StaminaUse = value
);

configMenu.AddNumberOption(
mod: ModManifest,
name: () => Helper.Translation.Get("GMCM_Option_FireDamage_Name"),
getValue: () => Config.FireDamage,
setValue: value => Config.FireDamage = value
);

configMenu.AddNumberOption(
mod: ModManifest,
name: () => Helper.Translation.Get("GMCM_Option_FireDistance_Name"),
getValue: () => Config.FireDistance,
setValue: value => Config.FireDistance = value
);

configMenu.AddTextOption(
mod: ModManifest,
name: () => "Transform Sound",
name: () => Helper.Translation.Get("GMCM_Option_TransformSound_Name"),
getValue: () => Config.TransformSound,
setValue: value => Config.TransformSound = value
);
configMenu.AddTextOption(
mod: ModManifest,
name: () => Helper.Translation.Get("GMCM_Option_FireSound_Name"),
getValue: () => Config.FireSound,
setValue: value => Config.FireSound = value
);
}

}
Expand Down
11 changes: 11 additions & 0 deletions DinoForm/i18n/default.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{
"GMCM_Option_ModEnabled_Name": "Mod Enabled",
"GMCM_Option_EatTrigger_Name": "Eat Trigger",
"GMCM_Option_EatLastSeconds_Name": "Duration (s)",
"GMCM_Option_TransformKey_Name": "Key Trigger",
"GMCM_Option_FireKey_Name": "Fire Key",
"GMCM_Option_MoveSpeed_Name": "Move Speed",
"GMCM_Option_Defense_Name": "Defense",
"GMCM_Option_StaminaUse_Name": "Stamina Use",
"GMCM_Option_FireDamage_Name": "Fire Damage",
"GMCM_Option_FireDistance_Name": "Fire Distance",
"GMCM_Option_TransformSound_Name": "Transform Sound",
"GMCM_Option_FireSound_Name": "Mod",
"dino-form": "Dino Form",
"dino-buff-description": "Speed {0}\nDefense +{1}\nDemolish\nFire Breath"
}
6 changes: 3 additions & 3 deletions DinoForm/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
},
"Dependencies": [
{
"UniqueID": "Platonymous.ModUpdater",
"IsRequired": false
"UniqueID": "aedenthorn.BuffFramework",
"IsRequired": true
}
],
"UpdateKeys": [ "Nexus:" ]
"UpdateKeys": [ "Nexus:18244" ]
}
35 changes: 33 additions & 2 deletions LightMod/CodePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static void Postfix(Object __instance)
__instance.initializeLightSource(__instance.TileLocation);
}
}

[HarmonyPatch(typeof(GameLocation), nameof(GameLocation.drawLightGlows))]
private static class GameLocation_drawLightGlows_Patch
{
Expand All @@ -177,6 +177,37 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
return codes.AsEnumerable();
}
}
[HarmonyPatch(typeof(GameLocation), nameof(GameLocation.drawAboveFrontLayer))]
private static class GameLocation_drawAboveFrontLayer_Patch
{
public static void Postfix(GameLocation __instance, SpriteBatch b)
{
if (!Config.ModEnabled)
return;

foreach(var npc in __instance.characters)
{
if (!lightDataDict.TryGetValue(npc.Name, out var data))
continue;

float alpha = 1;
float radius = data.radius;
if (npc.modData.TryGetValue(alphaKey, out string astr) && int.TryParse(astr, out int a))
{
alpha = (byte)a / 255f;
}
if (npc.modData.TryGetValue(radiusKey, out string rstr) && float.TryParse(rstr, NumberStyles.Float, CultureInfo.InvariantCulture, out float r))
{
radius = r;
}
float scale = 1;
Point location = Utility.Vector2ToPoint(Game1.GlobalToLocal(Game1.viewport, npc.GetBoundingBox().Center.ToVector2() - new Vector2(20.5f, 33.5f) * scale * 4));
Point size = Utility.Vector2ToPoint(new Vector2(41f, 67f) * scale * 4);
b.Draw(Game1.mouseCursors, new Rectangle(location, size), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(21, 1695, 41, 67)), Color.Yellow * 0.5f, 0f, Vector2.Zero, SpriteEffects.None, 1f);

}
}
}

[HarmonyPatch(typeof(Furniture), nameof(Furniture.removeLights))]
private static class Furniture_removeLights_Patch
Expand All @@ -186,7 +217,7 @@ public static bool Prefix(Furniture __instance)
return (!Config.ModEnabled || !__instance.modData.TryGetValue(switchKey, out string status) || status == "off");
}
}

[HarmonyPatch(typeof(Game1), nameof(Game1.pressSwitchToolButton))]
private static class Game1_pressSwitchToolButton_Patch
{
Expand Down
Loading

0 comments on commit a0a76ef

Please sign in to comment.