mirror of
https://gitgud.io/ll.mirrors/sizedapparel.git
synced 2024-08-15 00:43:40 +00:00
Mirror of 1.4.7 from Lovers Lab
This commit is contained in:
parent
161133e4e1
commit
9a3d9f4185
607 changed files with 11263 additions and 1309 deletions
372
1.3/source/SizedApparel/SizedApparelsDatabase.cs
Normal file
372
1.3/source/SizedApparel/SizedApparelsDatabase.cs
Normal file
|
@ -0,0 +1,372 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using rjw;
|
||||
|
||||
namespace SizedApparel
|
||||
{
|
||||
|
||||
public static class SizedApparelsDatabase
|
||||
{
|
||||
|
||||
public struct BodyGraphicKey
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public struct SizedApparelDatabaseKey
|
||||
{
|
||||
public string pathWithoutSizeIndex; // Do Not Include Size Data to path! bodytype could be included
|
||||
public string raceName;
|
||||
public string bodyTypeName;
|
||||
public Gender gender;
|
||||
public string hediffName;
|
||||
public int targetSize;
|
||||
public bool isHorny;
|
||||
public string customPose;
|
||||
public string variation;
|
||||
|
||||
|
||||
public SizedApparelDatabaseKey(string path, string race, string bodyType = null, Gender genderInput = Gender.None , string hediff = null, int size = -1, bool horny = false, string customPose = null, string variation = null)
|
||||
{
|
||||
this.pathWithoutSizeIndex = path;
|
||||
this.raceName = race;
|
||||
this.bodyTypeName = bodyType;
|
||||
this.gender = genderInput;
|
||||
this.hediffName = hediff;
|
||||
this.targetSize = size;
|
||||
this.isHorny = horny;
|
||||
this.customPose = customPose;
|
||||
this.variation = variation;
|
||||
}
|
||||
}
|
||||
public struct SizedApparelDatabaseKeyComparer : IEqualityComparer<SizedApparelDatabaseKey>
|
||||
{
|
||||
public bool Equals(SizedApparelDatabaseKey x, SizedApparelDatabaseKey y)
|
||||
{
|
||||
if (x.targetSize != y.targetSize)
|
||||
return false;
|
||||
return true && (x.pathWithoutSizeIndex == y.pathWithoutSizeIndex) && (x.bodyTypeName == y.bodyTypeName) && (x.raceName == y.raceName)&& (x.gender == y.gender) && (x.hediffName == y.hediffName) && (x.isHorny == y.isHorny) && (x.customPose == y.customPose) && (x.variation == y.variation);
|
||||
}
|
||||
|
||||
public int GetHashCode(SizedApparelDatabaseKey obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
public struct BodyPartDatabaseKey
|
||||
{
|
||||
public string raceName;
|
||||
public string bodyTypeName;
|
||||
public string hediffName;
|
||||
public string folderPath;
|
||||
public Gender gender;
|
||||
public int targetSize;
|
||||
public bool isHorny;
|
||||
public string customPose; // null custom pose as default pose
|
||||
public string variation; // null variation as default graphic
|
||||
|
||||
public BodyPartDatabaseKey(string race, string bodyType = null, string hediff = null, string path = null, Gender pawnGender = Gender.None, int size = -1, bool horny = false, string customPose = null, string variation = null)
|
||||
{
|
||||
this.raceName = race;
|
||||
this.bodyTypeName = bodyType;
|
||||
this.hediffName = hediff;
|
||||
this.folderPath = path;
|
||||
this.gender = pawnGender;
|
||||
this.targetSize = size;
|
||||
this.isHorny = horny;
|
||||
this.customPose = customPose;
|
||||
this.variation = variation;
|
||||
}
|
||||
}
|
||||
public struct BodyPartDatabaseKeyComparer : IEqualityComparer<BodyPartDatabaseKey>
|
||||
{
|
||||
public bool Equals(BodyPartDatabaseKey x, BodyPartDatabaseKey y)
|
||||
{
|
||||
if (x.targetSize != y.targetSize)
|
||||
return false;
|
||||
return true && (x.raceName == y.raceName) && (x.bodyTypeName == y.bodyTypeName) && (x.hediffName == y.hediffName) && ( x.folderPath == y.folderPath)&& (x.gender == y.gender) && (x.isHorny == y.isHorny) && (x.customPose == y.customPose) && (x.variation == y.variation);
|
||||
}
|
||||
|
||||
public int GetHashCode(BodyPartDatabaseKey obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
public struct PathAndSize
|
||||
{
|
||||
public string pathWithSizeIndex;
|
||||
public int size;
|
||||
public bool isUnsupportedHumanlikePath;
|
||||
public bool isCustomPose;
|
||||
public string hediffName;
|
||||
public Dictionary<string, BodyPartPoint> points;
|
||||
|
||||
public PathAndSize(string path, int index, bool unsupportedHumanlike = false, bool customPose = false, string hediff = null ,Dictionary<string, BodyPartPoint> pointsInput = null)
|
||||
{
|
||||
this.pathWithSizeIndex = path;
|
||||
this.size = index;
|
||||
this.isUnsupportedHumanlikePath = unsupportedHumanlike;
|
||||
this.isCustomPose = customPose;
|
||||
this.hediffName = hediff;
|
||||
this.points = pointsInput;
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<BodyGraphicKey, Graphic> SizedApparelBodyGraphic = new Dictionary<BodyGraphicKey, Graphic>(); // TODO
|
||||
private static Dictionary<SizedApparelDatabaseKey, PathAndSize> SupportedApparelResultPath = new Dictionary<SizedApparelDatabaseKey, PathAndSize>(new SizedApparelDatabaseKeyComparer());
|
||||
private static Dictionary<BodyPartDatabaseKey, PathAndSize> SupportedBodyPartResultPath = new Dictionary<BodyPartDatabaseKey, PathAndSize>(new BodyPartDatabaseKeyComparer());
|
||||
private static Dictionary<string, string> SupportedApparelOriginalPath = new Dictionary<string, string>();
|
||||
|
||||
//AlienRace AllowHumanlike. Need to Restart or Clear cache to change options
|
||||
|
||||
|
||||
|
||||
public static Dictionary<string, bool> AlienRaceUseHumanlike = new Dictionary<string, bool>();
|
||||
private static void ResetAlienRaceUseHumanlike()
|
||||
{
|
||||
AlienRaceUseHumanlike.Clear();
|
||||
IEnumerable<ThingDef> HumanlikeRaces;
|
||||
HumanlikeRaces = DefDatabase<ThingDef>.AllDefs.Where(b =>b.race?.Humanlike == true);
|
||||
|
||||
foreach (ThingDef raceDef in HumanlikeRaces)
|
||||
{
|
||||
//Default Value Is True
|
||||
AlienRaceUseHumanlike.Add(raceDef.defName, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GetAlienRaceUseHumanlike(string raceDef)
|
||||
{
|
||||
if (AlienRaceUseHumanlike.NullOrEmpty())
|
||||
{
|
||||
ResetAlienRaceUseHumanlike();
|
||||
}
|
||||
if (AlienRaceUseHumanlike.ContainsKey(raceDef))
|
||||
return AlienRaceUseHumanlike[raceDef];
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<string> GetAlienRacesDefNames()
|
||||
{
|
||||
if (AlienRaceUseHumanlike.NullOrEmpty())
|
||||
{
|
||||
ResetAlienRaceUseHumanlike();
|
||||
}
|
||||
//It must have one or more elements: human.
|
||||
return AlienRaceUseHumanlike.Keys.ToList();
|
||||
}
|
||||
|
||||
|
||||
public static void ClearAll()
|
||||
{
|
||||
SupportedApparelResultPath.Clear();
|
||||
SupportedBodyPartResultPath.Clear();
|
||||
SupportedApparelOriginalPath.Clear();
|
||||
AlienRaceUseHumanlike.Clear();
|
||||
}
|
||||
|
||||
//Apparels, Bodyparts can be used
|
||||
public static PathAndSize GetSupportedApparelSizedPath(SizedApparelDatabaseKey key)
|
||||
{
|
||||
int currentSize = -1;
|
||||
float currentSeverity = -1;
|
||||
return GetSupportedApparelSizedPath(key, out currentSize, out currentSeverity);
|
||||
|
||||
}
|
||||
|
||||
public static string GetSupportedApparelOriginalPath(string path)
|
||||
{
|
||||
string outString;
|
||||
if (SupportedApparelOriginalPath.TryGetValue(path, out outString))
|
||||
return outString;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Dictionary<string, BodyPartPoint> GetGraphicPoints(string textuerPath)
|
||||
{
|
||||
//DefDatabase<>
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PathAndSize GetSupportedApparelSizedPath(SizedApparelDatabaseKey key, out int indexOut, out float currentSeverityOut)
|
||||
{
|
||||
if (SupportedApparelResultPath.ContainsKey(key))
|
||||
{
|
||||
if (SizedApparelSettings.Debug)
|
||||
Log.Message("[Sized Apparel] SizedApparelDataBase::ValidKey: "+ key.pathWithoutSizeIndex);
|
||||
var value = SupportedApparelResultPath.TryGetValue(key);
|
||||
indexOut = value.size;
|
||||
currentSeverityOut = SizedApparelUtility.BreastSizeIndexToSeverity(value.size);
|
||||
if (SizedApparelSettings.Debug)
|
||||
Log.Message("[Sized Apparel] SizedApparelDataBase::Result Path: " + value.pathWithSizeIndex);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
if (SizedApparelSettings.Debug)
|
||||
Log.Message(" [Sized Apparel] SizedApparelDataBase::Key Not Found: " + key.pathWithoutSizeIndex);
|
||||
|
||||
PathAndSize result;
|
||||
Graphic sourceGraphic = GraphicDatabase.Get<Graphic_Multi>(key.pathWithoutSizeIndex);
|
||||
bool flag;
|
||||
bool customPose = true; //default none pose also custom pose
|
||||
string hediffResult;
|
||||
string targetRaceName;
|
||||
//if (GetAlienRaceUseHumanlike(key.raceName))
|
||||
//TODO. AlienRaceHumanlike
|
||||
/*
|
||||
var pawnDef = DefDatabase<SizedApparelPawnDef>.GetNamed(key.raceName);
|
||||
if (pawnDef != null)
|
||||
{
|
||||
if(pawnDef.isHumanlike)
|
||||
targetRaceName = "Humanlike";
|
||||
}
|
||||
|
||||
else
|
||||
targetRaceName = key.raceName;*/
|
||||
targetRaceName = key.raceName;
|
||||
Graphic graphic = null;
|
||||
graphic = SizedApparelUtility.GetSizedApparelGraphic(sourceGraphic, SizedApparelUtility.BreastSizeIndexToSeverity(key.targetSize), out indexOut, out currentSeverityOut, out flag, out hediffResult, targetRaceName, key.hediffName, key.customPose, key.gender);//key.customPose
|
||||
if(graphic == null && key.gender != Gender.None)
|
||||
{
|
||||
//try Genderless
|
||||
graphic = SizedApparelUtility.GetSizedApparelGraphic(sourceGraphic, SizedApparelUtility.BreastSizeIndexToSeverity(key.targetSize), out indexOut, out currentSeverityOut, out flag, out hediffResult, targetRaceName, key.hediffName, key.customPose, Gender.None);//key.customPose
|
||||
}
|
||||
|
||||
if (key.customPose != null && graphic == null)
|
||||
{
|
||||
customPose = false;
|
||||
graphic = SizedApparelUtility.GetSizedApparelGraphic(sourceGraphic, SizedApparelUtility.BreastSizeIndexToSeverity(key.targetSize), out indexOut, out currentSeverityOut, out flag, out hediffResult , targetRaceName, key.hediffName , null ,key.gender);
|
||||
if (graphic == null && key.gender != Gender.None)
|
||||
{
|
||||
//try Genderless
|
||||
graphic = SizedApparelUtility.GetSizedApparelGraphic(sourceGraphic, SizedApparelUtility.BreastSizeIndexToSeverity(key.targetSize), out indexOut, out currentSeverityOut, out flag, out hediffResult, targetRaceName, key.hediffName, null, Gender.None);//key.customPose
|
||||
}
|
||||
}
|
||||
|
||||
//Try Find Different Target Size
|
||||
if (flag == true)
|
||||
{
|
||||
result = new PathAndSize(graphic.path, indexOut, false, customPose, hediffResult);
|
||||
SupportedApparelResultPath.SetOrAdd(key, result);
|
||||
SupportedApparelOriginalPath.SetOrAdd(result.pathWithSizeIndex, key.pathWithoutSizeIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new PathAndSize(null, -1);
|
||||
SupportedApparelResultPath.SetOrAdd(key, result);
|
||||
SupportedApparelOriginalPath.SetOrAdd(key.pathWithoutSizeIndex, key.pathWithoutSizeIndex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static PathAndSize GetSupportedBodyPartPath(BodyPartDatabaseKey key, bool isBreast, string folderName, string defaultHediffName)
|
||||
{
|
||||
PathAndSize result;
|
||||
if (SupportedBodyPartResultPath.ContainsKey(key))
|
||||
return SupportedBodyPartResultPath.TryGetValue(key);
|
||||
int currentSize = -1;
|
||||
string hediffResult;
|
||||
Graphic graphic = null;
|
||||
if (key.customPose != null)
|
||||
{
|
||||
graphic = SizedApparelUtility.GetBodyPartGraphic(key.raceName, key.bodyTypeName, key.hediffName, isBreast, key.targetSize, folderName+"/CustomPose/"+key.customPose, defaultHediffName, out currentSize, out hediffResult, key.isHorny, null, key.variation, key.gender);
|
||||
if (graphic != null)
|
||||
{
|
||||
result = new PathAndSize(graphic.path, currentSize, false, true, hediffResult);
|
||||
SupportedBodyPartResultPath.SetOrAdd(key, result);
|
||||
return result;
|
||||
}
|
||||
if (key.bodyTypeName != null)
|
||||
graphic = SizedApparelUtility.GetBodyPartGraphic(key.raceName, null, key.hediffName, isBreast, key.targetSize, folderName + "/CustomPose/" + key.customPose, defaultHediffName, out currentSize, out hediffResult, key.isHorny, null, key.variation, key.gender);
|
||||
if (graphic != null)
|
||||
{
|
||||
result = new PathAndSize(graphic.path, currentSize, false, true, hediffResult);
|
||||
SupportedBodyPartResultPath.SetOrAdd(key, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
graphic = SizedApparelUtility.GetBodyPartGraphic(key.raceName, key.bodyTypeName, key.hediffName, isBreast, key.targetSize, folderName, defaultHediffName, out currentSize, out hediffResult, key.isHorny, null, key.variation, key.gender);
|
||||
if (graphic != null)
|
||||
{
|
||||
result = new PathAndSize(graphic.path, currentSize, false, key.customPose == null ? true : false, hediffResult);
|
||||
SupportedBodyPartResultPath.SetOrAdd(key, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (key.bodyTypeName != null)
|
||||
graphic = SizedApparelUtility.GetBodyPartGraphic(key.raceName, null, key.hediffName, isBreast, key.targetSize, folderName, defaultHediffName, out currentSize, out hediffResult, key.isHorny, null, key.variation, key.gender);
|
||||
if (graphic != null)
|
||||
{
|
||||
result = new PathAndSize(graphic.path, currentSize, false, key.customPose == null ? true : false, hediffResult);
|
||||
SupportedBodyPartResultPath.SetOrAdd(key, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//SizedApparelMod.CheckAndLoadAlienRaces();
|
||||
//HumanLike Search
|
||||
var raceSetting = SizedApparelSettings.alienRaceSettings.FirstOrDefault((AlienRaceSetting s) => s.raceName == key.raceName);
|
||||
if (raceSetting !=null && !raceSetting.asHumanlike) //old: !SizedApparelSettings.UnsupportedRaceToUseHumanlike
|
||||
{
|
||||
//Cannot find Any result
|
||||
result = new PathAndSize(null, -1);
|
||||
SupportedBodyPartResultPath.SetOrAdd(key, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (key.customPose != null)
|
||||
{
|
||||
graphic = SizedApparelUtility.GetBodyPartGraphic(key.raceName, key.bodyTypeName, key.hediffName, isBreast, key.targetSize, folderName + "/CustomPose/" + key.customPose, defaultHediffName, out currentSize, out hediffResult, key.isHorny, "Humanlike", key.variation, key.gender);
|
||||
if (graphic != null)
|
||||
{
|
||||
result = new PathAndSize(graphic.path, currentSize, true, true, hediffResult);
|
||||
SupportedBodyPartResultPath.SetOrAdd(key, result);
|
||||
return result;
|
||||
}
|
||||
if (key.bodyTypeName != null)
|
||||
graphic = SizedApparelUtility.GetBodyPartGraphic(key.raceName, null, key.hediffName, isBreast, key.targetSize, folderName + "/CustomPose/" + key.customPose, defaultHediffName, out currentSize, out hediffResult, key.isHorny, "Humanlike", key.variation, key.gender);
|
||||
if (graphic != null)
|
||||
{
|
||||
result = new PathAndSize(graphic.path, currentSize, true, true, hediffResult);
|
||||
SupportedBodyPartResultPath.SetOrAdd(key, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
graphic = SizedApparelUtility.GetBodyPartGraphic(key.raceName, key.bodyTypeName, key.hediffName, isBreast, key.targetSize, folderName, defaultHediffName, out currentSize, out hediffResult, key.isHorny, "Humanlike", key.variation, key.gender);
|
||||
if (graphic != null)
|
||||
{
|
||||
result = new PathAndSize(graphic.path, currentSize, true, key.customPose == null ? true : false, hediffResult);
|
||||
SupportedBodyPartResultPath.SetOrAdd(key, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (key.bodyTypeName != null)
|
||||
graphic = SizedApparelUtility.GetBodyPartGraphic(key.raceName, null, key.hediffName, isBreast, key.targetSize, folderName, defaultHediffName, out currentSize, out hediffResult, key.isHorny, "Humanlike", key.variation, key.gender);
|
||||
if (graphic != null)
|
||||
{
|
||||
result = new PathAndSize(graphic.path, currentSize, true, key.customPose == null ? true : false, hediffResult);
|
||||
SupportedBodyPartResultPath.SetOrAdd(key, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Cannot find Any result
|
||||
result = new PathAndSize(null, -1);
|
||||
SupportedBodyPartResultPath.SetOrAdd(key, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue