chore: 외부 에셋 권한 및 줄바꿈 재기록 반영
- Assets/External 하위 샘플 및 서드파티 에셋 파일의 실행 비트 변경을 별도 커밋으로 분리 - PolygonGeneric, SidekickCharacters, Synty 도구 자산 전반의 줄바꿈 및 재직렬화 차이를 그대로 보존 - 프로젝트 고유 로직 변경과 분리해 이후 히스토리에서 외부 에셋 노이즈 범위를 식별하기 쉽게 정리
This commit is contained in:
694
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickColorRow.cs
vendored
Normal file → Executable file
694
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickColorRow.cs
vendored
Normal file → Executable file
@@ -1,347 +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}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickColorRow.cs.meta
vendored
Normal file → Executable file
0
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickColorRow.cs.meta
vendored
Normal file → Executable file
12
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickColorSet.cs
vendored
Normal file → Executable file
12
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickColorSet.cs
vendored
Normal file → Executable file
@@ -154,18 +154,6 @@ namespace Synty.SidekickCharacters.Database.DTO
|
||||
/// <returns>A color set with all DTO class properties set</returns>
|
||||
private static void Decorate(DatabaseManager dbManager, SidekickColorSet set)
|
||||
{
|
||||
if (set == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
set.SourceColorPath = DatabaseManager.NormalizeLegacyAssetPath(set.SourceColorPath);
|
||||
set.SourceMetallicPath = DatabaseManager.NormalizeLegacyAssetPath(set.SourceMetallicPath);
|
||||
set.SourceSmoothnessPath = DatabaseManager.NormalizeLegacyAssetPath(set.SourceSmoothnessPath);
|
||||
set.SourceReflectionPath = DatabaseManager.NormalizeLegacyAssetPath(set.SourceReflectionPath);
|
||||
set.SourceEmissionPath = DatabaseManager.NormalizeLegacyAssetPath(set.SourceEmissionPath);
|
||||
set.SourceOpacityPath = DatabaseManager.NormalizeLegacyAssetPath(set.SourceOpacityPath);
|
||||
|
||||
if (set.Species == null && set.PtrSpecies >= 0)
|
||||
{
|
||||
set.Species = SidekickSpecies.GetByID(dbManager, set.PtrSpecies);
|
||||
|
||||
0
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickColorSet.cs.meta
vendored
Normal file → Executable file
0
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickColorSet.cs.meta
vendored
Normal file → Executable file
2
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickPart.cs
vendored
Normal file → Executable file
2
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickPart.cs
vendored
Normal file → Executable file
@@ -222,8 +222,6 @@ namespace Synty.SidekickCharacters.Database.DTO
|
||||
{
|
||||
if (part != null)
|
||||
{
|
||||
part.Location = DatabaseManager.NormalizeLegacyAssetPath(part.Location);
|
||||
|
||||
if (part.Species == null && part.PtrSpecies >= 0)
|
||||
{
|
||||
part.Species = SidekickSpecies.GetByID(dbManager, part.PtrSpecies);
|
||||
|
||||
0
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickPart.cs.meta
vendored
Normal file → Executable file
0
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickPart.cs.meta
vendored
Normal file → Executable file
570
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickPartPreset.cs
vendored
Normal file → Executable file
570
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickPartPreset.cs
vendored
Normal file → Executable file
@@ -1,285 +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);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickPartPreset.cs.meta
vendored
Normal file → Executable file
0
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DTO/SidekickPartPreset.cs.meta
vendored
Normal file → Executable file
242
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DatabaseManager.cs
vendored
Normal file → Executable file
242
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DatabaseManager.cs
vendored
Normal file → Executable file
@@ -12,9 +12,7 @@
|
||||
using SQLite;
|
||||
using Synty.SidekickCharacters.Database.DTO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Synty.SidekickCharacters.Database
|
||||
{
|
||||
@@ -23,18 +21,11 @@ namespace Synty.SidekickCharacters.Database
|
||||
/// </summary>
|
||||
public class DatabaseManager
|
||||
{
|
||||
private const string _DATABASE_FILE_NAME = "Side_Kick_Data.db";
|
||||
private const string _LEGACY_PACKAGE_ROOT = "Assets/Synty/SidekickCharacters";
|
||||
private const string _LEGACY_TOOLS_PACKAGE_ROOT = "Assets/Synty/Tools/SidekickCharacters";
|
||||
private const string _WORKING_DATABASE_DIRECTORY = "SidekickCharacters";
|
||||
private static readonly string _DATABASE_PATH = "Assets/External/Models/SidekickCharacters/Database/Side_Kick_Data.db";
|
||||
private readonly string _CURRENT_VERSION = "1.0.2";
|
||||
|
||||
private static SQLiteConnection _connection;
|
||||
private static int _connectionHash;
|
||||
private static string _databasePath;
|
||||
private static string _seedDatabasePath;
|
||||
private static string _packageRootAbsolutePath;
|
||||
private static string _packageRootAssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DB connection with the given connection details.
|
||||
@@ -48,13 +39,7 @@ namespace Synty.SidekickCharacters.Database
|
||||
{
|
||||
if (_connection == null)
|
||||
{
|
||||
string databasePath = GetDatabasePath();
|
||||
if (string.IsNullOrEmpty(databasePath))
|
||||
{
|
||||
throw new FileNotFoundException("Unable to locate Sidekick database file in this Unity project.");
|
||||
}
|
||||
|
||||
_connection = new SQLiteConnection(databasePath, true);
|
||||
_connection = new SQLiteConnection(_DATABASE_PATH, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -115,12 +100,12 @@ namespace Synty.SidekickCharacters.Database
|
||||
{
|
||||
Species = new SidekickSpecies { ID = -1, Name = "None" },
|
||||
Name = "Default",
|
||||
SourceColorPath = GetPackageAssetPath("Resources", "Textures", "T_ColorMap.png"),
|
||||
SourceMetallicPath = GetPackageAssetPath("Resources", "Textures", "T_MetallicMap.png"),
|
||||
SourceSmoothnessPath = GetPackageAssetPath("Resources", "Textures", "T_SmoothnessMap.png"),
|
||||
SourceReflectionPath = GetPackageAssetPath("Resources", "Textures", "T_ReflectionMap.png"),
|
||||
SourceEmissionPath = GetPackageAssetPath("Resources", "Textures", "T_EmissionMap.png"),
|
||||
SourceOpacityPath = GetPackageAssetPath("Resources", "Textures", "T_OpacityMap.png"),
|
||||
SourceColorPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_ColorMap.png",
|
||||
SourceMetallicPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_MetallicMap.png",
|
||||
SourceSmoothnessPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_SmoothnessMap.png",
|
||||
SourceReflectionPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_ReflectionMap.png",
|
||||
SourceEmissionPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_EmissionMap.png",
|
||||
SourceOpacityPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_OpacityMap.png",
|
||||
};
|
||||
|
||||
newSet.Save(this);
|
||||
@@ -221,216 +206,5 @@ namespace Synty.SidekickCharacters.Database
|
||||
{
|
||||
return new Version(GetCurrentDbConnection()?.Table<SidekickDBVersion>().FirstOrDefault().SemanticVersion ?? "0.0.1ea");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the absolute filesystem path to the Sidekick database file.
|
||||
/// </summary>
|
||||
/// <returns>The absolute path to the DB file, if found.</returns>
|
||||
public static string GetDatabasePath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_databasePath) && File.Exists(_databasePath))
|
||||
{
|
||||
return _databasePath;
|
||||
}
|
||||
|
||||
string seedDatabasePath = GetSeedDatabasePath();
|
||||
if (string.IsNullOrEmpty(seedDatabasePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string projectRoot = Directory.GetParent(Application.dataPath)?.FullName;
|
||||
if (string.IsNullOrEmpty(projectRoot))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string workingDirectory = Path.Combine(projectRoot, "Library", _WORKING_DATABASE_DIRECTORY);
|
||||
Directory.CreateDirectory(workingDirectory);
|
||||
|
||||
_databasePath = Path.Combine(workingDirectory, _DATABASE_FILE_NAME);
|
||||
if (!File.Exists(_databasePath))
|
||||
{
|
||||
File.Copy(seedDatabasePath, _databasePath, false);
|
||||
}
|
||||
|
||||
_databasePath = Path.GetFullPath(_databasePath);
|
||||
CleanupLegacyDatabaseArtifacts(seedDatabasePath);
|
||||
return _databasePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the absolute filesystem path to the Sidekick package root.
|
||||
/// </summary>
|
||||
/// <returns>The absolute path to the package root, if found.</returns>
|
||||
public static string GetPackageRootAbsolutePath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_packageRootAbsolutePath) && Directory.Exists(_packageRootAbsolutePath))
|
||||
{
|
||||
return _packageRootAbsolutePath;
|
||||
}
|
||||
|
||||
string seedDatabasePath = GetSeedDatabasePath();
|
||||
if (string.IsNullOrEmpty(seedDatabasePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string databaseDirectory = Path.GetDirectoryName(seedDatabasePath);
|
||||
if (string.IsNullOrEmpty(databaseDirectory))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_packageRootAbsolutePath = Path.GetDirectoryName(databaseDirectory);
|
||||
if (!string.IsNullOrEmpty(_packageRootAbsolutePath))
|
||||
{
|
||||
_packageRootAbsolutePath = Path.GetFullPath(_packageRootAbsolutePath);
|
||||
}
|
||||
|
||||
return _packageRootAbsolutePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the project-relative asset path to the Sidekick package root.
|
||||
/// </summary>
|
||||
/// <returns>The asset path to the package root, if found.</returns>
|
||||
public static string GetPackageRootAssetPath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_packageRootAssetPath))
|
||||
{
|
||||
return _packageRootAssetPath;
|
||||
}
|
||||
|
||||
string packageRootAbsolutePath = GetPackageRootAbsolutePath();
|
||||
if (string.IsNullOrEmpty(packageRootAbsolutePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_packageRootAssetPath = ToAssetPath(packageRootAbsolutePath);
|
||||
return _packageRootAssetPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a project-relative asset path under the Sidekick package root.
|
||||
/// </summary>
|
||||
/// <param name="relativeSegments">Path segments under the package root.</param>
|
||||
/// <returns>The combined asset path, if the package root could be found.</returns>
|
||||
public static string GetPackageAssetPath(params string[] relativeSegments)
|
||||
{
|
||||
string packageRootAssetPath = GetPackageRootAssetPath();
|
||||
if (string.IsNullOrEmpty(packageRootAssetPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string combinedPath = packageRootAssetPath;
|
||||
foreach (string segment in relativeSegments)
|
||||
{
|
||||
combinedPath = Path.Combine(combinedPath, segment);
|
||||
}
|
||||
|
||||
return NormalizePathSeparators(combinedPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalizes legacy Sidekick asset paths so moved packages still load correctly.
|
||||
/// </summary>
|
||||
/// <param name="assetPath">The asset path to normalize.</param>
|
||||
/// <returns>The remapped path if it pointed at an old root; otherwise the original path.</returns>
|
||||
public static string NormalizeLegacyAssetPath(string assetPath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(assetPath))
|
||||
{
|
||||
return assetPath;
|
||||
}
|
||||
|
||||
string normalizedPath = NormalizePathSeparators(assetPath);
|
||||
string packageRootAssetPath = GetPackageRootAssetPath();
|
||||
if (string.IsNullOrEmpty(packageRootAssetPath))
|
||||
{
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
if (normalizedPath.StartsWith(_LEGACY_TOOLS_PACKAGE_ROOT, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return packageRootAssetPath + normalizedPath.Substring(_LEGACY_TOOLS_PACKAGE_ROOT.Length);
|
||||
}
|
||||
|
||||
if (normalizedPath.StartsWith(_LEGACY_PACKAGE_ROOT, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return packageRootAssetPath + normalizedPath.Substring(_LEGACY_PACKAGE_ROOT.Length);
|
||||
}
|
||||
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
private static string ToAssetPath(string fullPath)
|
||||
{
|
||||
string normalizedFullPath = NormalizePathSeparators(Path.GetFullPath(fullPath));
|
||||
string normalizedAssetsPath = NormalizePathSeparators(Path.GetFullPath(Application.dataPath));
|
||||
|
||||
if (!normalizedFullPath.StartsWith(normalizedAssetsPath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return normalizedFullPath;
|
||||
}
|
||||
|
||||
return "Assets" + normalizedFullPath.Substring(normalizedAssetsPath.Length);
|
||||
}
|
||||
|
||||
private static string NormalizePathSeparators(string path)
|
||||
{
|
||||
return path?.Replace('\\', '/');
|
||||
}
|
||||
|
||||
private static string GetSeedDatabasePath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_seedDatabasePath) && File.Exists(_seedDatabasePath))
|
||||
{
|
||||
return _seedDatabasePath;
|
||||
}
|
||||
|
||||
string[] databaseFiles = Directory.GetFiles(Application.dataPath, _DATABASE_FILE_NAME, SearchOption.AllDirectories);
|
||||
_seedDatabasePath = databaseFiles
|
||||
.OrderBy(path => path.Contains($"{Path.DirectorySeparatorChar}SidekickCharacters{Path.DirectorySeparatorChar}Database{Path.DirectorySeparatorChar}") ? 0 : 1)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (!string.IsNullOrEmpty(_seedDatabasePath))
|
||||
{
|
||||
_seedDatabasePath = Path.GetFullPath(_seedDatabasePath);
|
||||
}
|
||||
|
||||
return _seedDatabasePath;
|
||||
}
|
||||
|
||||
private static void CleanupLegacyDatabaseArtifacts(string seedDatabasePath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(seedDatabasePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DeleteIfExists(seedDatabasePath + "-journal");
|
||||
DeleteIfExists(seedDatabasePath + "-journal.meta");
|
||||
DeleteIfExists(seedDatabasePath + "-wal");
|
||||
DeleteIfExists(seedDatabasePath + "-wal.meta");
|
||||
DeleteIfExists(seedDatabasePath + "-shm");
|
||||
DeleteIfExists(seedDatabasePath + "-shm.meta");
|
||||
}
|
||||
|
||||
private static void DeleteIfExists(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DatabaseManager.cs.meta
vendored
Normal file → Executable file
0
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DatabaseManager.cs.meta
vendored
Normal file → Executable file
Reference in New Issue
Block a user