Skip to content

Commit

Permalink
day one patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionmeow authored Aug 7, 2022
2 parents 80d8af5 + 7207b1f commit 89eee2b
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 36 deletions.
4 changes: 2 additions & 2 deletions SRML/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyVersion("0.2.1.0")]
[assembly: AssemblyFileVersion("0.2.1.0")]
13 changes: 13 additions & 0 deletions SRML/SR/BindingRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ public static PlayerAction RegisterBindedAction(string name)
return act;
}

/// <summary>
/// Creates and registers a <see cref="PlayerAction"/>, adds it into the options UI, and adds a translation.
/// </summary>
/// <param name="name">The name of the action.</param>
/// <param name="translation">The translated name of the action.</param>
/// <returns>The created action</returns>
public static PlayerAction RegisterBindedTranslatedAction(string name, string translation)
{
PlayerAction act = RegisterBindedAction(name);
TranslationPatcher.AddUITranslation("key." + name.ToLower(), translation);
return act;
}

/// <summary>
/// Check if an action is modded.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions SRML/SR/DroneRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static IEnumerable<DroneMetadata> GetMetadatas()
HashSet<DroneMetadata> metadataCache = new HashSet<DroneMetadata>();
foreach(var v in Gadget.DRONE_CLASS)
{
if (!context.LookupDirector.gadgetDefinitionDict.ContainsKey(v)) continue;

var data = context.LookupDirector.GetGadgetDefinition(v).prefab.GetComponentInChildren<DroneGadget>().metadata;
if (metadataCache.Add(data)) yield return data;
}
Expand Down
26 changes: 15 additions & 11 deletions SRML/SR/GadgetCategorization.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
using System;
using System.Collections.Generic;

namespace SRML.SR
{
[AttributeUsage(AttributeTargets.Field)]
public class GadgetCategorization : Attribute
{
public Rule rules;
public static List<Gadget.Id> doNotAutoCategorize = new List<Gadget.Id>();

public GadgetCategorization(Rule rules) => this.rules = rules;

public Rule rules;

[Flags]
public enum Rule
{
MISC = 0,
EXTRACTOR = 1,
TELEPORTER = 2,
WARP_DEPOT = 4,
ECHO_NET = 8,
LAMP = 16,
FASHION_POD = 32,
SNARE = 64,
DECO = 128,
DRONE = 256
NONE = 0,
MISC = 1,
EXTRACTOR = 2,
TELEPORTER = 4,
WARP_DEPOT = 8,
ECHO_NET = 16,
LAMP = 32,
FASHION_POD = 64,
SNARE = 128,
DECO = 256,
DRONE = 512
}
}
}
3 changes: 1 addition & 2 deletions SRML/SR/GadgetRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public static void Categorize(this Gadget.Id id, GadgetCategorization.Rule rule)
/// Remove all instances of an <see cref="Gadget.Id"/> from every class in <see cref="Gadget"/>
/// </summary>
/// <param name="id"></param>
/// <param name="rule"></param>
public static void Uncategorize(this Gadget.Id id)
{
Gadget.DECO_CLASS.Remove(id);
Expand All @@ -119,7 +118,7 @@ internal static void CategorizeAllIds()
{
if (rules.ContainsKey(id))
CategorizeId(id, rules[id]);
else
else if (!GadgetCategorization.doNotAutoCategorize.Contains(id))
CategorizeId(id);
}
}
Expand Down
4 changes: 3 additions & 1 deletion SRML/SR/IdentifiableCategorization.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System;
using System.Collections.Generic;

