Skip to content

Commit

Permalink
Release 26
Browse files Browse the repository at this point in the history
  • Loading branch information
Epicguru authored Aug 22, 2024
2 parents 1f417da + d7c9c0e commit 6e9cc5e
Show file tree
Hide file tree
Showing 30 changed files with 364 additions and 396 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@ You can download the [latest release here](https://github.com/Epicguru/AdvancedA
Other mods may be compatible. The mods listed above are just the mods that have patches made by Epicguru.

[Click here to see how to create a patch yourself!](Source/TweakTutorial/AuthorTweaks.md)

## For modders and maintainers
Legal: please see the LICENSE for what you can and can not do with this mod's source code and assets.
I would appreciate being contacted if you plan to do a major fork or continuation of this mod: I can be contacted by opening an issue on this Github page, or on discord under the @epicguru handle.

### How to build
Clone this repository into your Mods folder.
The recommended IDE is Rider, but Visual Studio should also work. Visual Studio Code (VS Code) will *NOT* work!
There is a seperate solution file and folder for each major Rimworld version, such as `1.4` and `1.5`.
Simply open the solution for the current version and build the entire solution (`Ctrl+Shift+B` will build everything).
There is no need to link up any assembly or project references, it is all done via NuGet packages.
All the assemblies will be put into the correct folders automatically.

### Creating new animations
See the [Animation Creation Guide](Source/AnimationTutorial/AnimationTutorial.md).
13 changes: 13 additions & 0 deletions Source/1.4/.idea/.idea.AnimationMod/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Source/1.4/.idea/.idea.AnimationMod/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Source/1.4/.idea/.idea.AnimationMod/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Source/1.4/.idea/.idea.AnimationMod/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Source/1.4/ThingGenerator/Tweaks/ItemTweakData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public ISweepProvider GetSweepProvider()
{
Core.Error($"Failed to create instance of ISweepProvider '{klass.FullName}':", e);
return null;
; }
}
}

cachedSweepProvider = instance;
Expand Down
41 changes: 23 additions & 18 deletions Source/1.5/AnimationMod/AnimDef.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Xml.Serialization;
using AM.AMSettings;
using AM.Data;
using AM.Idle;
using AM.RendererWorkers;
using AM.Reqs;
using AM.Sweep;
using JetBrains.Annotations;
using LudeonTK;
using RimWorld;
using UnityEngine;
using Verse;
using LudeonTK;

namespace AM;

Expand Down Expand Up @@ -72,7 +72,7 @@ public static void ReloadAllAnimations()
continue;

def.resolvedData = AnimData.Load(def.FullDataPath, false);
def.resolvedNonLethalData = File.Exists(def.FullNonLethalDataPath) ? AnimData.Load(def.FullNonLethalDataPath, false) : def.resolvedData;
def.resolvedNonLethalData = AnimData.Load(def.FullNonLethalDataPath, false) ?? def.resolvedData;
}
}

Expand Down Expand Up @@ -100,21 +100,29 @@ public virtual string FullDataPath
{
get
{
var mod = modContentPack;
if (mod == null)
string dataName = data.Trim();
if (dataName.EndsWith(".json"))
{
Core.Error($"This def '{defName}' has no modContentPack, so FullDataPath cannot be resolved! Returning relative path instead...");
return data;
dataName = dataName[..^5];
}

string relative = data.Trim();
if (string.IsNullOrWhiteSpace(new FileInfo(relative).Extension))
relative += ".json";
return AnimDataSourceManager.TryGetDataFilePath(dataName);
}
}
public virtual string FullNonLethalDataPath
{
get
{
string dataName = data.Trim();
if (dataName.EndsWith(".json"))
{
dataName = dataName[..^5];
}
dataName += "_NL";

return Path.Combine(mod.RootDir, "Animations", relative);
return AnimDataSourceManager.TryGetDataFilePath(dataName);
}
}
public virtual string FullNonLethalDataPath => FullDataPath.Replace(".json", "_NL.json");
public AnimData Data
{
get
Expand Down Expand Up @@ -214,11 +222,8 @@ public void SetDefaultSData()

protected virtual void ResolveData()
{
if (File.Exists(FullDataPath))
resolvedData = AnimData.Load(FullDataPath);

if (File.Exists(FullNonLethalDataPath))
resolvedNonLethalData = AnimData.Load(FullNonLethalDataPath);
resolvedData = AnimData.Load(FullDataPath);
resolvedNonLethalData = AnimData.Load(FullNonLethalDataPath);
}

public T TryGetAdditionalData<T>(string id, T defaultValue = default)
Expand Down Expand Up @@ -265,7 +270,7 @@ public override IEnumerable<string> ConfigErrors()

if (string.IsNullOrWhiteSpace(data))
yield return "Animation has no data path! Please specify the location of the data file using the data tag.";
else if (!File.Exists(FullDataPath))
else if (FullDataPath == null) // Means not found in the file system.
yield return $"Failed to find animation file at '{FullDataPath}'!";

if (type is AnimType.Execution or AnimType.Duel or AnimType.Idle && weaponFilter == null)
Expand Down
34 changes: 23 additions & 11 deletions Source/1.5/AnimationMod/Core.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
using AM.AMSettings;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using AM.AMSettings;
using AM.Data;
using AM.Hands;
using AM.Patches;
using AM.Retexture;
Expand All @@ -7,13 +16,6 @@
using ModRequestAPI;
using ModRequestAPI.Models;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;

Expand Down Expand Up @@ -162,7 +164,7 @@ private static void AddParser<T>(Func<string, T> func)
ParseHelper.Parsers<T>.Register(func);
}

private static void PatchVBE()
private static void PatchVanillaBackgroundsExpanded()
{
if (ModLister.GetActiveModWithIdentifier("vanillaexpanded.backgrounds") == null)
return;
Expand All @@ -187,7 +189,7 @@ private static async Task UploadMissingModData(IEnumerable<MissingModRequest> li
var client = new ModRequestClient();
await client.TryPostModRequests(list);
}

public Core(ModContentPack content) : base(content)
{
AddParsers();
Expand Down Expand Up @@ -222,11 +224,21 @@ public Core(ModContentPack content) : base(content)
AddLateLoadAction(true, "Applying settings...", Settings.PostLoadDefs);
AddLateLoadAction(true, "Matching textures with mods...", PreCacheAllRetextures);
AddLateLoadAction(true, "Loading weapon tweak data...", LoadAllTweakData);
AddLateLoadAction(true, "Patch VBE", PatchVBE);
AddLateLoadAction(true, "Patch VBE", PatchVanillaBackgroundsExpanded);
AddLateLoadAction(true, "Apply final patches", Patch_Verb_MeleeAttack_ApplyMeleeDamageToTarget.PatchAll);
AddLateLoadAction(true, "Cache gloves", HandUtility.DoInitialLoading);

AddLateLoadEvents();

// This needs to be done now, before defs are loaded.
try
{
AnimDataSourceManager.ScanForDataFiles();
}
catch (Exception e)
{
Error("Failed to scan for animation data files.", e);
}
}

private static void RegisterWeaponDefOverrides()
Expand Down
12 changes: 8 additions & 4 deletions Source/1.5/AnimationMod/Data/AnimData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ private static Mesh MakeMesh(Vector2 size, bool flipX, bool flipY)
tris[3] = 0;
tris[4] = 2;
tris[5] = 3;
Mesh mesh = new();
mesh.name = $"AM Mesh: {flipX}, {flipY}";
mesh.vertices = verts;
mesh.uv = (flipX && flipY) ? fxy : flipX ? fx : flipY ? fy : normal;
var mesh = new Mesh
{
name = $"AM Mesh: {flipX}, {flipY}",
vertices = verts,
uv = (flipX && flipY) ? fxy : flipX ? fx : flipY ? fy : normal
};
mesh.SetTriangles(tris, 0);
mesh.RecalculateNormals();
mesh.RecalculateBounds();
Expand All @@ -88,7 +90,9 @@ private static Mesh MakeMesh(Vector2 size, bool flipX, bool flipY)
public static AnimData Load(string filePath, bool allowFromCache = true, bool saveToCache = true)
{
if (filePath == null)
{
return null;
}

if (allowFromCache)
{
Expand Down
52 changes: 52 additions & 0 deletions Source/1.5/AnimationMod/Data/AnimDataSourceManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections.Generic;
using System.IO;
using Verse;

namespace AM.Data;

public static class AnimDataSourceManager
{
private static readonly Dictionary<string, string> dataNameToFilePath = new Dictionary<string, string>();

public static void ScanForDataFiles()
{
dataNameToFilePath.Clear();

var activeMods = LoadedModManager.RunningModsListForReading;
int modsWithDataCount = 0;
Core.Log($"Scanning {activeMods.Count} mods for animation data...");

foreach (var mod in activeMods)
{
string dir = mod.RootDir;

string expectedPath = Path.Combine(dir, "Animations");
if (!Directory.Exists(expectedPath))
{
continue;
}

string animFolderAbsolute = new FileInfo(expectedPath).FullName;
bool any = false;

foreach (string filePath in Directory.GetFiles(expectedPath, "*.json", SearchOption.AllDirectories))
{
string absolute = new FileInfo(filePath).FullName;
string relative = absolute[(animFolderAbsolute.Length + 1)..];
string relativeWithoutExtension = Path.GetFileNameWithoutExtension(relative);

dataNameToFilePath[relativeWithoutExtension] = absolute;
any = true;
}

if (any)
{
modsWithDataCount++;
}
}

Core.Log($"Found {modsWithDataCount} mod folders with animation data, total {dataNameToFilePath.Count} loadable files.");
}

public static string TryGetDataFilePath(string dataName) => dataNameToFilePath.GetValueOrDefault(dataName);
}
Binary file added Source/AnimationTutorial/AnimSaveFolder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Source/AnimationTutorial/AnimStarter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6e9cc5e

Please sign in to comment.