Skip to content

Commit

Permalink
Merge pull request #132 from Garrakx/wip-43
Browse files Browse the repository at this point in the history
Release version 43
  • Loading branch information
Garrakx committed Mar 23, 2022
2 parents b05edb2 + 1a1d385 commit 0135b25
Show file tree
Hide file tree
Showing 12 changed files with 841 additions and 164 deletions.
65 changes: 34 additions & 31 deletions Custom-Regions/Creatures/FlyGraphicsHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,45 +132,48 @@ private static void Fly_Update(On.Fly.orig_Update orig, Fly self, bool eu)
{
return;
}

if (!self.dead)
try
{
FlyFields.GetField(self).flickeringFac = 1f;
FlyFields.GetField(self).flickerDuration = Mathf.Lerp(10f, 30f, UnityEngine.Random.value);
if (UnityEngine.Random.value < 0.1f)

if (!self.dead)
{
FlyFields.GetField(self).flicker = Mathf.Max(FlyFields.GetField(self).flicker, UnityEngine.Random.value);
FlyFields.GetField(self).flickeringFac = 1f;
FlyFields.GetField(self).flickerDuration = Mathf.Lerp(10f, 30f, UnityEngine.Random.value);
if (UnityEngine.Random.value < 0.1f)
{
FlyFields.GetField(self).flicker = Mathf.Max(FlyFields.GetField(self).flicker, UnityEngine.Random.value);
}
}
}

if (FlyFields.GetField(self).light != null)
{
if (FlyFields.GetField(self).light.slatedForDeletetion || self.room.Darkness(self.mainBodyChunk.pos) == 0f || self.dead || self.Stunned)
if (FlyFields.GetField(self).light != null)
{
FlyFields.GetField(self).light = null;
if (FlyFields.GetField(self).light.slatedForDeletetion || self.room.Darkness(self.mainBodyChunk.pos) == 0f || self.dead || self.Stunned)
{
FlyFields.GetField(self).light = null;
}
else
{
FlyFields.GetField(self).sin += 1f / Mathf.Lerp(20f, 80f, UnityEngine.Random.value);
float sin = FlyFields.GetField(self).sin;
FlyFields.GetField(self).light.stayAlive = true;
FlyFields.GetField(self).light.setPos = new UnityEngine.Vector2?(self.bodyChunks[0].pos);
FlyFields.GetField(self).light.setRad = new float?(60f + 20f * UnityEngine.Mathf.Sin(sin * 3.14159274f * 2f));
FlyFields.GetField(self).light.setAlpha = new float?(0.55f - 0.1f * UnityEngine.Mathf.Sin(sin * 3.14159274f * 2f));
// float customColorHue = customColor == null ? 0.6f : CRExtras.RGB2HSL(customColor ?? UnityEngine.Color.white).hue;
HSLColor color = CRExtras.RGB2HSL(customColor ?? UnityEngine.Color.white);
FlyFields.GetField(self).light.color = RWCustom.Custom.HSL2RGB(color.hue, color.saturation, color.lightness - 0.2f * FlyFields.GetField(self).flicker);
}
}
else
else if (self.room.Darkness(self.bodyChunks[0].pos) > 0f && !self.dead)
{
FlyFields.GetField(self).sin += 1f / Mathf.Lerp(20f, 80f, UnityEngine.Random.value);
float sin = FlyFields.GetField(self).sin;
FlyFields.GetField(self).light.stayAlive = true;
FlyFields.GetField(self).light.setPos = new UnityEngine.Vector2?(self.bodyChunks[0].pos);
FlyFields.GetField(self).light.setRad = new float?(60f + 20f * UnityEngine.Mathf.Sin(sin * 3.14159274f * 2f));
FlyFields.GetField(self).light.setAlpha = new float?(0.55f - 0.1f * UnityEngine.Mathf.Sin(sin * 3.14159274f * 2f));
// float customColorHue = customColor == null ? 0.6f : CRExtras.RGB2HSL(customColor ?? UnityEngine.Color.white).hue;
HSLColor color = CRExtras.RGB2HSL(customColor ?? UnityEngine.Color.white);
FlyFields.GetField(self).light.color = RWCustom.Custom.HSL2RGB(color.hue, color.saturation, color.lightness - 0.2f * FlyFields.GetField(self).flicker);
}
}
else if (self.room.Darkness(self.bodyChunks[0].pos) > 0f && !self.dead)
{
Mod.CustomWorldMod.Log($"Creating light for [{self.abstractCreature.creatureTemplate}-{self.abstractPhysicalObject.ID.number}]",
false, CustomWorldMod.DebugLevel.FULL);
Mod.CustomWorldMod.Log($"Creating light for [{self.abstractCreature.creatureTemplate}-{self.abstractPhysicalObject.ID.number}]",
false, CustomWorldMod.DebugLevel.FULL);

FlyFields.GetField(self).light = new LightSource(self.bodyChunks[0].pos, false, UnityEngine.Color.yellow, self);
FlyFields.GetField(self).light.requireUpKeep = true;
self.room.AddObject(FlyFields.GetField(self).light);
}
FlyFields.GetField(self).light = new LightSource(self.bodyChunks[0].pos, false, UnityEngine.Color.yellow, self);
FlyFields.GetField(self).light.requireUpKeep = true;
self.room.AddObject(FlyFields.GetField(self).light);
}
} catch { /* I am lazy, sorry in advance */ }
}