namespace SRML.SR
{
[AttributeUsage(AttributeTargets.Field)]
public class IdentifiableCategorization : Attribute
{
public Rule rules;
public static List<Identifiable.Id> doNotAutoCategorize = new List<Identifiable.Id>();

public IdentifiableCategorization(Rule rules) => this.rules = rules;
public Rule rules;

[Flags]
public enum Rule
Expand Down
2 changes: 1 addition & 1 deletion SRML/SR/IdentifiableRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal static void CategorizeAllIds()
{
if (rules.TryGetValue(id, out IdentifiableCategorization.Rule rule))
CategorizeId(id, rule);
else
else if (!IdentifiableCategorization.doNotAutoCategorize.Contains(id))
CategorizeId(id);

if (!FoodGroupRegistry.alreadyRegistered.Contains(id))
Expand Down
34 changes: 31 additions & 3 deletions SRML/SR/SlimeRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void RegisterSlimeDefinition(SlimeDefinition definition, bool refr
break;
}

if (definition.IsLargo && definition.BaseSlimes != null)
if (definition.IsLargo && definition.BaseSlimes != null && definition.BaseSlimes.Length > 1)
{
if (definition.BaseSlimes[0].Diet.ProducePlorts() && definition.BaseSlimes[1].Diet.ProducePlorts())
definitions.largoDefinitionByBasePlorts.AddOrChange(new SlimeDefinitions.PlortPair(definition.BaseSlimes[0].Diet.Produces[0], definition.BaseSlimes[1].Diet.Produces[0]), definition);
Expand Down Expand Up @@ -210,7 +210,12 @@ public static SlimeDefinition CombineDefinitions(Identifiable.Id id, SlimeDefini
slimeDefinition.Sounds = ((props & (LargoProps.SWAP_SOUNDS)) != 0) ? slime2.Sounds : slime1.Sounds;

slimeDefinition.LoadLargoDiet();
slimeDefinition.LoadFavoriteToysFromBaseSlimes();

slimeDefinition.FavoriteToys = new Identifiable.Id[0];
if (slime1.FavoriteToys != null)
slimeDefinition.FavoriteToys = slimeDefinition.FavoriteToys.Union(slime1.FavoriteToys).ToArray();
if (slime2.FavoriteToys != null)
slimeDefinition.FavoriteToys = slimeDefinition.FavoriteToys.Union(slime2.FavoriteToys).ToArray();

if ((props & (LargoProps.PREVENT_SLIME1_EATMAP_TRANSFORM)) != 0)
preventLargoTransforms.Add(new KeyValuePair<Identifiable.Id, Identifiable.Id>(slime1.IdentifiableId, id));
Expand Down Expand Up @@ -277,7 +282,26 @@ public static GameObject CombineSlimePrefabs(SlimeDefinition def)
/// <param name="slime1SSProps">The properties controlling the base Secret Style and the addon normal <see cref="SlimeAppearance"/>s are combined.</param>
/// <param name="slime2SSProps">The properties controlling the base normal and the addon Secret Style <see cref="SlimeAppearance"/>s are combined.</param>
/// <param name="slime12SSProps">The properties controlling the base Secret Style and the addon Secret Style <see cref="SlimeAppearance"/>s are combined.</param>
public static void CraftLargo(Identifiable.Id largoId, Identifiable.Id slime1, Identifiable.Id slime2, LargoProps props, LargoProps slime1SSProps = LargoProps.NONE, LargoProps slime2SSProps = LargoProps.NONE, LargoProps slime12SSProps = LargoProps.NONE)
public static void CraftLargo(Identifiable.Id largoId, Identifiable.Id slime1, Identifiable.Id slime2,
LargoProps props, LargoProps slime1SSProps = LargoProps.NONE, LargoProps slime2SSProps = LargoProps.NONE, LargoProps slime12SSProps = LargoProps.NONE) =>
CraftLargo(largoId, slime1, slime2, props, out var largoDefinition, out var largoAppearance, out var largoObject, slime1SSProps, slime2SSProps, slime12SSProps);

/// <summary>
/// Combines two slimes into a largo.
/// </summary>
/// <param name="largoId">The <see cref="Identifiable.Id"/> belonging to the resulting largo.</param>
/// <param name="slime1">The <see cref="Identifiable.Id"/> belonging to the base slime.</param>
/// <param name="slime2">The <see cref="Identifiable.Id"/> belonging to the addon slime.</param>
/// <param name="props">The properties controlling the way the slimes are combined.</param>
/// <param name="slime1SSProps">The properties controlling the base Secret Style and the addon normal <see cref="SlimeAppearance"/>s are combined.</param>
/// <param name="slime2SSProps">The properties controlling the base normal and the addon Secret Style <see cref="SlimeAppearance"/>s are combined.</param>
/// <param name="slime12SSProps">The properties controlling the base Secret Style and the addon Secret Style <see cref="SlimeAppearance"/>s are combined.</param>
/// <param name="largoDefinition">The <see cref="SlimeDefinition"/> of the created largo.</param>
/// <param name="largoAppearance">The <see cref="SlimeAppearance"/> of the created largo.</param>
/// <param name="largoObject">The <see cref="GameObject"/> of the created largo.</param>
public static void CraftLargo(Identifiable.Id largoId, Identifiable.Id slime1, Identifiable.Id slime2, LargoProps props,
out SlimeDefinition largoDefinition, out SlimeAppearance largoAppearance, out GameObject largoObject,
LargoProps slime1SSProps = LargoProps.NONE, LargoProps slime2SSProps = LargoProps.NONE, LargoProps slime12SSProps = LargoProps.NONE)
{
SlimeDefinition slime1Def = slime1.GetSlimeDefinition();
SlimeDefinition slime2Def = slime2.GetSlimeDefinition();
Expand Down Expand Up @@ -316,6 +340,10 @@ public static void CraftLargo(Identifiable.Id largoId, Identifiable.Id slime1, I
LookupRegistry.RegisterIdentifiablePrefab(largoOb);
RegisterAppearance(def, app);
RegisterSlimeDefinition(def);

largoDefinition = def;
largoAppearance = app;
largoObject = largoOb;
}

internal static void InheritStripe(this Material mat, Material inherited, Shader shader = null)
Expand Down
20 changes: 15 additions & 5 deletions SRML/SRModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,21 @@ internal static ICollection<SRMod> GetMods()

static SRMod AddMod(ProtoMod modInfo, Type entryType)
{
IModEntryPoint entryPoint = (IModEntryPoint)Activator.CreateInstance(entryType);
if (entryPoint is ModEntryPoint) ((ModEntryPoint)entryPoint).ConsoleInstance = new Console.Console.ConsoleInstance(modInfo.name);
var newmod = new SRMod(modInfo.ToModInfo(), entryPoint, modInfo.path);
Mods.Add(modInfo.id, newmod);
return newmod;
try
{
IModEntryPoint entryPoint = (IModEntryPoint)Activator.CreateInstance(entryType);

if (entryPoint is ModEntryPoint)
((ModEntryPoint)entryPoint).ConsoleInstance = new Console.Console.ConsoleInstance(modInfo.name);

var newmod = new SRMod(modInfo.ToModInfo(), entryPoint, modInfo.path);
Mods.Add(modInfo.id, newmod);
return newmod;
}
catch (Exception e)
{
throw new Exception($"Error initializing '{modInfo.id}'!: {e}");
}
}

internal static void PreLoadMods()
Expand Down
8 changes: 7 additions & 1 deletion SRML/Utils/Enum/EnumHolderAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ namespace SRML.Utils.Enum
{
public class EnumHolderAttribute : Attribute
{
public bool shouldCategorize = true;

public EnumHolderAttribute()
{

}

public EnumHolderAttribute(bool shouldCategorize)
{
this.shouldCategorize = shouldCategorize;
}
}
}
34 changes: 26 additions & 8 deletions SRML/Utils/Enum/EnumHolderResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using System.Text;
using UnityEngine;
using SRML.SR.Utils;

namespace SRML.Utils.Enum
{
Expand All @@ -17,6 +18,8 @@ public static void RegisterAllEnums(Module module)
{
if (type.GetCustomAttributes(true).Any((x) => x is EnumHolderAttribute))
{
EnumHolderAttribute enumHolder = type.GetCustomAttribute<EnumHolderAttribute>();

foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public |
BindingFlags.NonPublic))
{
Expand All @@ -26,22 +29,37 @@ public static void RegisterAllEnums(Module module)
{
var newVal = EnumPatcher.GetFirstFreeValue(field.FieldType);
EnumPatcher.AddEnumValueWithAlternatives(field.FieldType, newVal, field.Name);
field.SetValue(null,newVal);
field.SetValue(null, newVal);
}
else
EnumPatcher.AddEnumValueWithAlternatives(field.FieldType,field.GetValue(null),field.Name);
EnumPatcher.AddEnumValueWithAlternatives(field.FieldType, field.GetValue(null), field.Name);

if (field.FieldType == typeof(Identifiable.Id))
{
foreach (var att in field.GetCustomAttributes())
if (att is IdentifiableCategorization)
((Identifiable.Id)field.GetValue(null)).Categorize(((IdentifiableCategorization)att).rules);
if (enumHolder.shouldCategorize)
{
foreach (var att in field.GetCustomAttributes())
if (att is IdentifiableCategorization)
((Identifiable.Id)field.GetValue(null)).Categorize(((IdentifiableCategorization)att).rules);
}
else
{
IdentifiableCategorization.doNotAutoCategorize.Add((Identifiable.Id)field.GetValue(null));
}
}

if (field.FieldType == typeof(Gadget.Id))
{
foreach (var att in field.GetCustomAttributes())
if (att is GadgetCategorization)
((Gadget.Id)field.GetValue(null)).Categorize(((GadgetCategorization)att).rules);
if (enumHolder.shouldCategorize)
{
foreach (var att in field.GetCustomAttributes())
if (att is GadgetCategorization)
((Gadget.Id)field.GetValue(null)).Categorize(((GadgetCategorization)att).rules);
}
else
{
IdentifiableCategorization.doNotAutoCategorize.Add((Identifiable.Id)field.GetValue(null));
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions SRMLInstaller/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ string GetAlternateRoot()
void SendFilesOver(bool canLog = true)
{
foreach(var file in Directory.GetFiles(GetAlternateRoot()))
{
File.Delete(file);
}

foreach (var v in Assembly.GetExecutingAssembly().GetManifestResourceNames().Where((x) =>
x.Length > embeddedResourceProject.Length &&
Expand Down

0 comments on commit 89eee2b

Please sign in to comment.