Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
reorganized some stuff + improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmical committed Jul 7, 2021
1 parent af36122 commit b6283d8
Show file tree
Hide file tree
Showing 42 changed files with 1,542 additions and 791 deletions.
71 changes: 0 additions & 71 deletions DebugPlugin/DebugPlugin.cs

This file was deleted.

73 changes: 0 additions & 73 deletions DebugPlugin/DebugPlugin.csproj

This file was deleted.

36 changes: 0 additions & 36 deletions DebugPlugin/Properties/AssemblyInfo.cs

This file was deleted.

6 changes: 0 additions & 6 deletions RogueLibs v3.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PluginBuildEvents", "Plugin
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RogueLibsCore.Test", "RogueLibsCore.Test\RogueLibsCore.Test.csproj", "{99ED3605-22DC-4E91-A9F0-790209CFE9E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DebugPlugin", "DebugPlugin\DebugPlugin.csproj", "{4EB71CF3-AD33-4B2F-B077-96E93E3C506E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -41,10 +39,6 @@ Global
{99ED3605-22DC-4E91-A9F0-790209CFE9E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99ED3605-22DC-4E91-A9F0-790209CFE9E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99ED3605-22DC-4E91-A9F0-790209CFE9E8}.Release|Any CPU.Build.0 = Release|Any CPU
{4EB71CF3-AD33-4B2F-B077-96E93E3C506E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4EB71CF3-AD33-4B2F-B077-96E93E3C506E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EB71CF3-AD33-4B2F-B077-96E93E3C506E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EB71CF3-AD33-4B2F-B077-96E93E3C506E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 12 additions & 4 deletions RogueLibsCore.Test/Smoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ public static void Test()
{
RogueLibs.CreateCustomTrait<Smoker>()
.WithName(new CustomNameInfo("Smoker"))
.WithDescription(new CustomNameInfo("Cough randomly, alerting any nearby enemies"))
.WithUnlock(new TraitUnlock { CharacterCreationCost = -3, });
.WithDescription(new CustomNameInfo("Randomly cough, alerting enemies"))
.WithUnlock(new TraitUnlock { CharacterCreationCost = -4, });

RogueLibs.CreateCustomName("Smoker_Cough1", "Dialogue", new CustomNameInfo("*Cough*"));
RogueLibs.CreateCustomName("Smoker_Cough2", "Dialogue", new CustomNameInfo("*Cough* *CouGH*"));
RogueLibs.CreateCustomName("Smoker_Cough3", "Dialogue", new CustomNameInfo("*coUGH* *COUgh*"));
}

public override void OnAdded() { }
public override void OnRemoved() { }
public override void OnAdded()
{
Owner.SetEndurance(Owner.enduranceStatMod - 1);
Owner.SetSpeed(Owner.speedStatMod - 1);
}
public override void OnRemoved()
{
Owner.SetEndurance(Owner.enduranceStatMod + 1);
Owner.SetSpeed(Owner.speedStatMod + 1);
}
public override void OnUpdated(TraitUpdatedArgs e)
{
e.UpdateDelay = 5f;
Expand Down
60 changes: 36 additions & 24 deletions RogueLibsCore/CustomName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public interface IName : IEnumerable<KeyValuePair<LanguageCode, string>>
}
public class CustomName : IName
{
static CustomName() => Languages = new ReadOnlyDictionary<string, LanguageCode>(languages);
internal CustomName(string name, string type, string english)
{
Name = name;
Expand Down Expand Up @@ -56,27 +55,6 @@ public string this[LanguageCode language]

public IEnumerator<KeyValuePair<LanguageCode, string>> GetEnumerator() => translations.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

private static readonly Dictionary<string, LanguageCode> languages = new Dictionary<string, LanguageCode>
{
["english"] = LanguageCode.English,
["spanish"] = LanguageCode.Spanish,
["schinese"] = LanguageCode.Chinese,
["german"] = LanguageCode.German,
["brazilian"] = LanguageCode.Brazilian,
["french"] = LanguageCode.French,
["russian"] = LanguageCode.Russian,
["koreana"] = LanguageCode.Korean,
};
public static ReadOnlyDictionary<string, LanguageCode> Languages { get; }
public static void RegisterLanguageCode(string languageId, LanguageCode code)
{
if (languageId is null) throw new ArgumentNullException(nameof(languageId));
if (languages.ContainsKey(languageId))
throw new ArgumentException($"The specified {nameof(languageId)} is already taken.", nameof(languageId));
RogueFramework.Logger.LogDebug($"Registered \"{languageId}\" language id ({(int)code})");
languages.Add(languageId, code);
}
}
public struct CustomNameInfo : IName
{
Expand Down Expand Up @@ -132,9 +110,43 @@ public enum LanguageCode
}
public static class LanguageService
{
static LanguageService()
{
Languages = new ReadOnlyDictionary<string, LanguageCode>(languages);
languageNames = languages.ToDictionary(e => e.Value, e => e.Key);
}
public static NameDB NameDB { get; internal set; }
public static LanguageCode Current { get; internal set; }
public static LanguageCode FallBack { get; internal set; }
public static LanguageCode FallBack { get; set; }

private static readonly Dictionary<string, LanguageCode> languages = new Dictionary<string, LanguageCode>
{
["english"] = LanguageCode.English,
["spanish"] = LanguageCode.Spanish,
["schinese"] = LanguageCode.Chinese,
["german"] = LanguageCode.German,
["brazilian"] = LanguageCode.Brazilian,
["french"] = LanguageCode.French,
["russian"] = LanguageCode.Russian,
["koreana"] = LanguageCode.Korean,
};
private static readonly Dictionary<LanguageCode, string> languageNames;
public static ReadOnlyDictionary<string, LanguageCode> Languages { get; }

public static string GetLanguageName(LanguageCode code)
=> languageNames.TryGetValue(code, out string name) ? name : null;
public static void RegisterLanguageCode(string languageName, LanguageCode code)
{
if (languageName is null) throw new ArgumentNullException(nameof(languageName));
if (languages.ContainsKey(languageName))
throw new ArgumentException($"The specified {nameof(languageName)} is already taken.", nameof(languageName));
RogueFramework.Logger.LogDebug($"Registered \"{languageName}\" language ({(int)code})");
languages.Add(languageName, code);
languageNames.Add(code, languageName);
}

public static string GetCurrent(this IName name) => name[Current];
public static string GetCurrentOrDefault(this IName name) => name[Current] ?? name[FallBack];
}
public interface INameProvider
{
Expand All @@ -149,7 +161,7 @@ public void GetName(string name, string type, ref string result)
if (name != null && type != null
&& CustomNames.TryGetValue(type, out Dictionary<string, CustomName> category)
&& category.TryGetValue(name, out CustomName customName))
result = customName[LanguageService.Current] ?? customName[LanguageService.FallBack];
result = customName.GetCurrentOrDefault();
}
public CustomName AddName(string name, string type, CustomNameInfo info)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public class EffectUpdatedArgs : EventArgs
}
public sealed class CustomEffectFactory : HookFactoryBase<StatusEffect>
{
private readonly Dictionary<string, ItemEntry> effectsDict = new Dictionary<string, ItemEntry>();
private readonly Dictionary<string, EffectEntry> effectsDict = new Dictionary<string, EffectEntry>();
public override bool TryCreate(StatusEffect instance, out IHook<StatusEffect> hook)
{
if (instance != null && effectsDict.TryGetValue(instance.statusEffectName, out ItemEntry entry))
if (instance != null && effectsDict.TryGetValue(instance.statusEffectName, out EffectEntry entry))
{
hook = entry.Initializer();
if (hook is CustomEffect custom)
Expand All @@ -61,11 +61,11 @@ public override bool TryCreate(StatusEffect instance, out IHook<StatusEffect> ho
public EffectInfo AddEffect<T>() where T : CustomEffect, new()
{
EffectInfo info = EffectInfo.Get<T>();
effectsDict.Add(info.Name, new ItemEntry { Initializer = () => new T(), EffectInfo = info });
effectsDict.Add(info.Name, new EffectEntry { Initializer = () => new T(), EffectInfo = info });
return info;
}

private struct ItemEntry
private struct EffectEntry
{
public Func<IHook<StatusEffect>> Initializer;
public EffectInfo EffectInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public sealed class EffectInfo
{
public string Name { get; }
public EffectLimitations Limitations { get; }
public bool RemoveOnDeath => (Limitations & EffectLimitations.RemoveOnDeath) != 0;
public bool RemoveOnKnockOut => (Limitations & EffectLimitations.RemoveOnKnockOut) != 0;
public bool RemoveOnNextLevel => (Limitations & EffectLimitations.RemoveOnNextLevel) != 0;
public bool RemoveOnDeath { get; }
public bool RemoveOnKnockOut { get; }
public bool RemoveOnNextLevel { get; }

private static readonly Dictionary<Type, EffectInfo> infos = new Dictionary<Type, EffectInfo>();
public static EffectInfo Get(Type type) => infos.TryGetValue(type, out EffectInfo info) ? info : (infos[type] = new EffectInfo(type));
Expand All @@ -22,8 +22,15 @@ private EffectInfo(Type type)
{
if (!typeof(CustomEffect).IsAssignableFrom(type))
throw new ArgumentException($"The specified {nameof(type)} is not a {nameof(CustomEffect)}!", nameof(type));
EffectNameAttribute attr = type.GetCustomAttribute<EffectNameAttribute>();

EffectNameAttribute attr = type.GetCustomAttributes<EffectNameAttribute>().FirstOrDefault();
Name = attr?.Name ?? type.Name;

EffectParametersAttribute parsAttr = type.GetCustomAttributes<EffectParametersAttribute>().FirstOrDefault();
Limitations = parsAttr?.Limitations ?? EffectLimitations.Default;
RemoveOnDeath = (Limitations & EffectLimitations.RemoveOnDeath) != 0;
RemoveOnKnockOut = (Limitations & EffectLimitations.RemoveOnKnockOut) != 0;
RemoveOnNextLevel = (Limitations & EffectLimitations.RemoveOnNextLevel) != 0;
}
}
[AttributeUsage(AttributeTargets.Class)]
Expand All @@ -36,7 +43,7 @@ public class EffectNameAttribute : Attribute
public class EffectParametersAttribute : Attribute
{
public EffectLimitations Limitations { get; }
public EffectParametersAttribute(EffectLimitations limitations = EffectLimitations.RemoveOnDeath) => Limitations = limitations;
public EffectParametersAttribute(EffectLimitations limitations = EffectLimitations.Default) => Limitations = limitations;
}
[Flags]
public enum EffectLimitations
Expand All @@ -47,6 +54,6 @@ public enum EffectLimitations
RemoveOnKnockOut = 1 << 1,
RemoveOnNextLevel = 1 << 2,

Default = RemoveOnDeath
Default = RemoveOnDeath,
}
}
Loading

0 comments on commit b6283d8

Please sign in to comment.