// scrapped
Expand Down
9 changes: 9 additions & 0 deletions Custom-Regions/Custom-Regions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>default</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>..\References\BepInEx.dll</HintPath>
</Reference>
<Reference Include="ConfigMachine, Version=1.4.4.4, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\ConfigMachine.dll</HintPath>
Expand All @@ -43,6 +47,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\EnumExtender.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil, Version=0.10.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="MonoMod, Version=18.6.0.33005, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\MonoMod.exe</HintPath>
Expand Down Expand Up @@ -77,6 +85,7 @@
<Compile Include="Creatures\ScavengerAbstractAIHook.cs" />
<Compile Include="CustomMenu\PauseMenuHook.cs" />
<Compile Include="DevInterface\TriggersPageHook.cs" />
<Compile Include="Mod\API.cs" />
<Compile Include="Music\MultiplayerDJHook.cs" />
<Compile Include="Arena\MultiplayerUnlocksHook.cs" />
<Compile Include="Creatures\BigEelHook.cs" />
Expand Down
28 changes: 28 additions & 0 deletions Custom-Regions/CustomMenu/SlugcatSelectMenuHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ private static void SlugcatSelectMenu_ctor(On.Menu.SlugcatSelectMenu.orig_ctor o

self.pages[0].subObjects.Add(menuLabel);
}
if (CustomWorldMod.missingDependencies.Count > 0)
{
string errorText = CustomWorldMod.Translate($"You have missing dependencies, please reinstall the following packs: " +
$"[{string.Join(", ", CustomWorldMod.missingDependencies.Keys.ToArray())}]");

MenuLabel menuLabel = new MenuLabel(self, self.pages[0],
errorText,
new Vector2(self.manager.rainWorld.options.ScreenSize.x * 0.5f, self.manager.rainWorld.options.ScreenSize.y * 0.95f),
new Vector2(0, 0), true);

menuLabel.label.color = new Color((108f / 255f), 0.001f, 0.001f);
menuLabel.label.alignment = FLabelAlignment.Center;

self.pages[0].subObjects.Add(menuLabel);

// Second line

MenuLabel menuLabel2 = new MenuLabel(self, self.pages[0],
$"Missing dependencies: [{string.Join(", ", CustomWorldMod.missingDependencies.Values.SelectMany(i => i).Distinct().ToArray())}]",
new Vector2(self.manager.rainWorld.options.ScreenSize.x * 0.5f, self.manager.rainWorld.options.ScreenSize.y * 0.91f),
new Vector2(0, 0), false);

menuLabel2.label.color = new Color((108f / 255f), 0.001f, 0.001f);
menuLabel2.label.alignment = FLabelAlignment.Center;

self.pages[0].subObjects.Add(menuLabel2);

}
}

