chore: Assets 디렉토리 구조 정리 및 네이밍 컨벤션 적용

- Assets/_Game/ 하위로 게임 에셋 통합
- External/ 패키지 벤더별 분류 (Synty, Animations, UI)
- 에셋 네이밍 컨벤션 확립 및 적용
  (Data_Skill_, Data_SkillEffect_, Prefab_, Anim_, Model_, BT_ 등)
- pre-commit hook으로 네이밍 컨벤션 자동 검사 추가
- RESTRUCTURE_CHECKLIST.md 작성

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-16 19:08:27 +09:00
parent 309bf5f48b
commit c265f980db
17251 changed files with 2630777 additions and 206 deletions

View File

@@ -0,0 +1,203 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using Synty.SidekickCharacters.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_blend_shape_rig_movement")]
public class SidekickBlendShapeRigMovement
{
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("part_type")]
public CharacterPartType PartType { get; set; }
[Column("blend_type")]
public BlendShapeType BlendType { get; set; }
[Column("max_offset_x")]
public float MaxOffsetX { get; set; }
[Column("max_offset_y")]
public float MaxOffsetY { get; set; }
[Column("max_offset_z")]
public float MaxOffsetZ { get; set; }
[Column("max_rotation_x")]
public float MaxRotationX { get; set; }
[Column("max_rotation_y")]
public float MaxRotationY { get; set; }
[Column("max_rotation_z")]
public float MaxRotationZ { get; set; }
[Column("max_scale_x")]
public float MaxScaleX { get; set; }
[Column("max_scale_y")]
public float MaxScaleY { get; set; }
[Column("max_scale_z")]
public float MaxScaleZ { get; set; }
[Ignore]
public Vector3 MaxOffset
{
get => new Vector3(MaxOffsetX, MaxOffsetY, MaxOffsetZ);
set
{
MaxOffsetX = value.x;
MaxOffsetY = value.y;
MaxOffsetZ = value.z;
}
}
[Ignore]
public Quaternion MaxRotation
{
get => Quaternion.Euler(new Vector3(MaxRotationX, MaxRotationY, MaxRotationZ));
set
{
Vector3 rot = value.eulerAngles;
MaxRotationX = rot.x;
MaxRotationY = rot.y;
MaxRotationZ = rot.z;
}
}
[Ignore]
public Vector3 MaxScale
{
get => new Vector3(MaxScaleX, MaxScaleY, MaxScaleZ);
set
{
MaxScaleX = value.x;
MaxScaleY = value.y;
MaxScaleZ = value.z;
}
}
public static readonly Dictionary<CharacterPartType, string> PART_TYPE_JOINT_MAP = new Dictionary<CharacterPartType, string>
{
[CharacterPartType.AttachmentBack] = "backAttach",
[CharacterPartType.AttachmentHipsFront] = "hipAttachFront",
[CharacterPartType.AttachmentHipsBack] = "hipAttachBack",
[CharacterPartType.AttachmentHipsLeft] = "hipAttach_l",
[CharacterPartType.AttachmentHipsRight] = "hipAttach_r",
[CharacterPartType.AttachmentShoulderLeft] = "shoulderAttach_l",
[CharacterPartType.AttachmentShoulderRight] = "shoulderAttach_r",
[CharacterPartType.AttachmentElbowLeft] = "elbowAttach_l",
[CharacterPartType.AttachmentElbowRight] = "elbowAttach_r",
[CharacterPartType.AttachmentKneeLeft] = "kneeAttach_l",
[CharacterPartType.AttachmentKneeRight] = "kneeAttach_r"
};
public SidekickBlendShapeRigMovement()
{
// Empty constructor required for SQLite
}
private SidekickBlendShapeRigMovement(CharacterPartType partType, BlendShapeType blendType)
{
ID = -1;
PartType = partType;
BlendType = blendType;
}
/// <summary>
/// Gets a list of all the parts in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all blend shape rig movements in the database.</returns>
public static List<SidekickBlendShapeRigMovement> GetAll(DatabaseManager dbManager)
{
return dbManager.GetCurrentDbConnection().Table<SidekickBlendShapeRigMovement>().ToList();
}
/// <summary>
/// Gets all the blend shape rig movements from the database, sorted into dictionaries for easy processing.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
/// <returns>All the blend shape rig movements from the database, sorted into dictionaries for easy processing.</returns>
public static Dictionary<CharacterPartType, Dictionary<BlendShapeType, SidekickBlendShapeRigMovement>> GetAllForProcessing(
DatabaseManager dbManager
)
{
Dictionary<CharacterPartType, Dictionary<BlendShapeType, SidekickBlendShapeRigMovement>> offsetLibrary =
new Dictionary<CharacterPartType, Dictionary<BlendShapeType, SidekickBlendShapeRigMovement>>();
List<SidekickBlendShapeRigMovement> allRigMovements = GetAll(dbManager);
foreach (CharacterPartType type in PART_TYPE_JOINT_MAP.Keys)
{
List<SidekickBlendShapeRigMovement> typeMovements = allRigMovements.Where(rm => rm.PartType == type).ToList();
Dictionary<BlendShapeType, SidekickBlendShapeRigMovement> typeMovementDictionary =
new Dictionary<BlendShapeType, SidekickBlendShapeRigMovement>();
foreach (BlendShapeType blendType in Enum.GetValues(typeof(BlendShapeType)))
{
SidekickBlendShapeRigMovement movement = typeMovements.FirstOrDefault(tm => tm.BlendType == blendType);
typeMovementDictionary[blendType] = movement;
}
offsetLibrary[type] = typeMovementDictionary;
}
return offsetLibrary;
}
/// <summary>
/// Gets a specific blend shape rig movement by its part type and blend shape type.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partType">The part type to filter by.</param>
/// <param name="blendType">The blend shape to filter by.</param>
/// <returns>The blend shape rig movement if it exists; otherwise null.</returns>
public static SidekickBlendShapeRigMovement GetByPartTypeAndBlendType(DatabaseManager dbManager, CharacterPartType partType, BlendShapeType blendType)
{
SidekickBlendShapeRigMovement rigMovement = dbManager.GetCurrentDbConnection().Table<SidekickBlendShapeRigMovement>().FirstOrDefault(rm
=> rm.BlendType == blendType && rm.PartType == partType);
return rigMovement ?? new SidekickBlendShapeRigMovement(partType, blendType);
}
public Vector3 GetBlendedOffsetValue(float blendValue)
{
return Vector3.Lerp(Vector3.zero, MaxOffset, blendValue);
}
public Quaternion GetBlendedRotationValue(float blendValue)
{
return Quaternion.Lerp(Quaternion.Euler(Vector3.zero), MaxRotation, blendValue);
}
public Vector3 GetBlendedScaleValue(float blendValue)
{
return Vector3.Lerp(Vector3.zero, MaxScale, blendValue);
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID < 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
dbManager.GetCurrentDbConnection().Delete<SidekickBlendShapeRigMovement>(ID);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a4448e0059304113aa6a54e83bd2d846
timeCreated: 1732662833

View File

@@ -0,0 +1,75 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_body_shape_preset")]
public class SidekickBodyShapePreset
{
[PrimaryKey]
[AutoIncrement]
[Column("id")]
public int ID { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("body_type")]
public int BodyType { get; set; }
[Column("body_size")]
public int BodySize { get; set; }
[Column("musculature")]
public int Musculature { get; set; }
/// <summary>
/// Gets a list of all the Preset Body Shape in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all Preset Body Shapes in the database.</returns>
public static List<SidekickBodyShapePreset> GetAll(DatabaseManager dbManager)
{
return dbManager.GetCurrentDbConnection().Table<SidekickBodyShapePreset>().ToList();
}
/// <summary>
/// Gets a specific Preset Body Shape by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Preset Body Shape.</param>
/// <returns>The specific Preset Body Shape if it exists; otherwise null.</returns>
public static SidekickBodyShapePreset GetByID(DatabaseManager dbManager, int id)
{
return dbManager.GetCurrentDbConnection().Get<SidekickBodyShapePreset>(id);
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID < 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
dbManager.GetCurrentDbConnection().Delete<SidekickBodyShapePreset>(ID);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: efa4463b5ff19d2469d6bee0175a0f8a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,115 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_body_shape_preset_image")]
public class SidekickBodyShapePresetImage
{
private SidekickBodyShapePreset _bodyShapePreset;
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("ptr_body_shape_preset")]
public int PtrPreset { get; set; }
[Column("img_data")]
public byte[] ImageData { get; set; }
[Column("img_width")]
public int Width { get; set; }
[Column("img_height")]
public int Height { get; set; }
[Ignore]
public SidekickBodyShapePreset BodyShapePreset
{
get => _bodyShapePreset;
set
{
_bodyShapePreset = value;
PtrPreset = value.ID;
}
}
/// <summary>
/// Gets a specific Preset Part by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Preset Part.</param>
/// <returns>The specific Preset Part if it exists; otherwise null.</returns>
public static SidekickBodyShapePresetImage GetByID(DatabaseManager dbManager, int id)
{
SidekickBodyShapePresetImage bodyShapePresetImage = dbManager.GetCurrentDbConnection().Find<SidekickBodyShapePresetImage>(id);
Decorate(dbManager, bodyShapePresetImage);
return bodyShapePresetImage;
}
/// <summary>
/// Gets a list of all the Preset Parts in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all preset parts in the database.</returns>
public static List<SidekickBodyShapePresetImage> GetAll(DatabaseManager dbManager)
{
List<SidekickBodyShapePresetImage> bodyShapePresetImages = dbManager.GetCurrentDbConnection().Table<SidekickBodyShapePresetImage>().ToList();
foreach (SidekickBodyShapePresetImage bodyShapePresetImage in bodyShapePresetImages)
{
Decorate(dbManager, bodyShapePresetImage);
}
return bodyShapePresetImages;
}
/// <summary>
/// Gets a list of all the Preset Part Images in the database that have the matching Part Preset.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="bodyShapePreset">The preset to get all the preset part images for.</param>
/// <returns>A list of all preset part images in the database for the given preset.</returns>
public static SidekickBodyShapePresetImage GetByPreset(DatabaseManager dbManager, SidekickBodyShapePreset bodyShapePreset)
{
SidekickBodyShapePresetImage bodyShapePresetImage = dbManager.GetCurrentDbConnection().Table<SidekickBodyShapePresetImage>()
.FirstOrDefault(bodyShapePresetImage => bodyShapePresetImage.PtrPreset == bodyShapePreset.ID);
if (bodyShapePresetImage != null)
{
Decorate(dbManager, bodyShapePresetImage);
}
return bodyShapePresetImage;
}
/// <summary>
/// Ensures that the given preset has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="bodyShapePresetImage">The color preset to decorate</param>
/// <returns>A color set with all DTO class properties set</returns>
private static void Decorate(DatabaseManager dbManager, SidekickBodyShapePresetImage bodyShapePresetImage)
{
bodyShapePresetImage.BodyShapePreset ??= SidekickBodyShapePreset.GetByID(dbManager, bodyShapePresetImage.PtrPreset);
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 225ce6946562800478b23f28f0f721a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_color_filter")]
public class SidekickColorFilter
{
[PrimaryKey, Column("id")]
public int ID { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("display_name")]
public string DisplayName { get; set; }
/// <summary>
/// Gets a list of all the Color Filters in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all Color Filters in the database.</returns>
public static List<SidekickColorFilter> GetAll(DatabaseManager dbManager)
{
return dbManager.GetCurrentDbConnection().Table<SidekickColorFilter>().ToList();
}
/// <summary>
/// Gets a specific Color Filter by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Color Filter.</param>
/// <returns>The specific Color Filter if it exists; otherwise null.</returns>
public static SidekickColorFilter GetByID(DatabaseManager dbManager, int id)
{
return dbManager.GetCurrentDbConnection().Get<SidekickColorFilter>(id);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2e524419640c4fcdb41c8bdb5c26cb0c
timeCreated: 1711075931

View File

@@ -0,0 +1,204 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using Synty.SidekickCharacters.Enums;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_color_preset")]
public class SidekickColorPreset
{
private SidekickSpecies _species;
[PrimaryKey]
[AutoIncrement]
[Column("id")]
public int ID { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("color_group")]
public ColorGroup ColorGroup { get; set; }
[Column("ptr_species")]
public int PtrSpecies { get; set; }
[Ignore]
public SidekickSpecies Species
{
get => _species;
set
{
_species = value;
PtrSpecies = value.ID;
}
}
/// <summary>
/// Gets a list of all the Color Presets in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all color presets in the database.</returns>
public static List<SidekickColorPreset> GetAll(DatabaseManager dbManager)
{
List<SidekickColorPreset> presets = dbManager.GetCurrentDbConnection().Table<SidekickColorPreset>().ToList();
foreach (SidekickColorPreset preset in presets)
{
Decorate(dbManager, preset);
}
return presets;
}
/// <summary>
/// Gets a list of all the Color Presets in the database that have the matching species.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="species">The species to get all the color presets for.</param>
/// <returns>A list of all color presets in the database for the given species.</returns>
public static List<SidekickColorPreset> GetAllBySpecies(DatabaseManager dbManager, SidekickSpecies species)
{
List<SidekickColorPreset> presets = dbManager.GetCurrentDbConnection().Table<SidekickColorPreset>()
.Where(set => set.PtrSpecies == species.ID)
.ToList();
foreach (SidekickColorPreset preset in presets)
{
preset.Species = species;
}
return presets;
}
/// <summary>
/// Gets a Color Presets in the database with the matching name if one exists.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="name">The name of the preset to retrieve.</param>
/// <returns>Returns a Color Presets in the database with the matching name if one exists; otherwise null.</returns>
public static SidekickColorPreset GetByName(DatabaseManager dbManager, string name)
{
SidekickColorPreset colorPreset = dbManager.GetCurrentDbConnection()
.Table<SidekickColorPreset>()
.FirstOrDefault(colorPreset => colorPreset.Name == name);
if (colorPreset != null)
{
Decorate(dbManager, colorPreset);
}
return colorPreset;
}
/// <summary>
/// Gets a list of all the Color Presets in the database that have the matching species.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="colorGroup">The color group to get all the color presets for.</param>
/// <returns>A list of all color presets in the database for the given color group.</returns>
public static List<SidekickColorPreset> GetAllByColorGroup(DatabaseManager dbManager, ColorGroup colorGroup)
{
List<SidekickColorPreset> presets = dbManager.GetCurrentDbConnection().Table<SidekickColorPreset>()
.Where(preset => preset.ColorGroup == colorGroup)
.ToList();
foreach (SidekickColorPreset preset in presets)
{
Decorate(dbManager, preset);
}
return presets;
}
/// <summary>
/// Gets a list of all the Color Presets in the database that have the matching species.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="colorGroup">The color group to get all the color presets for.</param>
/// <param name="species">The species to get the color presets for.</param>
/// <returns>A list of all color presets in the database for the given color group and species.</returns>
public static List<SidekickColorPreset> GetAllByColorGroupAndSpecies(
DatabaseManager dbManager,
ColorGroup colorGroup,
SidekickSpecies species
)
{
List<SidekickColorPreset> presets = dbManager.GetCurrentDbConnection()
.Table<SidekickColorPreset>()
.Where(preset => preset.ColorGroup == colorGroup && preset.PtrSpecies == species.ID)
.ToList();
foreach (SidekickColorPreset preset in presets)
{
preset.Species = species;
}
return presets;
}
/// <summary>
/// Gets a specific Color Preset by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Color Preset.</param>
/// <returns>The specific Color Preset if it exists; otherwise null.</returns>
public static SidekickColorPreset GetByID(DatabaseManager dbManager, int id)
{
SidekickColorPreset preset = dbManager.GetCurrentDbConnection().Find<SidekickColorPreset>(id);
Decorate(dbManager, preset);
return preset;
}
/// <summary>
/// Ensures that the given preset has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="preset">The color preset to decorate</param>
/// <returns>A color set with all DTO class properties set</returns>
private static void Decorate(DatabaseManager dbManager, SidekickColorPreset preset)
{
if (preset.Species == null && preset.PtrSpecies >= 0)
{
preset.Species = SidekickSpecies.GetByID(dbManager, preset.PtrSpecies);
}
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID < 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
foreach (SidekickColorPresetRow row in SidekickColorPresetRow.GetAllByPreset(dbManager, this))
{
row.Delete(dbManager);
}
SidekickColorPresetImage image = SidekickColorPresetImage.GetByPresetAndColorGroup(dbManager, this, ColorGroup);
image?.Delete(dbManager);
dbManager.GetCurrentDbConnection().Delete<SidekickColorPreset>(ID);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1a1a7fb5aa0d51340a968dedab10d7b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,158 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using Synty.SidekickCharacters.Enums;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_color_preset_image")]
public class SidekickColorPresetImage
{
private SidekickColorPreset _colorPreset;
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("ptr_color_preset")]
public int PtrPreset { get; set; }
[Column("color_group")]
public ColorGroup ColorGroup { get; set; }
[Column("img_data")]
public byte[] ImageData { get; set; }
[Column("img_width")]
public int Width { get; set; }
[Column("img_height")]
public int Height { get; set; }
[Ignore]
public SidekickColorPreset ColorPreset
{
get => _colorPreset;
set
{
_colorPreset = value;
PtrPreset = value.ID;
}
}
/// <summary>
/// Gets a specific Preset Part by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Preset Part.</param>
/// <returns>The specific Preset Part if it exists; otherwise null.</returns>
public static SidekickColorPresetImage GetByID(DatabaseManager dbManager, int id)
{
SidekickColorPresetImage partPresetImage = dbManager.GetCurrentDbConnection().Find<SidekickColorPresetImage>(id);
Decorate(dbManager, partPresetImage);
return partPresetImage;
}
/// <summary>
/// Gets a list of all the Preset Parts in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all preset parts in the database.</returns>
public static List<SidekickColorPresetImage> GetAll(DatabaseManager dbManager)
{
List<SidekickColorPresetImage> partPresetImages = dbManager.GetCurrentDbConnection().Table<SidekickColorPresetImage>().ToList();
foreach (SidekickColorPresetImage partPresetImage in partPresetImages)
{
Decorate(dbManager, partPresetImage);
}
return partPresetImages;
}
/// <summary>
/// Gets a list of all the Preset Part Images in the database that have the matching Part Preset.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partPreset">The preset to get all the preset part images for.</param>
/// <returns>A list of all preset part images in the database for the given preset.</returns>
public static List<SidekickColorPresetImage> GetAllByPreset(DatabaseManager dbManager, SidekickPartPreset partPreset)
{
List<SidekickColorPresetImage> partPresetImages = dbManager.GetCurrentDbConnection().Table<SidekickColorPresetImage>()
.Where(presetPart => presetPart.PtrPreset == partPreset.ID)
.ToList();
foreach (SidekickColorPresetImage partPresetImage in partPresetImages)
{
Decorate(dbManager, partPresetImage);
}
return partPresetImages;
}
/// <summary>
/// Gets the Preset Part Image in the database that have the matching Part Preset and Part Group.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partPreset">The preset to get the preset part image for.</param>
/// <param name="partGroup">The part group to filter the results by.</param>
/// <returns>The preset part image in the database for the given preset and part group.</returns>
public static SidekickColorPresetImage GetByPresetAndColorGroup(
DatabaseManager dbManager,
SidekickColorPreset partPreset,
ColorGroup partGroup
)
{
SidekickColorPresetImage partPresetImage = dbManager.GetCurrentDbConnection().Table<SidekickColorPresetImage>()
.FirstOrDefault(presetPart => presetPart.PtrPreset == partPreset.ID && presetPart.ColorGroup == partGroup);
if (partPresetImage != null)
{
Decorate(dbManager, partPresetImage);
}
return partPresetImage;
}
/// <summary>
/// Ensures that the given preset has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partPresetImage">The color preset to decorate</param>
/// <returns>A color set with all DTO class properties set</returns>
private static void Decorate(DatabaseManager dbManager, SidekickColorPresetImage partPresetImage)
{
if (partPresetImage != null)
{
if (partPresetImage.ColorPreset == null && partPresetImage.PtrPreset >= 0)
{
partPresetImage.ColorPreset = SidekickColorPreset.GetByID(dbManager, partPresetImage.PtrPreset);
}
}
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
dbManager.GetCurrentDbConnection().Delete<SidekickColorPresetImage>(ID);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7586d1ff5aab4e6a972345f299975238
timeCreated: 1730241515

View File

@@ -0,0 +1,288 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System.Collections.Generic;
using UnityEngine;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_color_preset_row")]
public class SidekickColorPresetRow
{
private SidekickColorPreset _colorPreset;
private SidekickColorProperty _colorProperty;
private Color? _niceColor;
private Color? _niceMetallic;
private Color? _niceSmoothness;
private Color? _niceReflection;
private Color? _niceEmission;
private Color? _niceOpacity;
[PrimaryKey]
[AutoIncrement]
[Column("id")]
public int ID { get; set; }
[Column("ptr_color_preset")]
public int PtrColorPreset { get; set; }
[Column("ptr_color_property")]
public int PtrColorProperty { get; set; }
[Column("color")]
public string MainColor { get; set; }
[Column("metallic")]
public string Metallic { get; set; }
[Column("smoothness")]
public string Smoothness { get; set; }
[Column("reflection")]
public string Reflection { get; set; }
[Column("emission")]
public string Emission { get; set; }
[Column("opacity")]
public string Opacity { get; set; }
[Ignore]
public SidekickColorPreset ColorPreset
{
get => _colorPreset;
set
{
_colorPreset = value;
PtrColorPreset = value.ID;
}
}
[Ignore]
public SidekickColorProperty ColorProperty
{
get => _colorProperty;
set
{
_colorProperty = value;
PtrColorProperty = value.ID;
}
}
[Ignore]
public Color NiceColor
{
get
{
_niceColor ??= ColorUtility.TryParseHtmlString("#" + MainColor, out Color color) ? color : Color.white;
return (Color) _niceColor;
}
set
{
_niceColor = value;
MainColor = ColorUtility.ToHtmlStringRGB(value);
}
}
[Ignore]
public Color NiceMetallic
{
get
{
_niceMetallic ??= ColorUtility.TryParseHtmlString("#" + Metallic, out Color color) ? color : Color.white;
return (Color) _niceMetallic;
}
set
{
_niceMetallic = value;
Metallic = ColorUtility.ToHtmlStringRGB(value);
}
}
[Ignore]
public Color NiceSmoothness
{
get
{
_niceSmoothness ??= ColorUtility.TryParseHtmlString("#" + Smoothness, out Color color) ? color : Color.white;
return (Color) _niceSmoothness;
}
set
{
_niceSmoothness = value;
Smoothness = ColorUtility.ToHtmlStringRGB(value);
}
}
[Ignore]
public Color NiceReflection
{
get
{
_niceReflection ??= ColorUtility.TryParseHtmlString("#" + Reflection, out Color color) ? color : Color.white;
return (Color) _niceReflection;
}
set
{
_niceReflection = value;
Reflection = ColorUtility.ToHtmlStringRGB(value);
}
}
[Ignore]
public Color NiceEmission
{
get
{
_niceEmission ??= ColorUtility.TryParseHtmlString("#" + Emission, out Color color) ? color : Color.white;
return (Color) _niceEmission;
}
set
{
_niceEmission = value;
Emission = ColorUtility.ToHtmlStringRGB(value);
}
}
[Ignore]
public Color NiceOpacity
{
get
{
_niceOpacity ??= ColorUtility.TryParseHtmlString("#" + Opacity, out Color color) ? color : Color.white;
return (Color) _niceOpacity;
}
set
{
_niceOpacity = value;
Opacity = ColorUtility.ToHtmlStringRGB(value);
}
}
/// <summary>
/// Gets a list of all the Color Preset Rows in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all Color Preset Rows in the database.</returns>
public static List<SidekickColorPresetRow> GetAll(DatabaseManager dbManager)
{
List<SidekickColorPresetRow> rows = dbManager.GetCurrentDbConnection().Table<SidekickColorPresetRow>().ToList();
foreach (SidekickColorPresetRow row in rows)
{
Decorate(dbManager, row);
}
return rows;
}
/// <summary>
/// Gets a specific Color Preset Row by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Color Preset Row.</param>
/// <returns>The specific Color Preset Row if it exists; otherwise null.</returns>
public static SidekickColorPresetRow GetByID(DatabaseManager dbManager, int id)
{
SidekickColorPresetRow row = dbManager.GetCurrentDbConnection().Find<SidekickColorPresetRow>(id);
Decorate(dbManager, row);
return row;
}
/// <summary>
/// Gets a list of all the Color Preset Rows in the database that have the matching Property.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="property">The property to get all the color preset rows for.</param>
/// <returns>A list of all color preset rows in the database for the given property.</returns>
public static List<SidekickColorPresetRow> GetAllByProperty(DatabaseManager dbManager, SidekickColorProperty property)
{
List<SidekickColorPresetRow> rows = dbManager.GetCurrentDbConnection().Table<SidekickColorPresetRow>()
.Where(row => row.PtrColorProperty == property.ID)
.ToList();
foreach (SidekickColorPresetRow row in rows)
{
row.ColorProperty = property;
Decorate(dbManager, row);
}
return rows;
}
/// <summary>
/// Gets a list of all the Color Preset Rows in the database that have the matching Set and Property.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="preset">The color preset to get the color preset rows for.</param>
/// <param name="property">The property to get all the color preset rows for.</param>
/// <returns>A list of all color preset rows in the database for the given set and property.</returns>
public static List<SidekickColorPresetRow> GetAllByPresetAndProperty(
DatabaseManager dbManager,
SidekickColorPreset preset,
SidekickColorProperty property
)
{
List<SidekickColorPresetRow> rows = dbManager.GetCurrentDbConnection().Table<SidekickColorPresetRow>()
.Where(row => row.PtrColorPreset == preset.ID && row.PtrColorProperty == property.ID)
.ToList();
foreach (SidekickColorPresetRow row in rows)
{
row.ColorProperty = property;
row.ColorPreset = preset;
}
return rows;
}
/// <summary>
/// Gets a list of all the Color Preset Rows in the database that have the matching Set.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="preset">The color preset to get the color preset rows for.</param>
/// <returns>A list of all color preset rows in the database for the given set.</returns>
public static List<SidekickColorPresetRow> GetAllByPreset(DatabaseManager dbManager, SidekickColorPreset preset)
{
List<SidekickColorPresetRow> rows = dbManager.GetCurrentDbConnection().Table<SidekickColorPresetRow>()
.Where(row => row.PtrColorPreset == preset.ID)
.ToList();
foreach (SidekickColorPresetRow row in rows)
{
row.ColorPreset = preset;
Decorate(dbManager, row);
}
return rows;
}
/// <summary>
/// Ensures that the given row has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="row">The color preset row to decorate</param>
/// <returns>A color preset row with all DTO class properties set</returns>
private static void Decorate(DatabaseManager dbManager, SidekickColorPresetRow row)
{
// don't need PtrColorProperty check as should always be >= 0; if it's not, we have bad data and want the error
row.ColorProperty ??= SidekickColorProperty.GetByID(dbManager, row.PtrColorProperty);
row.ColorPreset ??= SidekickColorPreset.GetByID(dbManager, row.PtrColorPreset);
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID < 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
dbManager.GetCurrentDbConnection().Delete<SidekickColorPresetRow>(ID);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 76b21d6d2b49a5f45a08f97a17c23c08
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using Synty.SidekickCharacters.Enums;
using System.Collections.Generic;
using UnityEngine;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_color_property")]
public class SidekickColorProperty
{
[PrimaryKey, Column("id")]
public int ID { get; set; }
// NOTE : automatically converts to the integer mapping of the enum
[Column("color_group")]
public ColorGroup Group { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("u")]
public int U { get; set; }
[Column("v")]
public int V { get; set; }
/// <summary>
/// Gets a list of all the Color Properties in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all Color Properties in the database.</returns>
public static List<SidekickColorProperty> GetAll(DatabaseManager dbManager)
{
return dbManager.GetCurrentDbConnection().Table<SidekickColorProperty>().ToList();
}
/// <summary>
/// Gets a list of all the Color Properties in the database that have the matching group.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="group">The color group to get all the color properties for.</param>
/// <returns>A list of all color groups in the database for the given group.</returns>
public static List<SidekickColorProperty> GetAllByGroup(DatabaseManager dbManager, ColorGroup group)
{
return dbManager.GetCurrentDbConnection().Table<SidekickColorProperty>().Where(prop => prop.Group == group).ToList();
}
/// <summary>
/// Gets a specific Color Property by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Color Property.</param>
/// <returns>The specific Color Property if it exists; otherwise null.</returns>
public static SidekickColorProperty GetByID(DatabaseManager dbManager, int id)
{
return dbManager.GetCurrentDbConnection().Find<SidekickColorProperty>(id);
}
/// <summary>
/// Gets a list of properties that match any of the UVs from the given list.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="uVs">The list of UVs to get the properties for.</param>
/// <returns>A list of properties that match any of the UVs from the given list.</returns>
public static List<SidekickColorProperty> GetByUVs(DatabaseManager dbManager, List<Vector2> uVs)
{
List<SidekickColorProperty> properties = new List<SidekickColorProperty>();
foreach (Vector2 uv in uVs)
{
properties.AddRange(
dbManager.GetCurrentDbConnection().Table<SidekickColorProperty>()
.Where(prop => prop.U == uv.x && prop.V == uv.y)
.ToList()
);
}
return properties;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 111a0f92d48c4b54bfc31c7845f94085
timeCreated: 1711070621

View File

@@ -0,0 +1,347 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_color_row")]
public class SidekickColorRow
{
private SidekickColorSet _colorSet;
private SidekickColorProperty _colorProperty;
private Color? _niceColor;
private Color? _niceMetallic;
private Color? _niceSmoothness;
private Color? _niceReflection;
private Color? _niceEmission;
private Color? _niceOpacity;
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("ptr_color_set")]
public int PtrColorSet { get; set; }
[Column("ptr_color_property")]
public int PtrColorProperty { get; set; }
[Column("color")]
public string MainColor { get; set; }
[Column("metallic")]
public string Metallic { get; set; }
[Column("smoothness")]
public string Smoothness { get; set; }
[Column("reflection")]
public string Reflection { get; set; }
[Column("emission")]
public string Emission { get; set; }
[Column("opacity")]
public string Opacity { get; set; }
[Ignore]
public SidekickColorSet ColorSet
{
get => _colorSet;
set
{
_colorSet = value;
PtrColorSet = value.ID;
}
}
[Ignore]
public SidekickColorProperty ColorProperty
{
get => _colorProperty;
set
{
_colorProperty = value;
PtrColorProperty = value.ID;
}
}
[Ignore]
public Color NiceColor
{
get
{
_niceColor ??= ColorUtility.TryParseHtmlString("#" + MainColor, out Color color) ? color : Color.white;
return (Color) _niceColor;
}
set
{
_niceColor = value;
MainColor = ColorUtility.ToHtmlStringRGB(value);
}
}
[Ignore]
public Color NiceMetallic
{
get
{
_niceMetallic ??= ColorUtility.TryParseHtmlString("#" + Metallic, out Color color) ? color : Color.white;
return (Color) _niceMetallic;
}
set
{
_niceMetallic = value;
Metallic = ColorUtility.ToHtmlStringRGB(value);
}
}
[Ignore]
public Color NiceSmoothness
{
get
{
_niceSmoothness ??= ColorUtility.TryParseHtmlString("#" + Smoothness, out Color color) ? color : Color.white;
return (Color) _niceSmoothness;
}
set
{
_niceSmoothness = value;
Smoothness = ColorUtility.ToHtmlStringRGB(value);
}
}
[Ignore]
public Color NiceReflection
{
get
{
_niceReflection ??= ColorUtility.TryParseHtmlString("#" + Reflection, out Color color) ? color : Color.white;
return (Color) _niceReflection;
}
set
{
_niceReflection = value;
Reflection = ColorUtility.ToHtmlStringRGB(value);
}
}
[Ignore]
public Color NiceEmission
{
get
{
_niceEmission ??= ColorUtility.TryParseHtmlString("#" + Emission, out Color color) ? color : Color.white;
return (Color) _niceEmission;
}
set
{
_niceEmission = value;
Emission = ColorUtility.ToHtmlStringRGB(value);
}
}
[Ignore]
public Color NiceOpacity
{
get
{
_niceOpacity ??= ColorUtility.TryParseHtmlString("#" + Opacity, out Color color) ? color : Color.white;
return (Color) _niceOpacity;
}
set
{
_niceOpacity = value;
Opacity = ColorUtility.ToHtmlStringRGB(value);
}
}
[Ignore]
public bool IsLocked { get; set; }
[Ignore]
public Image ButtonImage { get; set; }
/// <summary>
/// Gets a list of all the Color Rows in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all Color Rows in the database.</returns>
public static List<SidekickColorRow> GetAll(DatabaseManager dbManager)
{
List<SidekickColorRow> rows = dbManager.GetCurrentDbConnection().Table<SidekickColorRow>().ToList();
foreach (SidekickColorRow row in rows)
{
Decorate(dbManager, row);
}
return rows;
}
/// <summary>
/// Gets a specific Color Row by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Color Row.</param>
/// <returns>The specific Color Row if it exists; otherwise null.</returns>
public static SidekickColorRow GetByID(DatabaseManager dbManager, int id)
{
SidekickColorRow row = dbManager.GetCurrentDbConnection().Find<SidekickColorRow>(id);
Decorate(dbManager, row);
return row;
}
/// <summary>
/// Gets a list of all the Color Rows in the database that have the matching Property.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="property">The property to get all the color rows for.</param>
/// <returns>A list of all color rows in the database for the given property.</returns>
public static List<SidekickColorRow> GetAllByProperty(DatabaseManager dbManager, SidekickColorProperty property)
{
List<SidekickColorRow> rows = dbManager.GetCurrentDbConnection().Table<SidekickColorRow>()
.Where(row => row.PtrColorProperty == property.ID)
.ToList();
foreach (SidekickColorRow row in rows)
{
row.ColorProperty = property;
Decorate(dbManager, row);
}
return rows;
}
/// <summary>
/// Gets a list of all the Color Rows in the database that have the matching Set and Property.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="set">The color set to get the color rows for.</param>
/// <param name="property">The property to get all the color rows for.</param>
/// <returns>A list of all color rows in the database for the given set and property.</returns>
public static List<SidekickColorRow> GetAllBySetAndProperty(DatabaseManager dbManager, SidekickColorSet set, SidekickColorProperty property)
{
List<SidekickColorRow> rows = dbManager.GetCurrentDbConnection().Table<SidekickColorRow>()
.Where(row => row.PtrColorSet == set.ID && row.PtrColorProperty == property.ID)
.ToList();
foreach (SidekickColorRow row in rows)
{
row.ColorSet = set;
row.ColorProperty = property;
Decorate(dbManager, row);
}
return rows;
}
/// <summary>
/// Gets a list of all the Color Rows in the database that have the matching Set.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="set">The color set to get the color rows for.</param>
/// <returns>A list of all color rows in the database for the given set.</returns>
public static List<SidekickColorRow> GetAllBySet(DatabaseManager dbManager, SidekickColorSet set)
{
List<SidekickColorRow> rows = dbManager.GetCurrentDbConnection().Table<SidekickColorRow>()
.Where(row => row.PtrColorSet == set.ID)
.ToList();
foreach (SidekickColorRow row in rows)
{
row.ColorSet = set;
Decorate(dbManager, row);
}
return rows;
}
/// <summary>
/// Creates a SidekickColorRow from a SidekickColorPresetRow.
/// </summary>
/// <param name="row">The SidekickColorPresetRow to convert.</param>
/// <returns>A SidekickColorRow created from a SidekickColorPresetRow.</returns>
public static SidekickColorRow CreateFromPresetColorRow(SidekickColorPresetRow row)
{
SidekickColorRow newRow = new SidekickColorRow()
{
MainColor = row.MainColor,
Emission = row.Emission,
Metallic = row.Metallic,
Opacity = row.Opacity,
Reflection = row.Reflection,
Smoothness = row.Smoothness,
ColorProperty = row.ColorProperty
};
return newRow;
}
/// <summary>
/// Ensures that the given row has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="row">The color row to decorate</param>
/// <returns>A color row with all DTO class properties set</returns>
private static void Decorate(DatabaseManager dbManager, SidekickColorRow row)
{
// don't need PtrColorProperty check as should always be >= 0; if it's not, we have bad data and want the error
row.ColorProperty ??= SidekickColorProperty.GetByID(dbManager, row.PtrColorProperty);
if (row.ColorSet == null && row.PtrColorSet >= 0)
{
row.ColorSet = SidekickColorSet.GetByID(dbManager, row.PtrColorSet);
}
}
/// <summary>
/// Delete this color row from the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
int deletedCount = dbManager.GetCurrentDbConnection().Delete<SidekickColorRow>(ID);
if (deletedCount == 0)
{
throw new Exception($"Could not delete color set with ID '{ID}'");
}
}
/// <summary>
/// Inserts, or updates the values in the database, depending on this object has been saved before or not.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
public void Save(DatabaseManager dbManager)
{
if (ID < 0)
{
SaveToDB(dbManager);
}
else
{
UpdateDB(dbManager);
}
}
/// <summary>
/// Saves this Color Set to the database with the current values.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
private void SaveToDB(DatabaseManager dbManager)
{
SQLiteConnection connection = dbManager.GetCurrentDbConnection();
int insertCount = connection.Insert(this);
if (insertCount == 0)
{
throw new Exception("Unable to save current color row");
}
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(connection.Handle);
}
/// <summary>
/// Updates this Color Set in the database with the current values.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
private void UpdateDB(DatabaseManager dbManager)
{
int updatedCount = dbManager.GetCurrentDbConnection().Update(this);
if (updatedCount == 0)
{
throw new Exception($"Could not update color row with ID '{ID}'");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7364093cfc524536bef3f864a7991e75
timeCreated: 1711501683

View File

@@ -0,0 +1,222 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_color_set")]
public class SidekickColorSet
{
private SidekickSpecies _species;
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
// NOTE : cannot make private as the ORM requires it to be visible when calling Save()
// NOTE : not possible to encapsulate setting _species without a dbManager reference, so always set via Species instead
[Column("ptr_species")]
public int PtrSpecies { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("src_color")]
public string SourceColorPath { get; set; }
[Column("src_metallic")]
public string SourceMetallicPath { get; set; }
[Column("src_smoothness")]
public string SourceSmoothnessPath { get; set; }
[Column("src_reflection")]
public string SourceReflectionPath { get; set; }
[Column("src_emission")]
public string SourceEmissionPath { get; set; }
[Column("src_opacity")]
public string SourceOpacityPath { get; set; }
[Ignore]
public SidekickSpecies Species
{
get => _species;
set
{
_species = value;
PtrSpecies = value.ID;
}
}
/// <summary>
/// Gets a list of all the Color Sets in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all color sets in the database.</returns>
public static List<SidekickColorSet> GetAll(DatabaseManager dbManager)
{
List<SidekickColorSet> sets = dbManager.GetCurrentDbConnection().Table<SidekickColorSet>().ToList();
foreach (SidekickColorSet set in sets)
{
Decorate(dbManager, set);
}
return sets;
}
/// <summary>
/// Gets a list of all the Color Sets in the database that have the matching species.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="species">The species to get all the color sets for.</param>
/// <returns>A list of all color sets in the database for the given species.</returns>
public static List<SidekickColorSet> GetAllBySpecies(DatabaseManager dbManager, SidekickSpecies species)
{
List<SidekickColorSet> sets = dbManager.GetCurrentDbConnection().Table<SidekickColorSet>()
.Where(set => set.PtrSpecies == species.ID)
.ToList();
foreach (SidekickColorSet set in sets)
{
set.Species = species;
Decorate(dbManager, set);
}
return sets;
}
/// <summary>
/// Gets the default Color Set in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>The default Color Set in the database.</returns>
public static SidekickColorSet GetDefault(DatabaseManager dbManager)
{
SidekickColorSet set = dbManager.GetCurrentDbConnection().Get<SidekickColorSet>(set => set.PtrSpecies == -1);
Decorate(dbManager, set);
return set;
}
/// <summary>
/// Gets count of all the Color Sets in the database that have the matching species.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="species">The species to get the color set count for.</param>
/// <returns>The count of all color sets in the database for the given species.</returns>
public static int GetCountBySpecies(DatabaseManager dbManager, SidekickSpecies species)
{
return dbManager.GetCurrentDbConnection().Table<SidekickColorSet>().Count(set => set.PtrSpecies == species.ID);
}
/// <summary>
/// Gets a specific Color Set by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Color Set.</param>
/// <returns>The specific Color Set if it exists; otherwise null.</returns>
public static SidekickColorSet GetByID(DatabaseManager dbManager, int id)
{
SidekickColorSet set = dbManager.GetCurrentDbConnection().Find<SidekickColorSet>(id);
Decorate(dbManager, set);
return set;
}
/// <summary>
/// Gets a specific Color Set by its database name.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="name">The name of the required Color Set.</param>
/// <returns>The specific Color Set if it exists; otherwise null.</returns>
public static SidekickColorSet GetByName(DatabaseManager dbManager, string name)
{
SidekickColorSet set = dbManager.GetCurrentDbConnection().Table<SidekickColorSet>().FirstOrDefault(set => set.Name == name);
Decorate(dbManager, set);
return set;
}
/// <summary>
/// Checks if the given color set name exists in the database or not.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="name">The name to check for.</param>
/// <returns>True if the name exists in the database; otherwise False.</returns>
public static bool DoesNameExist(DatabaseManager dbManager, string name)
{
return dbManager.GetCurrentDbConnection().Table<SidekickColorSet>().Count(set => set.Name == name) > 0;
}
/// <summary>
/// Ensures that the given set has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="set">The color set to decorate</param>
/// <returns>A color set with all DTO class properties set</returns>
private static void Decorate(DatabaseManager dbManager, SidekickColorSet set)
{
if (set.Species == null && set.PtrSpecies >= 0)
{
set.Species = SidekickSpecies.GetByID(dbManager, set.PtrSpecies);
}
}
/// <summary>
/// Delete this color set from the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
int deletedCount = dbManager.GetCurrentDbConnection().Delete<SidekickColorSet>(ID);
if (deletedCount == 0)
{
throw new Exception($"Could not delete color set with ID '{ID}'");
}
}
/// <summary>
/// Inserts, or updates the values in the database, depending on this object has been saved before or not.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
public void Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
SaveToDB(dbManager);
}
else
{
UpdateDB(dbManager);
}
}
/// <summary>
/// Saves this Color Set to the database with the current values.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
private void SaveToDB(DatabaseManager dbManager)
{
SQLiteConnection connection = dbManager.GetCurrentDbConnection();
int insertCount = connection.Insert(this);
if (insertCount == 0)
{
throw new Exception("Unable to save current color set");
}
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(connection.Handle);
}
/// <summary>
/// Updates this Color Set in the database with the current values.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
private void UpdateDB(DatabaseManager dbManager)
{
int updatedCount = dbManager.GetCurrentDbConnection().Update(this);
if (updatedCount == 0)
{
throw new Exception($"Could not update color set with ID '{ID}'");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 68d1d4b9f3c2474d99f37b7b600c2305
timeCreated: 1711058031

View File

@@ -0,0 +1,39 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_vdata")]
public class SidekickDBVersion
{
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("semantic_version")]
public string SemanticVersion { get; set; }
[Column("update_time")]
public DateTime LastUpdated { get; set; }
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5ee48c6f79044f06b72466f41d770727
timeCreated: 1716368689

View File

@@ -0,0 +1,346 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using Synty.SidekickCharacters.Enums;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_part")]
public class SidekickPart
{
private SidekickSpecies _species;
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("ptr_species")]
public int PtrSpecies { get; set; }
[Column("type")]
public CharacterPartType Type { get; set; }
[Column("part_group")]
public PartGroup PartGroup { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("part_file_name")]
public string FileName { get; set; }
[Column("part_location")]
public string Location { get; set; }
[Column("uses_wrap")]
public bool UsesWrap { get; set; }
[Column("file_exists")]
public bool FileExists { get; set; }
[Ignore]
public SidekickSpecies Species
{
get => _species;
set
{
_species = value;
PtrSpecies = value.ID;
}
}
/// <summary>
/// Gets a specific Preset Part by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Preset Part.</param>
/// <returns>The specific Preset Part if it exists; otherwise null.</returns>
public static SidekickPart GetByID(DatabaseManager dbManager, int id)
{
SidekickPart part = dbManager.GetCurrentDbConnection().Find<SidekickPart>(id);
Decorate(dbManager, part);
return part;
}
/// <summary>
/// Gets a list of all the parts in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all parts in the database.</returns>
public static List<SidekickPart> GetAll(DatabaseManager dbManager)
{
List<SidekickPart> parts = dbManager.GetCurrentDbConnection().Table<SidekickPart>().ToList();
foreach (SidekickPart part in parts)
{
Decorate(dbManager, part);
}
return parts;
}
/// <summary>
/// Gets a list of all the parts in the database for a given Character Part Type.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partType">The Character Part Type to get all the parts for.</param>
/// <returns>A list of all parts for the given Character Part Type in the database.</returns>
public static List<SidekickPart> GetAllForPartType(DatabaseManager dbManager, CharacterPartType partType)
{
List<SidekickPart> parts = dbManager.GetCurrentDbConnection().Table<SidekickPart>().Where(part => part.Type == partType).ToList();
foreach (SidekickPart part in parts)
{
Decorate(dbManager, part);
}
return parts;
}
/// <summary>
/// Gets a list of all the parts in the database for a given Character Part Type.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="species">The Character Part Type to get all the parts for.</param>
/// <param name="onlyPartsWithFile">Whether to include parts that have a file in the project or not.</param>
/// <returns>A list of all parts for the given Character Part Type in the database.</returns>
public static List<SidekickPart> GetAllForSpecies(DatabaseManager dbManager, SidekickSpecies species, bool onlyPartsWithFile = true)
{
List<SidekickPart> parts = new List<SidekickPart>();
if (onlyPartsWithFile)
{
parts = dbManager.GetCurrentDbConnection().Table<SidekickPart>().Where(part => part.PtrSpecies == species.ID && part.FileExists == onlyPartsWithFile).ToList();
}
else
{
parts = dbManager.GetCurrentDbConnection().Table<SidekickPart>().Where(part => part.PtrSpecies == species.ID).ToList();
}
foreach (SidekickPart part in parts)
{
Decorate(dbManager, part);
}
return parts;
}
/// <summary>
/// Get the part in the database for the given part file name.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="fileName">The file name to get the part for.</param>
/// <returns>A part in the database for the given part file name if it exists; otherwise null</returns>
public static SidekickPart GetByPartFileName(DatabaseManager dbManager, string fileName)
{
SidekickPart part = dbManager.GetCurrentDbConnection().Table<SidekickPart>().FirstOrDefault(part => part.FileName == fileName);
Decorate(dbManager, part);
return part;
}
/// <summary>
/// Gets all the base parts from the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all the base parts from the database.</returns>
public static List<SidekickPart> GetBaseParts(DatabaseManager dbManager)
{
List<SidekickPart> parts = dbManager.GetCurrentDbConnection().Table<SidekickPart>().Where(part => part.FileName.Contains("_BASE_")).ToList();
foreach (SidekickPart part in parts)
{
Decorate(dbManager, part);
}
return parts;
}
/// <summary>
/// Search for a part in the database where the part name or filename match the given term.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partName">The term to search for the part with.</param>
/// <returns>A part in the database for that matches the search term if it exists; otherwise null</returns>
public static SidekickPart SearchForByName(DatabaseManager dbManager, string partName)
{
SidekickPart part = dbManager.GetCurrentDbConnection().Table<SidekickPart>().FirstOrDefault(part => part.Name == partName || part
.FileName.Contains(partName));
Decorate(dbManager, part);
return part;
}
/// <summary>
/// Checks to see if the provided part name is unique.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partName">The part name to check and see if it is unique.</param>
/// <returns>True if no part exists in the database with given name; otherwise false.</returns>
public static bool IsPartNameUnique(DatabaseManager dbManager, string partName)
{
SidekickPart part = dbManager.GetCurrentDbConnection().Table<SidekickPart>().FirstOrDefault(part => part.Name == partName);
return part == null;
}
/// <summary>
/// Gets the species for a specific part.
/// TODO: get from the DB when data is populated.
/// </summary>
/// <param name="allSpecies">The list of all species to return a populated species object from.</param>
/// <param name="partName">The name of the part to get the species for.</param>
/// <returns>The species the part belongs to.</returns>
public static SidekickSpecies GetSpeciesForPart(List<SidekickSpecies> allSpecies, string partName)
{
string shortcode = partName.Split('_').Last().Substring(0, 2);
SidekickSpecies selectedSpecies = allSpecies[0];
foreach (SidekickSpecies species in allSpecies)
{
if (string.Equals(shortcode, species.Code, StringComparison.CurrentCultureIgnoreCase))
{
selectedSpecies = species;
}
}
return selectedSpecies;
}
/// <summary>
/// Updates all of the given parts in the DB. This is an Update only, and will not insert new objects.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
/// <param name="parts">The parts to update</param>
public static void UpdateAll(DatabaseManager dbManager, List<SidekickPart> parts)
{
dbManager.GetCurrentDbConnection().UpdateAll(parts, false);
}
/// <summary>
/// Ensures that the given part has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="part">The part to decorate</param>
private static void Decorate(DatabaseManager dbManager, SidekickPart part)
{
if (part != null)
{
if (part.Species == null && part.PtrSpecies >= 0)
{
part.Species = SidekickSpecies.GetByID(dbManager, part.PtrSpecies);
}
}
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Gets the image associated with this part.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
/// <returns>The image associated with this part.</returns>
public SidekickPartImage GetImageForPart(DatabaseManager dbManager)
{
return SidekickPartImage.GetByPart(dbManager, this);
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
foreach (SidekickPartFilterRow row in SidekickPartFilterRow.GetAllForPart(dbManager, this))
{
row.Delete(dbManager);
}
foreach (SidekickPartPresetRow row in SidekickPartPresetRow.GetAllByPart(dbManager, this))
{
row.Delete(dbManager);
}
foreach (SidekickPartSpeciesLink link in SidekickPartSpeciesLink.GetAllForPart(dbManager, this))
{
link.Delete(dbManager);
}
SidekickPartImage image = SidekickPartImage.GetByPart(dbManager, this);
image?.Delete(dbManager);
dbManager.GetCurrentDbConnection().Delete<SidekickPart>(ID);
}
/// <summary>
/// Gets the GameObject model of this part.
/// </summary>
/// <returns>A GameObject with the part model</returns>
public GameObject GetPartModel()
{
string resource = GetResourcePath(Location);
return Resources.Load<GameObject>(resource);
}
/// <summary>
/// Checks if the file for this part exists.
/// </summary>
/// <returns>True if the file is available; otherwise false</returns>
public bool IsFileAvailable()
{
FileExists = File.Exists(Location);
return FileExists;
}
/// <summary>
/// Gets a resource path for using with Resources.Load() from a full path.
/// </summary>
/// <param name="fullPath">The full path to get the resource path from.</param>
/// <returns>The resource path.</returns>
private string GetResourcePath(string fullPath)
{
int startIndex = fullPath.IndexOf("Resources", StringComparison.Ordinal) + 10;
string resourcePath = fullPath.Substring(startIndex, fullPath.Length - startIndex);
return Path.Combine(Path.GetDirectoryName(resourcePath)?? "", Path.GetFileNameWithoutExtension(resourcePath));
}
/// <inheritdoc cref="Equals"/>
public override bool Equals(object obj)
{
SidekickPart part = (SidekickPart) obj;
if (ID > 0 && part?.ID > 0)
{
return ID == part?.ID;
}
return Name.Equals(part?.Name);
}
/// <inheritdoc cref="GetHashCode"/>
public override int GetHashCode()
{
HashCode hashCode = new HashCode();
hashCode.Add(_species);
hashCode.Add(ID);
hashCode.Add(PtrSpecies);
hashCode.Add((int) Type);
hashCode.Add((int) PartGroup);
hashCode.Add(Name);
hashCode.Add(FileName);
hashCode.Add(Location);
hashCode.Add(UsesWrap);
hashCode.Add(FileExists);
return hashCode.ToHashCode();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c0f548e027c531458516485dbd42cea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,125 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using Synty.SidekickCharacters.Enums;
using System.Collections.Generic;
using System.Linq;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_part_filter")]
public class SidekickPartFilter
{
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("filter_type")]
public FilterType Type { get; set; }
[Column("filter_term")]
public string Term { get; set; }
/// <summary>
/// Gets a specific Part Filter by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Part Filter.</param>
/// <returns>The specific Part Filter if it exists; otherwise null.</returns>
public static SidekickPartFilter GetByID(DatabaseManager dbManager, int id)
{
SidekickPartFilter filter = dbManager.GetCurrentDbConnection().Find<SidekickPartFilter>(id);
return filter;
}
/// <summary>
/// Gets a list of all the part filters in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all part filters in the database.</returns>
public static List<SidekickPartFilter> GetAll(DatabaseManager dbManager)
{
List<SidekickPartFilter> filters = dbManager.GetCurrentDbConnection().Table<SidekickPartFilter>().ToList();
return filters;
}
/// <summary>
/// Gets a list of all the filters in the database for a given Character Part Type.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="filterType">The Character Part Type to get all the filters for.</param>
/// <param name="excludeFiltersWithNoParts">Whether to exclude filters that have no parts associated</param>
/// <returns>A list of all filters for the given Character Part Type in the database.</returns>
public static List<SidekickPartFilter> GetAllForFilterType(DatabaseManager dbManager, FilterType filterType, bool
excludeFiltersWithNoParts = true)
{
List<SidekickPartFilter> filters = dbManager.GetCurrentDbConnection().Table<SidekickPartFilter>().Where(filter => filter.Type == filterType).ToList();
if (excludeFiltersWithNoParts)
{
List<SidekickPartFilter> toRemove = new List<SidekickPartFilter>();
foreach (SidekickPartFilter filter in filters)
{
List<SidekickPartFilterRow> rows = SidekickPartFilterRow.GetAllForFilter(dbManager, filter);
rows = rows.Where(row => !row.Part.FileName.Contains("_BASE_")).ToList();
if (rows.Count < 1)
{
toRemove.Add(filter);
}
}
filters.RemoveAll(filter => toRemove.Contains(filter));
}
return filters;
}
/// <summary>
/// Searches for a filter in the database with the given term and filter type.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="filterTerm">The term to search for.</param>
/// <param name="filterType">The Character Part Type to search for.</param>
/// <returns>The filter with the given term and given Character Part Type in the database if it exist; otherwise null.</returns>
public static SidekickPartFilter GetByTermAndFilterType(DatabaseManager dbManager, string filterTerm, FilterType filterType)
{
SidekickPartFilter filter = dbManager.GetCurrentDbConnection().Table<SidekickPartFilter>()
.FirstOrDefault(filter => filter.Term == filterTerm && filter.Type == filterType);
return filter;
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
foreach (SidekickPartFilterRow row in SidekickPartFilterRow.GetAllForFilter(dbManager, this))
{
row.Delete(dbManager);
}
dbManager.GetCurrentDbConnection().Delete<SidekickPartFilter>(ID);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0150aa2dd4f647b5992f3db3fe96b562
timeCreated: 1740023330

View File

@@ -0,0 +1,219 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using Synty.SidekickCharacters.Enums;
using System.Collections.Generic;
using System.Linq;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_part_filter_row")]
public class SidekickPartFilterRow
{
private SidekickPartFilter _filter;
private SidekickPart _part;
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("ptr_filter")]
public int PtrFilter { get; set; }
[Column("ptr_part")]
public int PtrPart { get; set; }
[Ignore]
public SidekickPartFilter Filter
{
get => _filter;
set
{
_filter = value;
PtrFilter = value.ID;
}
}
[Ignore]
public SidekickPart Part
{
get => _part;
set
{
_part = value;
PtrPart = value.ID;
}
}
/// <summary>
/// Gets a specific Part Filter by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Part Filter.</param>
/// <returns>The specific Part Filter if it exists; otherwise null.</returns>
public static SidekickPartFilterRow GetByID(DatabaseManager dbManager, int id)
{
SidekickPartFilterRow filterRow = dbManager.GetCurrentDbConnection().Find<SidekickPartFilterRow>(id);
Decorate(dbManager, filterRow);
return filterRow;
}
/// <summary>
/// Gets a list of all the part filters in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all part filters in the database.</returns>
public static List<SidekickPartFilterRow> GetAll(DatabaseManager dbManager)
{
List<SidekickPartFilterRow> filterRows = dbManager.GetCurrentDbConnection().Table<SidekickPartFilterRow>().ToList();
foreach (SidekickPartFilterRow row in filterRows)
{
Decorate(dbManager, row);
}
return filterRows;
}
/// <summary>
/// Gets a list of all the part filter rows in the database for a given part filter.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="filter">The Part Filter to get all the part filter rows for.</param>
/// <returns>A list of all part filter rows for the given Part Filter in the database.</returns>
public static List<SidekickPartFilterRow> GetAllForFilter(DatabaseManager dbManager, SidekickPartFilter filter, bool excludeMissingParts = true)
{
List<SidekickPartFilterRow> filterRows = dbManager.GetCurrentDbConnection().Table<SidekickPartFilterRow>().Where(filterRow => filterRow
.PtrFilter == filter.ID).ToList();
List<SidekickPartFilterRow> toRemove = new List<SidekickPartFilterRow>();
foreach (SidekickPartFilterRow row in filterRows)
{
Decorate(dbManager, row);
if (row.Part == null)
{
toRemove.Add(row);
}
}
if (excludeMissingParts)
{
foreach (SidekickPartFilterRow row in filterRows)
{
if (!row.Part.FileExists)
{
toRemove.Add(row);
}
}
}
filterRows.RemoveAll(row => toRemove.Contains(row));
return filterRows;
}
/// <summary>
/// Gets a list of all the part names in the database for a given part filter, species and part type.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="filter">The Part Filter to get all the part names for.</param>
/// <param name="species">The Species to get all the part names for.</param>
/// <param name="type">The Part Type to get all the part names for.</param>
/// <returns>A list of all the part names in the database for a given part filter, species and part type.</returns>
public static List<string> GetAllPartNamesForFilterSpeciesAndType(DatabaseManager dbManager,
SidekickPartFilter filter,
SidekickSpecies species,
CharacterPartType type)
{
List<string> filterRows = dbManager.GetCurrentDbConnection().Query<SidekickPart>("SELECT p.* FROM sk_part_filter_row AS pfw JOIN "
+ "sk_part AS p ON pfw.ptr_part = p.id JOIN sk_part_species_link AS s ON p.id = s.ptr_part WHERE pfw.ptr_filter = " + filter.ID
+ " AND s.ptr_species = " + species.ID + " AND p.type = " + (int)type + " AND p.file_exists = 1").ToList().Select(part => part.Name)
.ToList();
return filterRows;
}
/// <summary>
/// Gets a part filter row in the database for a given part filter and part.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="filter">The Part Filter to get all the part filter row for.</param>
/// <param name="part">The part to get the row for.</param>
/// <returns>The part filter row for the given Part Filter and Part in the database.</returns>
public static SidekickPartFilterRow GetForFilterAndPart(DatabaseManager dbManager, SidekickPartFilter filter, SidekickPart part)
{
SidekickPartFilterRow row = dbManager.GetCurrentDbConnection().Table<SidekickPartFilterRow>().FirstOrDefault(filterRow => filterRow
.PtrFilter == filter.ID && filterRow.PtrPart == part.ID
);
Decorate(dbManager, row);
return row;
}
/// <summary>
/// Gets a list of all the part filter rows in the database for a given part.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="part">The part to get the rows for.</param>
/// <returns>The part filter rows for the given Part in the database.</returns>
public static List<SidekickPartFilterRow> GetAllForPart(DatabaseManager dbManager, SidekickPart part)
{
List<SidekickPartFilterRow> rows = dbManager.GetCurrentDbConnection().Table<SidekickPartFilterRow>().Where(filterRow => filterRow.PtrPart == part.ID).ToList();
foreach (SidekickPartFilterRow row in rows)
{
Decorate(dbManager, row);
}
return rows;
}
/// <summary>
/// Ensures that the given part filter row has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="filterRow">The part filter row to decorate</param>
private static void Decorate(DatabaseManager dbManager, SidekickPartFilterRow filterRow)
{
SidekickPart part = SidekickPart.GetByID(dbManager, filterRow.PtrPart);
if (part == null)
{
filterRow.Delete(dbManager);
}
else
{
filterRow.Filter ??= SidekickPartFilter.GetByID(dbManager, filterRow.PtrFilter);
filterRow.Part ??= part;
}
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
dbManager.GetCurrentDbConnection().Delete<SidekickPartFilterRow>(ID);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 81f100234a4e4bedb2b3cdd3ea26edb1
timeCreated: 1740429753

View File

@@ -0,0 +1,124 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_part_image")]
public class SidekickPartImage
{
private SidekickPart _part;
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("ptr_part")]
public int PtrPart { get; set; }
[Column("img_data")]
public byte[] ImageData { get; set; }
[Column("img_width")]
public int Width { get; set; }
[Column("img_height")]
public int Height { get; set; }
[Ignore]
public SidekickPart Part
{
get => _part;
set
{
_part = value;
PtrPart = value.ID;
}
}
/// <summary>
/// Gets a specific Part Image by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Part Image.</param>
/// <returns>The specific Part Image if it exists; otherwise null.</returns>
public static SidekickPartImage GetByID(DatabaseManager dbManager, int id)
{
SidekickPartImage partImage = dbManager.GetCurrentDbConnection().Find<SidekickPartImage>(id);
Decorate(dbManager, partImage);
return partImage;
}
/// <summary>
/// Gets a specific Part Image for a specific part.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="part">The Part to get the image for.</param>
/// <returns>The specific Part Image for a specific part if it exists; otherwise null.</returns>
public static SidekickPartImage GetByPart(DatabaseManager dbManager, SidekickPart part)
{
SidekickPartImage partImage = dbManager.GetCurrentDbConnection().Table<SidekickPartImage>()
.FirstOrDefault(pi => pi.PtrPart == part.ID);
Decorate(dbManager, partImage);
return partImage;
}
/// <summary>
/// Gets a list of all the Part Images in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all part images in the database.</returns>
public static List<SidekickPartImage> GetAll(DatabaseManager dbManager)
{
List<SidekickPartImage> partImages = dbManager.GetCurrentDbConnection().Table<SidekickPartImage>().ToList();
foreach (SidekickPartImage partImage in partImages)
{
Decorate(dbManager, partImage);
}
return partImages;
}
/// <summary>
/// Ensures that the given preset has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partImage">The part image to decorate</param>
private static void Decorate(DatabaseManager dbManager, SidekickPartImage partImage)
{
if (partImage != null)
{
if (partImage.Part == null && partImage.PtrPart >= 0)
{
partImage.Part ??= SidekickPart.GetByID(dbManager, partImage.PtrPart);
}
}
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
dbManager.GetCurrentDbConnection().Delete<SidekickPartImage>(ID);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 77cb14daf5fc40d7854189c730575b4c
timeCreated: 1739227504

View File

@@ -0,0 +1,48 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_pmdata")]
public class SidekickPartMetaData
{
[PrimaryKey, Column("id")]
public int ID { get; set; }
[Column("part_guid")]
public string PartGuid { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("value")]
public string Value { get; set; }
[Column("type")]
public string Type { get; set; }
[Column("value_type")]
public string ValueType { get; set; }
[Column("last_updated")]
public DateTime LastUpdated { get; set; }
/// <summary>
/// Gets a list of part guids from the meta data based on the passed in type and value.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="type">The type of metadata to search for.</param>
/// <param name="value">The value of the metadata to search for.</param>
/// <returns>A list of part guids that match the given criteria.</returns>
public static List<string> GetPartGuidsByMetaDataValue(DatabaseManager dbManager, string type, string value)
{
return dbManager.GetCurrentDbConnection().Table<SidekickPartMetaData>()
.Where(meta => meta.Type == type && meta.Value == value)
.Select(meta => meta.PartGuid)
.ToList();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a9bc8817790f2341ae3c31d87d94f72
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,285 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using Synty.SidekickCharacters.Enums;
using Synty.SidekickCharacters.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_part_preset")]
public class SidekickPartPreset
{
private SidekickSpecies _species;
[PrimaryKey]
[AutoIncrement]
[Column("id")]
public int ID { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("part_group")]
public PartGroup PartGroup { get; set; }
[Column("ptr_species")]
public int PtrSpecies { get; set; }
[Column("outfit")]
public string Outfit { get; set; }
[Ignore]
public SidekickSpecies Species
{
get => _species;
set
{
_species = value;
PtrSpecies = value.ID;
}
}
/// <summary>
/// Gets a specific Preset by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Preset.</param>
/// <returns>The specific Preset if it exists; otherwise null.</returns>
public static SidekickPartPreset GetByID(DatabaseManager dbManager, int id)
{
SidekickPartPreset partPreset = dbManager.GetCurrentDbConnection().Find<SidekickPartPreset>(id);
Decorate(dbManager, partPreset);
return partPreset;
}
/// <summary>
/// Gets a list of all the Presets in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all presets in the database.</returns>
public static List<SidekickPartPreset> GetAll(DatabaseManager dbManager)
{
List<SidekickPartPreset> partPresets = dbManager.GetCurrentDbConnection().Table<SidekickPartPreset>().ToList();
foreach (SidekickPartPreset partPreset in partPresets)
{
Decorate(dbManager, partPreset);
}
return partPresets;
}
/// <summary>
/// Gets a list of all the Part Presets in the database that have the matching species.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="species">The species to get all the part presets for.</param>
/// <returns>A list of all part presets in the database for the given species.</returns>
public static List<SidekickPartPreset> GetAllBySpecies(DatabaseManager dbManager, SidekickSpecies species)
{
List<SidekickPartPreset> partPresets = dbManager.GetCurrentDbConnection().Table<SidekickPartPreset>()
.Where(partPreset => partPreset.PtrSpecies == species.ID)
.ToList();
foreach (SidekickPartPreset partPreset in partPresets)
{
partPreset.Species = species;
}
return partPresets;
}
/// <summary>
/// Gets a Part Presets in the database with the matching name if one exists.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="name">The name of the preset to retrieve.</param>
/// <returns>Returns a Part Presets in the database with the matching name if one exists; otherwise null.</returns>
public static SidekickPartPreset GetByName(DatabaseManager dbManager, string name)
{
SidekickPartPreset partPreset = dbManager.GetCurrentDbConnection()
.Table<SidekickPartPreset>()
.FirstOrDefault(partPreset => partPreset.Name == name);
if (partPreset != null)
{
Decorate(dbManager, partPreset);
}
return partPreset;
}
/// <summary>
/// Gets a list of all the Part Presets in the database that have the matching species and part group.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partGroup">The part group to filter search by.</param>
/// <returns>A list of all part presets in the database for the given species and part group.</returns>
public static List<SidekickPartPreset> GetAllByGroup(DatabaseManager dbManager, PartGroup partGroup, bool excludeMissingParts = true)
{
List<SidekickPartPreset> partPresets = dbManager.GetCurrentDbConnection().Table<SidekickPartPreset>()
.Where(partPreset => partPreset.PartGroup == partGroup)
.ToList();
foreach (SidekickPartPreset partPreset in partPresets)
{
Decorate(dbManager, partPreset);
}
if (excludeMissingParts)
{
List<SidekickPartPreset> toRemove = new List<SidekickPartPreset>();
foreach (SidekickPartPreset partPreset in partPresets)
{
if (!partPreset.HasAllPartsAvailable(dbManager))
{
toRemove.Add(partPreset);
}
}
partPresets.RemoveAll(preset => toRemove.Contains(preset));
}
return partPresets;
}
/// <summary>
/// Gets a list of all the Part Presets in the database that have the matching species and part group.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="species">The species to get all the part presets for.</param>
/// <param name="partGroup">The part group to filter search by.</param>
/// <returns>A list of all part presets in the database for the given species and part group.</returns>
public static List<SidekickPartPreset> GetAllBySpeciesAndGroup(DatabaseManager dbManager, SidekickSpecies species, PartGroup partGroup)
{
List<SidekickPartPreset> partPresets = dbManager.GetCurrentDbConnection().Table<SidekickPartPreset>()
.Where(partPreset => partPreset.PtrSpecies == species.ID && partPreset.PartGroup == partGroup)
.ToList();
foreach (SidekickPartPreset partPreset in partPresets)
{
partPreset.Species = species;
}
return partPresets;
}
/// <summary>
/// Ensures that the given set has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partPreset">The color set to decorate</param>
/// <returns>A color set with all DTO class properties set</returns>
private static void Decorate(DatabaseManager dbManager, SidekickPartPreset partPreset)
{
if (partPreset.Species == null && partPreset.PtrSpecies >= 0)
{
partPreset.Species = SidekickSpecies.GetByID(dbManager, partPreset.PtrSpecies);
}
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID < 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
foreach (SidekickPartPresetRow row in SidekickPartPresetRow.GetAllByPreset(dbManager, this))
{
row.Delete(dbManager);
}
foreach (SidekickPresetFilterRow row in SidekickPresetFilterRow.GetAllForPreset(dbManager, this))
{
row.Delete(dbManager);
}
SidekickPartPresetImage image = SidekickPartPresetImage.GetByPresetAndPartGroup(dbManager, this, PartGroup);
image?.Delete(dbManager);
dbManager.GetCurrentDbConnection().Delete<SidekickPartPreset>(ID);
}
/// <summary>
/// Determines if all the parts associated with this preset are valid (has a file in the project).
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
/// <returns>True if all parts are valid; otherwise False.</returns>
public bool HasAllPartsAvailable(DatabaseManager dbManager)
{
List<SidekickPartPresetRow> allRows = SidekickPartPresetRow.GetAllByPreset(dbManager, this);
return allRows.Count > 0 && allRows.All(row => row.HasValidPart());
}
/// <summary>
/// Determines if all the parts associated with this preset are valid (has a file in the project).
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
/// <returns>True if all parts are valid; otherwise False.</returns>
public bool HasOnlyBasePartsAndAllAvailable(DatabaseManager dbManager)
{
List<SidekickPartPresetRow> allRows = SidekickPartPresetRow.GetAllByPreset(dbManager, this);
return allRows.Count > 0 && allRows.All(row => row.HasValidPart() && (row.Part == null || PartUtils.IsBaseSpeciesPart(row.PartName)));
}
/// <summary>
/// Checks the equality of this preset to the given preset.
/// </summary>
/// <param name="other">The preset to check equality with.</param>
/// <returns>True if the presets are equal, otherwise false.</returns>
protected bool Equals(SidekickPartPreset other)
{
return ID == other.ID
&& Name == other.Name
&& PartGroup == other.PartGroup
&& PtrSpecies == other.PtrSpecies;
}
/// <inheritdoc cref="Equals"/>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != this.GetType())
{
return false;
}
return Equals((SidekickPartPreset) obj);
}
/// <inheritdoc cref="GetHashCode"/>
public override int GetHashCode()
{
return HashCode.Combine(ID, Name, (int) PartGroup, PtrSpecies);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e0b8001ee5bb39c47a2afe14d2c826f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,158 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using Synty.SidekickCharacters.Enums;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_part_preset_image")]
public class SidekickPartPresetImage
{
private SidekickPartPreset _partPreset;
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("ptr_part_preset")]
public int PtrPreset { get; set; }
[Column("part_group")]
public PartGroup PartGroup { get; set; }
[Column("img_data")]
public byte[] ImageData { get; set; }
[Column("img_width")]
public int Width { get; set; }
[Column("img_height")]
public int Height { get; set; }
[Ignore]
public SidekickPartPreset PartPreset
{
get => _partPreset;
set
{
_partPreset = value;
PtrPreset = value.ID;
}
}
/// <summary>
/// Gets a specific Preset Part by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Preset Part.</param>
/// <returns>The specific Preset Part if it exists; otherwise null.</returns>
public static SidekickPartPresetImage GetByID(DatabaseManager dbManager, int id)
{
SidekickPartPresetImage partPresetImage = dbManager.GetCurrentDbConnection().Find<SidekickPartPresetImage>(id);
Decorate(dbManager, partPresetImage);
return partPresetImage;
}
/// <summary>
/// Gets a list of all the Preset Parts in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all preset parts in the database.</returns>
public static List<SidekickPartPresetImage> GetAll(DatabaseManager dbManager)
{
List<SidekickPartPresetImage> partPresetImages = dbManager.GetCurrentDbConnection().Table<SidekickPartPresetImage>().ToList();
foreach (SidekickPartPresetImage partPresetImage in partPresetImages)
{
Decorate(dbManager, partPresetImage);
}
return partPresetImages;
}
/// <summary>
/// Gets a list of all the Preset Part Images in the database that have the matching Part Preset.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partPreset">The preset to get all the preset part images for.</param>
/// <returns>A list of all preset part images in the database for the given preset.</returns>
public static List<SidekickPartPresetImage> GetAllByPreset(DatabaseManager dbManager, SidekickPartPreset partPreset)
{
List<SidekickPartPresetImage> partPresetImages = dbManager.GetCurrentDbConnection().Table<SidekickPartPresetImage>()
.Where(presetPart => presetPart.PtrPreset == partPreset.ID)
.ToList();
foreach (SidekickPartPresetImage partPresetImage in partPresetImages)
{
Decorate(dbManager, partPresetImage);
}
return partPresetImages;
}
/// <summary>
/// Gets the Preset Part Image in the database that have the matching Part Preset and Part Group.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partPreset">The preset to get the preset part image for.</param>
/// <param name="partGroup">The part group to filter the results by.</param>
/// <returns>The preset part image in the database for the given preset and part group.</returns>
public static SidekickPartPresetImage GetByPresetAndPartGroup(
DatabaseManager dbManager,
SidekickPartPreset partPreset,
PartGroup partGroup
)
{
SidekickPartPresetImage partPresetImage = dbManager.GetCurrentDbConnection().Table<SidekickPartPresetImage>()
.FirstOrDefault(presetPart => presetPart.PtrPreset == partPreset.ID && presetPart.PartGroup == partGroup);
if (partPresetImage != null)
{
Decorate(dbManager, partPresetImage);
}
return partPresetImage;
}
/// <summary>
/// Ensures that the given preset has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partPresetImage">The color preset to decorate</param>
/// <returns>A color set with all DTO class properties set</returns>
private static void Decorate(DatabaseManager dbManager, SidekickPartPresetImage partPresetImage)
{
if (partPresetImage != null)
{
if (partPresetImage.PartPreset == null && partPresetImage.PtrPreset >= 0)
{
partPresetImage.PartPreset = SidekickPartPreset.GetByID(dbManager, partPresetImage.PtrPreset);
}
}
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
dbManager.GetCurrentDbConnection().Delete<SidekickPartPresetImage>(ID);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 524edcf93e2acd74f80d26307dc62db5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,190 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_part_preset_row")]
public class SidekickPartPresetRow
{
private SidekickPartPreset _partPreset;
private SidekickPart _part;
[PrimaryKey]
[AutoIncrement]
[Column("id")]
public int ID { get; set; }
[Column("part_name")]
public string PartName { get; set; }
[Column("ptr_part_preset")]
public int PtrPreset { get; set; }
[Column("ptr_part")]
public int PtrPart { get; set; } = -1;
[Column("part_type")]
public string PartType { get; set; }
[Ignore]
public SidekickPartPreset PartPreset
{
get => _partPreset;
set
{
_partPreset = value;
PtrPreset = value.ID;
}
}
[Ignore]
public SidekickPart Part
{
get => _part;
set
{
_part = value;
PtrPart = value.ID;
}
}
/// <summary>
/// Gets a specific Preset Part by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Preset Part.</param>
/// <returns>The specific Preset Part if it exists; otherwise null.</returns>
public static SidekickPartPresetRow GetByID(DatabaseManager dbManager, int id)
{
SidekickPartPresetRow partPreset = dbManager.GetCurrentDbConnection().Find<SidekickPartPresetRow>(id);
Decorate(dbManager, partPreset);
return partPreset;
}
/// <summary>
/// Gets a list of all the Preset Parts in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all preset parts in the database.</returns>
public static List<SidekickPartPresetRow> GetAll(DatabaseManager dbManager)
{
List<SidekickPartPresetRow> presetParts = dbManager.GetCurrentDbConnection().Table<SidekickPartPresetRow>().ToList();
foreach (SidekickPartPresetRow preset in presetParts)
{
Decorate(dbManager, preset);
}
return presetParts;
}
/// <summary>
/// Gets a list of all the Preset Part rows in the database that have the matching species.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partPreset">The preset to get all the preset part rows for.</param>
/// <returns>A list of all preset part rows in the database for the given preset.</returns>
public static List<SidekickPartPresetRow> GetAllByPreset(DatabaseManager dbManager, SidekickPartPreset partPreset)
{
List<SidekickPartPresetRow> presetParts = dbManager.GetCurrentDbConnection().Table<SidekickPartPresetRow>()
.Where(presetPart => presetPart.PtrPreset == partPreset.ID)
.ToList();
foreach (SidekickPartPresetRow presetPart in presetParts)
{
Decorate(dbManager, presetPart);
}
return presetParts;
}
/// <summary>
/// Gets a list of all the Preset Part rows in the database that have the matching part.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="part">The part to get all the preset part rows for.</param>
/// <returns>A list of all preset part rows in the database for the given part.</returns>
public static List<SidekickPartPresetRow> GetAllByPart(DatabaseManager dbManager, SidekickPart part)
{
List<SidekickPartPresetRow> presetParts = dbManager.GetCurrentDbConnection().Table<SidekickPartPresetRow>()
.Where(presetPart => presetPart.PtrPart == part.ID)
.ToList();
foreach (SidekickPartPresetRow presetPart in presetParts)
{
Decorate(dbManager, presetPart);
}
return presetParts;
}
/// <summary>
/// Ensures that the given preset has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partPreset">The color preset to decorate</param>
/// <returns>A color set with all DTO class properties set</returns>
private static void Decorate(DatabaseManager dbManager, SidekickPartPresetRow partPreset)
{
if (partPreset != null)
{
if (partPreset.PartPreset == null && partPreset.PtrPreset >= 0)
{
partPreset.PartPreset = SidekickPartPreset.GetByID(dbManager, partPreset.PtrPreset);
}
if (partPreset.Part == null && partPreset.PtrPart >= 0)
{
partPreset.Part = SidekickPart.GetByID(dbManager, partPreset.PtrPart);
}
else if (partPreset.Part == null && partPreset.PtrPart < 0)
{
SidekickPart part = SidekickPart.SearchForByName(dbManager, partPreset.PartName);
if (part != null)
{
partPreset.Part = part;
}
}
}
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID < 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
dbManager.GetCurrentDbConnection().Delete<SidekickPartPresetRow>(ID);
}
/// <summary>
/// Checks whether the associated part has a file that exists in the project.
/// </summary>
/// <returns>True if the part has a file in the project; otherwise False.</returns>
public bool HasValidPart()
{
return Part == null || Part.FileExists;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a33e02c0fd666db41a6558e5ff160bc7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,181 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_part_species_link")]
public class SidekickPartSpeciesLink
{
private SidekickSpecies _species;
private SidekickPart _part;
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("ptr_species")]
public int PtrSpecies { get; set; }
[Column("ptr_part")]
public int PtrPart { get; set; }
[Ignore]
public SidekickSpecies Species
{
get => _species;
set
{
_species = value;
PtrSpecies = value.ID;
}
}
[Ignore]
public SidekickPart Part
{
get => _part;
set
{
_part = value;
PtrPart = value.ID;
}
}
/// <summary>
/// Gets a specific Part Species Link by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Part Species Link.</param>
/// <returns>The specific Part Species Link if it exists; otherwise null.</returns>
public static SidekickPartSpeciesLink GetByID(DatabaseManager dbManager, int id)
{
SidekickPartSpeciesLink part = dbManager.GetCurrentDbConnection().Find<SidekickPartSpeciesLink>(id);
Decorate(dbManager, part);
return part;
}
/// <summary>
/// Gets a list of all the Part Species Links in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all Part Species Links in the database.</returns>
public static List<SidekickPartSpeciesLink> GetAll(DatabaseManager dbManager)
{
List<SidekickPartSpeciesLink> partSpeciesLinks = dbManager.GetCurrentDbConnection().Table<SidekickPartSpeciesLink>().ToList();
foreach (SidekickPartSpeciesLink partSpeciesLink in partSpeciesLinks)
{
Decorate(dbManager, partSpeciesLink);
}
return partSpeciesLinks;
}
/// <summary>
/// Gets a list of all the Part Species Links in the database for the specific species.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="species">The species to search for all parts species links for.</param>
/// <returns>A list of all Part Species Links in the database for the specified species.</returns>
public static List<SidekickPartSpeciesLink> GetAllForSpecies(DatabaseManager dbManager, SidekickSpecies species)
{
List<SidekickPartSpeciesLink> partSpeciesLinks = dbManager.GetCurrentDbConnection().Table<SidekickPartSpeciesLink>()
.Where(psl => psl.PtrSpecies == species.ID)
.ToList();
foreach (SidekickPartSpeciesLink partSpeciesLink in partSpeciesLinks)
{
Decorate(dbManager, partSpeciesLink);
}
return partSpeciesLinks;
}
/// <summary>
/// Gets a list of all the Part Species Links in the database for the specific part.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="part">The part to search for all parts species links for.</param>
/// <returns>A list of all Part Species Links in the database for the specified part.</returns>
public static List<SidekickPartSpeciesLink> GetAllForPart(DatabaseManager dbManager, SidekickPart part)
{
List<SidekickPartSpeciesLink> partSpeciesLinks = dbManager.GetCurrentDbConnection().Table<SidekickPartSpeciesLink>()
.Where(psl => psl.PtrPart == part.ID)
.ToList();
foreach (SidekickPartSpeciesLink partSpeciesLink in partSpeciesLinks)
{
Decorate(dbManager, partSpeciesLink);
}
return partSpeciesLinks;
}
/// <summary>
/// Gets a list of all the Part Species Links in the database for the specific part.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="species">The species to search for all parts species links for.</param>
/// <param name="part">The part to search for all parts species links for.</param>
/// <returns>A list of all Part Species Links in the database for the specified part.</returns>
public static SidekickPartSpeciesLink GetForSpeciesAndPart(DatabaseManager dbManager, SidekickSpecies species, SidekickPart part)
{
SidekickPartSpeciesLink partSpeciesLink = dbManager.GetCurrentDbConnection().Table<SidekickPartSpeciesLink>()
.FirstOrDefault(psl => psl.PtrSpecies == species.ID && psl.PtrPart == part.ID);
Decorate(dbManager, partSpeciesLink);
return partSpeciesLink;
}
/// <summary>
/// Ensures that the given part has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="partSpeciesLink">The part to decorate</param>
private static void Decorate(DatabaseManager dbManager, SidekickPartSpeciesLink partSpeciesLink)
{
if (partSpeciesLink != null)
{
if (partSpeciesLink.Species == null && partSpeciesLink.PtrSpecies >= 0)
{
partSpeciesLink.Species = SidekickSpecies.GetByID(dbManager, partSpeciesLink.PtrSpecies);
}
if (partSpeciesLink.Part == null && partSpeciesLink.PtrPart >= 0)
{
partSpeciesLink.Part = SidekickPart.GetByID(dbManager, partSpeciesLink.PtrPart);
}
}
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
dbManager.GetCurrentDbConnection().Delete<SidekickPartSpeciesLink>(ID);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b31bc1fc8ff44c3c9c0629ebaf7d69c2
timeCreated: 1745892314

View File

@@ -0,0 +1,163 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System.Collections.Generic;
using System.Linq;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_preset_filter")]
public class SidekickPresetFilter
{
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("filter_term")]
public string Term { get; set; }
private List<SidekickPartPreset> _allPresets = new List<SidekickPartPreset>();
/// <summary>
/// Gets a specific Preset Filter by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Preset Filter.</param>
/// <returns>The specific Preset Filter if it exists; otherwise null.</returns>
public static SidekickPresetFilter GetByID(DatabaseManager dbManager, int id)
{
SidekickPresetFilter filter = dbManager.GetCurrentDbConnection().Find<SidekickPresetFilter>(id);
return filter;
}
/// <summary>
/// Gets a list of all the Preset filters in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="excludeFiltersWithNoParts">Whether to exclude filters without any parts from the list or not.</param>
/// <returns>A list of all Preset filters in the database.</returns>
public static List<SidekickPresetFilter> GetAll(DatabaseManager dbManager, bool excludeFiltersWithNoParts = true)
{
List<SidekickPresetFilter> filters = dbManager.GetCurrentDbConnection().Table<SidekickPresetFilter>().ToList();
if (excludeFiltersWithNoParts)
{
List<SidekickPresetFilter> toRemove = new List<SidekickPresetFilter>();
foreach (SidekickPresetFilter filter in filters)
{
if (filter.GetAllPresetsForFilter(dbManager).Count < 1)
{
toRemove.Add(filter);
}
}
filters.RemoveAll(filter => toRemove.Contains(filter));
}
return filters;
}
/// <summary>
/// Searches for a filter in the database with the given term and filter type.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="filterTerm">The term to search for.</param>
/// <returns>The filter with the given term in the database if it exist; otherwise null.</returns>
public static SidekickPresetFilter GetByTerm(DatabaseManager dbManager, string filterTerm)
{
SidekickPresetFilter filter = dbManager.GetCurrentDbConnection().Table<SidekickPresetFilter>()
.FirstOrDefault(filter => filter.Term == filterTerm);
return filter;
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
foreach (SidekickPresetFilterRow row in SidekickPresetFilterRow.GetAllForFilter(dbManager, this))
{
row.Delete(dbManager);
}
dbManager.GetCurrentDbConnection().Delete<SidekickPresetFilter>(ID);
}
/// <summary>
/// Gets all of the presets for this filter.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
/// <param name="excludeMissingParts">Exclude presets where parts are missing or not.</param>
/// <param name="refreshList">Whether to refresh the list from the database or not.</param>
/// <returns>All of the presets for this filter.</returns>
public List<SidekickPartPreset> GetAllPresetsForFilter(DatabaseManager dbManager, bool excludeMissingParts = true, bool refreshList = false)
{
if (refreshList || _allPresets.Count < 1)
{
List<SidekickPresetFilterRow> filterRows = SidekickPresetFilterRow.GetAllForFilter(dbManager, this, excludeMissingParts);
_allPresets = filterRows.Select(row => row.Preset).ToList();
}
return _allPresets;
}
/// <summary>
/// Checks if this filter and the given filter are the same filter.
/// </summary>
/// <param name="other">The filter to check.</param>
/// <returns>True, if they are the same filter (IDs match); otherwise false.</returns>
protected bool Equals(SidekickPresetFilter other)
{
return ID == other.ID;
}
/// <inheritdoc cref="Equals"/>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != this.GetType())
{
return false;
}
return Equals((SidekickPresetFilter) obj);
}
/// <inheritdoc cref="GetHashCode"/>
public override int GetHashCode()
{
return ID;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9c5720e7c54f49fcb6b353ab3fdc8d47
timeCreated: 1744592126

View File

@@ -0,0 +1,197 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_preset_filter_row")]
public class SidekickPresetFilterRow
{
private SidekickPresetFilter _filter;
private SidekickPartPreset _preset;
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("ptr_filter")]
public int PtrFilter { get; set; }
[Column("ptr_preset")]
public int PtrPreset { get; set; }
[Ignore]
public SidekickPresetFilter Filter
{
get => _filter;
set
{
_filter = value;
PtrFilter = value.ID;
}
}
[Ignore]
public SidekickPartPreset Preset
{
get => _preset;
set
{
_preset = value;
PtrPreset = value.ID;
}
}
/// <summary>
/// Gets a specific Preset Filter by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Preset Filter.</param>
/// <returns>The specific Preset Filter if it exists; otherwise null.</returns>
public static SidekickPresetFilterRow GetByID(DatabaseManager dbManager, int id)
{
SidekickPresetFilterRow filterRow = dbManager.GetCurrentDbConnection().Find<SidekickPresetFilterRow>(id);
Decorate(dbManager, filterRow);
return filterRow;
}
/// <summary>
/// Gets a list of all the preset filters in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all preset filters in the database.</returns>
public static List<SidekickPresetFilterRow> GetAll(DatabaseManager dbManager)
{
List<SidekickPresetFilterRow> filterRows = dbManager.GetCurrentDbConnection().Table<SidekickPresetFilterRow>().ToList();
foreach (SidekickPresetFilterRow row in filterRows)
{
Decorate(dbManager, row);
}
return filterRows;
}
/// <summary>
/// Gets a list of all the preset filter rows in the database for a given preset filter.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="filter">The Preset Filter to get all the preset filter rows for.</param>
/// <returns>A list of all preset filter rows for the given Preset Filter in the database.</returns>
public static List<SidekickPresetFilterRow> GetAllForFilter(DatabaseManager dbManager, SidekickPresetFilter filter, bool excludeMissingParts = true)
{
List<SidekickPresetFilterRow> filterRows = dbManager.GetCurrentDbConnection().Table<SidekickPresetFilterRow>().Where(filterRow => filterRow
.PtrFilter == filter.ID).ToList();
List<SidekickPresetFilterRow> toRemove = new List<SidekickPresetFilterRow>();
foreach (SidekickPresetFilterRow row in filterRows)
{
Decorate(dbManager, row);
if (row.Preset == null)
{
toRemove.Add(row);
}
}
if (excludeMissingParts)
{
foreach (SidekickPresetFilterRow row in filterRows)
{
if (!row.Preset.HasAllPartsAvailable(dbManager))
{
toRemove.Add(row);
}
}
}
filterRows.RemoveAll(row => toRemove.Contains(row));
return filterRows;
}
/// <summary>
/// Gets a preset filter row in the database for a given preset filter and preset.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="filter">The Preset Filter to get all the preset filter row for.</param>
/// <param name="preset">The preset to get the row for.</param>
/// <returns>The preset filter row for the given Preset Filter and Preset in the database.</returns>
public static SidekickPresetFilterRow GetForFilterAndPreset(DatabaseManager dbManager, SidekickPresetFilter filter, SidekickPartPreset preset)
{
SidekickPresetFilterRow row = dbManager.GetCurrentDbConnection().Table<SidekickPresetFilterRow>().FirstOrDefault(filterRow => filterRow
.PtrFilter == filter.ID && filterRow.PtrPreset == preset.ID
);
Decorate(dbManager, row);
return row;
}
/// <summary>
/// Gets a list of all the preset filter rows in the database for a given part.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="preset">The preset to get the rows for.</param>
/// <returns>The preset filter rows for the given Preset in the database.</returns>
public static List<SidekickPresetFilterRow> GetAllForPreset(DatabaseManager dbManager, SidekickPartPreset preset)
{
List<SidekickPresetFilterRow> rows = dbManager.GetCurrentDbConnection().Table<SidekickPresetFilterRow>()
.Where(filterRow => filterRow.PtrPreset == preset.ID).ToList();
foreach (SidekickPresetFilterRow row in rows)
{
Decorate(dbManager, row);
}
return rows;
}
/// <summary>
/// Ensures that the given preset filter row has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="filterRow">The preset filter row to decorate</param>
private static void Decorate(DatabaseManager dbManager, SidekickPresetFilterRow filterRow)
{
SidekickPartPreset preset = SidekickPartPreset.GetByID(dbManager, filterRow.PtrPreset);
if (preset == null)
{
filterRow.Delete(dbManager);
}
else
{
filterRow.Filter ??= SidekickPresetFilter.GetByID(dbManager, filterRow.PtrFilter);
filterRow.Preset ??= preset;
}
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
dbManager.GetCurrentDbConnection().Delete<SidekickPresetFilterRow>(ID);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c29bd46d22b54dee81faf768f30ec75e
timeCreated: 1747794537

View File

@@ -0,0 +1,116 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_species")]
public class SidekickSpecies
{
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("code")]
public string Code { get; set; }
/// <summary>
/// Gets a list of all the Species in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="excludeSpeciesWithNoParts">Whether to excludes species that have no active parts</param>
/// <returns>A list of all species in the database.</returns>
public static List<SidekickSpecies> GetAll(DatabaseManager dbManager, bool excludeSpeciesWithNoParts = true)
{
List<SidekickSpecies> allSpecies = dbManager.GetCurrentDbConnection().Table<SidekickSpecies>().ToList();
List<SidekickSpecies> filteredSpecies = allSpecies;
if (excludeSpeciesWithNoParts)
{
filteredSpecies = new List<SidekickSpecies>();
foreach (SidekickSpecies species in allSpecies)
{
List<SidekickPart> allParts = SidekickPart.GetAllForSpecies(dbManager, species);
if (allParts.Count > 0 || species.Name.Equals("Unrestricted", StringComparison.OrdinalIgnoreCase))
{
filteredSpecies.Add(species);
}
}
}
return filteredSpecies;
}
/// <summary>
/// Gets a specific Species by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Species.</param>
/// <returns>The specific Species if it exists; otherwise null.</returns>
public static SidekickSpecies GetByID(DatabaseManager dbManager, int id)
{
return dbManager.GetCurrentDbConnection().Get<SidekickSpecies>(id);
}
/// <summary>
/// Gets a specific Species by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="name">The name of the required Species.</param>
/// <returns>The specific Species if it exists; otherwise null.</returns>
public static SidekickSpecies GetByName(DatabaseManager dbManager, string name)
{
return dbManager.GetCurrentDbConnection().Table<SidekickSpecies>().FirstOrDefault(species => species.Name.ToLower() == name.ToLower());
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public int Save(DatabaseManager dbManager)
{
if (ID < 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
return ID;
}
/// <summary>
/// Deletes this item from the database
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Delete(DatabaseManager dbManager)
{
dbManager.GetCurrentDbConnection().Delete<SidekickSpecies>(ID);
}
/// <inheritdoc cref="Equals"/>
public override bool Equals(object obj)
{
SidekickSpecies species = (SidekickSpecies) obj;
if (ID > 0 && species?.ID > 0)
{
return ID == species?.ID;
}
return Name.Equals(species?.Name);
}
/// <inheritdoc cref="GetHashCode"/>
public override int GetHashCode()
{
return HashCode.Combine(ID, Name, Code);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ae1041b77d83b5948bfad9006e8f4635
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,115 @@
// Copyright (c) 2024 Synty Studios Limited. All rights reserved.
//
// Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA)
// available at: https://syntystore.com/pages/end-user-licence-agreement
//
// For additional details, see the LICENSE.MD file bundled with this software.
using SQLite;
using System.Collections.Generic;
namespace Synty.SidekickCharacters.Database.DTO
{
[Table("sk_species_image")]
public class SidekickSpeciesImage
{
private SidekickSpecies _species;
[PrimaryKey, AutoIncrement, Column("id")]
public int ID { get; set; }
[Column("ptr_species")]
public int PtrSpecies { get; set; }
[Column("img_data")]
public byte[] ImageData { get; set; }
[Column("img_width")]
public int Width { get; set; }
[Column("img_height")]
public int Height { get; set; }
[Ignore]
public SidekickSpecies Species
{
get => _species;
set
{
_species = value;
PtrSpecies = value.ID;
}
}
/// <summary>
/// Gets a specific Species Image by its database ID.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="id">The id of the required Species Image.</param>
/// <returns>The specific Species Image if it exists; otherwise null.</returns>
public static SidekickSpeciesImage GetByID(DatabaseManager dbManager, int id)
{
SidekickSpeciesImage speciesImage = dbManager.GetCurrentDbConnection().Find<SidekickSpeciesImage>(id);
Decorate(dbManager, speciesImage);
return speciesImage;
}
/// <summary>
/// Gets a list of all the Species Image in the database.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <returns>A list of all species images in the database.</returns>
public static List<SidekickSpeciesImage> GetAll(DatabaseManager dbManager)
{
List<SidekickSpeciesImage> speciesImages = dbManager.GetCurrentDbConnection().Table<SidekickSpeciesImage>().ToList();
foreach (SidekickSpeciesImage speciesImage in speciesImages)
{
Decorate(dbManager, speciesImage);
}
return speciesImages;
}
/// <summary>
/// Gets the Species Image in the database that has the matching Species.
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="species">The species to get the species image for.</param>
/// <returns>The species image in the database for the given species.</returns>
public static SidekickSpeciesImage GetBySpecies(DatabaseManager dbManager, SidekickSpecies species)
{
SidekickSpeciesImage partPresetImage = dbManager.GetCurrentDbConnection().Table<SidekickSpeciesImage>()
.FirstOrDefault(presetPart => presetPart.PtrSpecies == species.ID);
if (partPresetImage != null)
{
Decorate(dbManager, partPresetImage);
}
return partPresetImage;
}
/// <summary>
/// Ensures that the given preset has its nice DTO class properties set
/// </summary>
/// <param name="dbManager">The Database Manager to use.</param>
/// <param name="bodyShapePresetImage">The color preset to decorate</param>
/// <returns>A color set with all DTO class properties set</returns>
private static void Decorate(DatabaseManager dbManager, SidekickSpeciesImage bodyShapePresetImage)
{
bodyShapePresetImage.Species ??= SidekickSpecies.GetByID(dbManager, bodyShapePresetImage.PtrSpecies);
}
/// <summary>
/// Updates or Inserts this item in the Database.
/// </summary>
/// <param name="dbManager">The database manager to use.</param>
public void Save(DatabaseManager dbManager)
{
if (ID <= 0)
{
dbManager.GetCurrentDbConnection().Insert(this);
// in theory this could return a different ID, but in practice it's highly unlikely
ID = (int) SQLite3.LastInsertRowid(dbManager.GetCurrentDbConnection().Handle);
}
dbManager.GetCurrentDbConnection().Update(this);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5c33e8e2dcf84666a0261253f096d61c
timeCreated: 1730347087