Skip to content

Commit

Permalink
3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAnsuz committed Mar 1, 2024
1 parent c5b8de5 commit 10921fb
Show file tree
Hide file tree
Showing 409 changed files with 55,182 additions and 5,547 deletions.
49 changes: 46 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
/packages/
/.vs/
/obj/
*/.vs/
/.dist/
/bin/
*/obj/
*/bin/
.vsconfig
*/Temp/
Release
Resources/Github/Wiki/.*

# Libraries
Amrv.ConfigurableCompany/libs/*

# Unity
Unity*/[Ll]ibrary/
Unity*/[Tt]emp/
Unity*/[Oo]bj/
Unity*/[Bb]uild/
Unity*/[Bb]uilds/
Unity*/[Ll]ogs/
Unity*/[Uu]ser[Ss]ettings/

Unity*/[Mm]emoryCaptures/
Unity*/[Rr]ecordings/

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.aab
*.unitypackage
*.app

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
Unity*/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
Unity*/[Aa]ssets/[Ss]treamingAssets/aa.meta
Unity*/[Aa]ssets/[Ss]treamingAssets/aa/*
130 changes: 130 additions & 0 deletions Amrv.ConfigurableCompany/API/CCategory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using Amrv.ConfigurableCompany.Core;
using Amrv.ConfigurableCompany.Core.Config;
using System.Collections.Generic;
using UnityEngine;

namespace Amrv.ConfigurableCompany.API
{
public sealed class CCategory
{
private static CCategory _defaultCategory;

public static CCategory Default
{
get
{
_defaultCategory ??= new CCategoryBuilder()
{
ID = "configurable-company_category_default",
Color = new Color32(214, 90, 24, 255),
HideIfEmpty = true,
Name = "Configurations",
Page = CPage.Default
};

return _defaultCategory;
}
}

private static readonly Dictionary<string, CCategory> _categories = [];

/// <summary>
/// A dictionary-like storage containing all the generated categories
/// </summary>
public static readonly IDStorage<CCategory> Storage = new(_categories);

/// <summary>
/// Get the standard builder to generate a new category
/// </summary>
/// <returns>The builder for a new category</returns>
public static CCategoryBuilder Builder() => new();

private readonly Dictionary<string, CSection> _sections;

/// <summary>
/// A dictionary-like storage containing all the sections attached to this category
/// </summary>
public readonly IDStorage<CSection> Sections;

internal void AddSection(CSection section) => _sections.Add(section.ID, section);
internal void RemoveSection(CSection section) => _sections.Remove(section.ID);

private readonly Dictionary<string, CConfig> _configs;

/// <summary>
/// A dictionary-like storage containing all the configurations attached to this category
/// </summary>
public readonly IDStorage<CConfig> Configs;

internal void AddConfig(CConfig config) => _configs.Add(config.ID, config);
internal void RemoveConfig(CConfig config) => _configs.Remove(config.ID);

/// <summary>
/// The page this category is attached to
/// </summary>
public readonly CPage Page;

/// <summary>
/// The internal ID for this category
/// </summary>
public readonly string ID;
/// <summary>
/// The display name for this category
/// </summary>
public readonly string Name;
/// <summary>
/// The background color shown with the category's header display
/// </summary>
public readonly Color Color;
/// <summary>
/// If true, the category won't be shown in the menu if it does not have items
/// </summary>
public readonly bool HideIfEmpty;

internal CCategory(CCategoryBuilder builder)
{
// Checks
if (builder == null) throw new BuildingException("Tried to create category without builder");

if (builder.ID == null) throw new BuildingException("Unable to build category without ID");

if (_categories.ContainsKey(builder.ID)) throw new BuildingException($"Tried to create a category with an existing ID ({builder.ID})");

if (builder.Page == null || !CPage.Storage.TryGetValue(builder.Page, out Page))
throw new BuildingException($"Tried to create category within an undefined page {builder.Page}");

// Sets
ID = builder.ID;
Name = builder.Name ?? "";
Color = builder.Color;

// Indexing
_sections = [];
Sections = new(_sections);
_configs = [];
Configs = new(_configs);

// Index itslef
_categories.Add(ID, this);
Page.AddCategory(this);

// Notify
ConfigEventRouter.OnCreate_Category(this);
}

public override bool Equals(object obj)
{
return obj is CCategory other && other.ID.Equals(ID);
}

public override int GetHashCode()
{
return 987361543 | ID.GetHashCode();
}

public override string ToString()
{
return $"Section[{ID}:{Name}]";
}
}
}
96 changes: 96 additions & 0 deletions Amrv.ConfigurableCompany/API/CCategoryBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using Amrv.ConfigurableCompany.Core;
using UnityEngine;

namespace Amrv.ConfigurableCompany.API
{
public sealed class CCategoryBuilder : InstanceBuilder<CCategory>
{
public string ID;
public string Name;
public Color Color;
public string Page;
public bool HideIfEmpty;

public CPage CPage
{
set
{
Page = value?.ID ?? null;
}
get
{
if (CPage.Storage.TryGetValue(Page, out var page))
{
return page;
}
return null;
}
}

public (byte, byte, byte) ColorRGB
{
set
{
Color = new Color32(value.Item1, value.Item2, value.Item3, byte.MaxValue);
}
get
{
return ((byte)(Color.r * byte.MaxValue), (byte)(Color.g * byte.MaxValue), (byte)(Color.b * byte.MaxValue));
}
}

public CCategoryBuilder SetID(string id)
{
ID = id;
return this;
}

public CCategoryBuilder SetName(string name)
{
Name = name;
return this;
}

public CCategoryBuilder SetColor(Color color)
{
Color = color;
return this;
}

public CCategoryBuilder SetColor(byte red, byte green, byte blue, byte alpha = 255)
{
Color = new Color32(red, green, blue, alpha);
return this;
}

public CCategoryBuilder SetPage(CPage page)
{
Page = page.ID;
return this;
}

public CCategoryBuilder SetPage(string pageId)
{
Page = pageId;
return this;
}

public CCategoryBuilder SetHideIfEmpty(bool hide)
{
HideIfEmpty = hide;
return this;
}

protected override CCategory BuildInstance()
{
CPage ??= CPage.Default;

return new CCategory(this);
}

protected override bool TryGetExisting(out CCategory item)
{
return CCategory.Storage.TryGetValue(ID, out item);
}
}
}
Loading

0 comments on commit 10921fb

Please sign in to comment.