/// <summary>
Expand Down
122 changes: 122 additions & 0 deletions Custom-Regions/Mod/API.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CustomRegions.Mod
{
public static class API
{

public class RegionInfo
{
/// <summary>
/// Pack name, empty used for vanilla.
/// </summary>
public string PackName { get; internal set; }

public string RegionID { get; internal set; }
/// <summary>
/// World lines from world_XX.txt file.
/// </summary>
public List<string> Lines { get; internal set; }

public bool Vanilla { get; internal set; } = false;
}

public delegate void RegionPreprocessor(RegionInfo info);

/// <summary>
/// Add region pre processor to the list.
/// </summary>
/// <param name="pre"> Method which filters or modifies API.RegionInfo</param>
public static void AddRegionPreprocessor(RegionPreprocessor pre)
{
CustomWorldMod.Log($"Adding preprocessor! [{pre.Method.Name}]");
if (CustomWorldMod.regionPreprocessors == null)
{
CustomWorldMod.Log("Initiation region preprocessors from other mod...");
CustomWorldMod.regionPreprocessors = new List<RegionPreprocessor>();
}
if (CustomWorldMod.regionPreprocessors.Contains(pre))
{
CustomWorldMod.Log($"Adding duplicated preprocessor! [{pre.Method.Name}]", true);
return;
}
CustomWorldMod.regionPreprocessors.Add(pre);
}

/// <summary>
/// Dictionary with all installed region packs, where the Key is the region pack name and the value is a struct with its information.
/// </summary>
public static Dictionary<string, CustomWorldStructs.RegionPack> InstalledPacks { get => CustomWorldMod.installedPacks; }

/// <summary>
/// Dictionary with activated region packs, where the Key is the region pack name and the value is the folder.
/// </summary>
public static Dictionary<string, string> ActivatedPacks { get => CustomWorldMod.activatedPacks; }

public static List<CustomWorldStructs.PackDependency> InstalledDependencies { get => CustomWorldMod.installedDependencies; }

/// <summary>
/// List containing unused dependencies, no region pack is using them so they can be disabled.
/// </summary>
public static List<CustomWorldStructs.PackDependency> UnusedDependencies { get => CustomWorldMod.installedDependencies.FindAll(x=>x.usedBy.Count() == 0); }

/// <summary>
/// Indicates wheter CRS is currently downloading a pack or not.
/// </summary>
public static bool DownloadInProcess { get => (CustomWorldMod.scripts.Count > 0 && CustomWorldMod.scripts.FindAll(x => x is PackDownloader).Count != 0); }

/// <summary>
/// Indicates wheter BepInEx is installed or not.
/// </summary>
public static bool UsingBepinex { get => CustomWorldMod.usingBepinex; }

/// <summary>
/// Indicates wheter Realm modloader is installed or not.
/// </summary>
public static bool UsingRealm { get => CustomWorldMod.usingRealm; }


/// <summary>
/// Enables/Disables the provided pack. Make sure to check if there is a download in process first
/// </summary>
/// <param name="packName"></param>
public static void DisableEnablePack(string packName)
{
if (DownloadInProcess) { throw new AccessViolationException("Mod tried to disable a pack while CRS was downloading a pack... Use the API.DownloadInProcess bool"); }

CRExtras.DisableTogglePack(packName);
}

/// <summary>
/// Forces CRS to reset, make sure you know what you are doing. Check for API.DownloadInProcess first.
/// </summary>
public static void ForceReloadCRS()
{
if (DownloadInProcess) { throw new AccessViolationException("Mod tried to reset CRS while CRS was downloading a pack... Use the API.DownloadInProcess bool"); }
CustomWorldMod.LoadCustomWorldResources();
}

/// <summary>
/// Builds a folder path. It will return a specific file if specified, otherwise it will end with backslash. Can also be used to navigate vanilla folders.
/// </summary>
/// <param name="regionPackFolder"> Folder name of the region pack. Use null for vanilla path. </param>
/// <param name="folderName"> Folder desired to build the path to (with spaces or underscore)</param>
/// <param name="regionID"> Region ID needed for Rooms or RegionID folder.</param>
/// <param name="file"> If specified, it will append a file after the folder path.</param>
/// <param name="folder"> If specified, it will append an additional folder path.</param>
/// <returns>Path built.</returns>
public static string BuildPath(string regionPackFolder, string folderName, string regionID = null,
string file = null, string folder = null, bool includeRoot = true)
{
CRExtras.CustomFolder folderEnum;
string folderNameEdited = folderName.Replace(" ", "_");
try { folderEnum = (CRExtras.CustomFolder)Enum.Parse(typeof(CRExtras.CustomFolder), folderNameEdited); }
catch ( Exception e) { CustomWorldMod.Log($"Folder [{folderName}] not supported by CRS, did you make a typo? {e}", true); return null; }

return CRExtras.BuildPath(regionPackFolder, folderEnum, regionID, file, folder, includeRoot);
}
}
}
14 changes: 12 additions & 2 deletions Custom-Regions/Mod/CRExtras.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace CustomRegions.Mod
{


public static class CRExtras
{
public enum CustomFolder
Expand All @@ -22,6 +21,7 @@ public enum CustomFolder
Assets,
World,
Levels,
PackDependencies,
// Depth 2.1
Gates_Shelters,
Gates,
Expand Down Expand Up @@ -51,6 +51,16 @@ public enum CustomFolder

}

public static void DisableTogglePack(string packName)
{
// Disable

CustomWorldStructs.RegionPack pack = CustomWorldMod.installedPacks[packName];
pack.activated = !pack.activated;
CustomWorldMod.SerializePackInfoJSON(CRExtras.BuildPath(pack.folderName, CRExtras.CustomFolder.None, file: "packInfo.json"), pack);
CustomWorldMod.LoadCustomWorldResources();
}


public static CustomWorldStructs.ProcessedThumbnail ProccessThumbnail(Texture2D oldTex, byte[] data, string packName)//, bool activated, bool raindb)
{
Expand Down Expand Up @@ -163,12 +173,12 @@ public static CustomWorldStructs.ProcessedThumbnail ProccessThumbnail(Texture2D
string recursivePath = string.Empty;
switch (folderEnum)
{

// Depth 1
case CustomFolder.None:
case CustomFolder.Assets:
case CustomFolder.Levels:
case CustomFolder.World:
case CustomFolder.PackDependencies:
if (includeRoot)
{
// Rain World/
Expand Down
Loading

0 comments on commit 0135b25

Please sign in to comment.