mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Race customization and data saving
This commit is contained in:
parent
2f3f807911
commit
d3b676df06
456 changed files with 6388 additions and 419 deletions
|
@ -17,7 +17,7 @@ namespace RimWorldAnimationStudio
|
|||
[XmlArray("tags"), XmlArrayItem("li")] public List<string> tags;
|
||||
|
||||
[XmlIgnore] public ActorGender gender;
|
||||
[XmlIgnore] public string raceDef;
|
||||
[XmlIgnore] private AlienRaceDef alienRaceDef;
|
||||
|
||||
public BodyTypeOffset bodyTypeOffset = new BodyTypeOffset();
|
||||
public bool initiator = false;
|
||||
|
@ -37,9 +37,24 @@ namespace RimWorldAnimationStudio
|
|||
public bool ShouldSerializeisFucking() { return isFucking; }
|
||||
public bool ShouldSerializeisFucked() { return isFucked; }
|
||||
|
||||
public AlienRaceDef GetAlienRaceDef()
|
||||
{
|
||||
if (alienRaceDef == null)
|
||||
{ alienRaceDef = AlienRaceDefs.GetNamed("Human"); }
|
||||
|
||||
return alienRaceDef;
|
||||
}
|
||||
|
||||
public void SetAlienRaceDef(string alienRaceDefName)
|
||||
{
|
||||
AlienRaceDef alienRaceDef = AlienRaceDefs.GetNamed(alienRaceDefName);
|
||||
|
||||
if (alienRaceDef != null)
|
||||
{ this.alienRaceDef = alienRaceDef; }
|
||||
}
|
||||
|
||||
public void ValidateData()
|
||||
{
|
||||
defNames = defNames.Intersect(Tags.defNames.Concat(CustomTags.defNames))?.ToList();
|
||||
bodyDefTypes = bodyDefTypes.Intersect(Tags.bodyDefTypes.Concat(CustomTags.bodyDefTypes))?.ToList();
|
||||
requiredGenitals = requiredGenitals.Intersect(Tags.bodyParts.Concat(CustomTags.bodyParts))?.ToList();
|
||||
}
|
||||
|
|
210
Assets/Scripts/AnimationComponents/AlienRaceDef.cs
Normal file
210
Assets/Scripts/AnimationComponents/AlienRaceDef.cs
Normal file
|
@ -0,0 +1,210 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class AlienRaceDef
|
||||
{
|
||||
public string defName;
|
||||
public bool isHumanoid = true;
|
||||
public float scale = 1f;
|
||||
|
||||
public List<MultiDirectionalGraphic> bodyTypeGraphics = new List<MultiDirectionalGraphic>();
|
||||
public MultiDirectionalGraphic headGraphics = new MultiDirectionalGraphic();
|
||||
|
||||
public AlienRaceDef()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public AlienRaceDef(string defName)
|
||||
{
|
||||
this.defName = defName;
|
||||
}
|
||||
|
||||
public Sprite GetHeadGraphic(CardinalDirection facing)
|
||||
{
|
||||
if (HasValidHeadGraphicPath(facing) == false)
|
||||
{ return null; }
|
||||
|
||||
switch (facing)
|
||||
{
|
||||
case CardinalDirection.North: return headGraphics.northGraphic.sprite;
|
||||
case CardinalDirection.East: return headGraphics.eastGraphic.sprite;
|
||||
case CardinalDirection.South: return headGraphics.southGraphic.sprite;
|
||||
default: return headGraphics.eastGraphic.sprite;
|
||||
}
|
||||
}
|
||||
|
||||
public Sprite GetBodyTypeGraphic(CardinalDirection facing, string bodyType = "None")
|
||||
{
|
||||
if (HasValidBodyTypeGraphicPath(facing, bodyType) == false)
|
||||
{ return null; }
|
||||
|
||||
MultiDirectionalGraphic bodyTypeGraphic = bodyTypeGraphics.FirstOrDefault(x => x.bodyType == bodyType);
|
||||
|
||||
if (bodyTypeGraphic == null)
|
||||
{
|
||||
bodyTypeGraphic = new MultiDirectionalGraphic(bodyType);
|
||||
bodyTypeGraphics.Add(bodyTypeGraphic);
|
||||
}
|
||||
|
||||
switch (facing)
|
||||
{
|
||||
case CardinalDirection.North: return bodyTypeGraphic.northGraphic.sprite;
|
||||
case CardinalDirection.East: return bodyTypeGraphic.eastGraphic.sprite;
|
||||
case CardinalDirection.South: return bodyTypeGraphic.southGraphic.sprite;
|
||||
default: return bodyTypeGraphic.eastGraphic.sprite;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetHeadGraphicPath(CardinalDirection facing)
|
||||
{
|
||||
if (HasValidHeadGraphicPath(facing) == false)
|
||||
{ return "Invalid file path"; }
|
||||
|
||||
switch (facing)
|
||||
{
|
||||
case CardinalDirection.North: return headGraphics.northGraphic.path;
|
||||
case CardinalDirection.East: return headGraphics.eastGraphic.path;
|
||||
case CardinalDirection.South: return headGraphics.southGraphic.path;
|
||||
default: return headGraphics.eastGraphic.path;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetBodyTypeGraphicPath(CardinalDirection facing, string bodyType = "None")
|
||||
{
|
||||
if (HasValidBodyTypeGraphicPath(facing, bodyType) == false)
|
||||
{ return "Invalid file path"; }
|
||||
|
||||
MultiDirectionalGraphic bodyTypeGraphic = bodyTypeGraphics.FirstOrDefault(x => x.bodyType == bodyType);
|
||||
|
||||
if (bodyTypeGraphic == null)
|
||||
{
|
||||
bodyTypeGraphic = new MultiDirectionalGraphic(bodyType);
|
||||
bodyTypeGraphics.Add(bodyTypeGraphic);
|
||||
}
|
||||
|
||||
switch (facing)
|
||||
{
|
||||
case CardinalDirection.North: return bodyTypeGraphic.northGraphic.path;
|
||||
case CardinalDirection.East: return bodyTypeGraphic.eastGraphic.path;
|
||||
case CardinalDirection.South: return bodyTypeGraphic.southGraphic.path;
|
||||
default: return bodyTypeGraphic.eastGraphic.path;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHeadGraphicPath(string path, CardinalDirection facing)
|
||||
{
|
||||
if (path == null || path.Any() == false || File.Exists(path) == false || Path.GetExtension(path) != ".png")
|
||||
{ path = "Invalid file path"; }
|
||||
|
||||
switch (facing)
|
||||
{
|
||||
case CardinalDirection.North:
|
||||
headGraphics.northGraphic.path = path;
|
||||
headGraphics.northGraphic.sprite = LoadSprite(path); break;
|
||||
case CardinalDirection.East:
|
||||
headGraphics.eastGraphic.path = path;
|
||||
headGraphics.eastGraphic.sprite = LoadSprite(path); break;
|
||||
case CardinalDirection.South:
|
||||
headGraphics.southGraphic.path = path;
|
||||
headGraphics.southGraphic.sprite = LoadSprite(path); break;
|
||||
default:
|
||||
headGraphics.eastGraphic.path = path;
|
||||
headGraphics.eastGraphic.sprite = LoadSprite(path); break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBodyTypeGraphicPath(string path, CardinalDirection facing, string bodyType = "None")
|
||||
{
|
||||
if (path == null || path.Any() == false || File.Exists(path) == false || Path.GetExtension(path) != ".png")
|
||||
{ path = "Invalid file path"; }
|
||||
|
||||
MultiDirectionalGraphic bodyTypeGraphic = bodyTypeGraphics.FirstOrDefault(x => x.bodyType == bodyType);
|
||||
|
||||
if (bodyTypeGraphic == null)
|
||||
{
|
||||
bodyTypeGraphic = new MultiDirectionalGraphic(bodyType);
|
||||
bodyTypeGraphics.Add(bodyTypeGraphic);
|
||||
}
|
||||
|
||||
switch (facing)
|
||||
{
|
||||
case CardinalDirection.North:
|
||||
bodyTypeGraphic.northGraphic.path = path;
|
||||
bodyTypeGraphic.northGraphic.sprite = LoadSprite(path); break;
|
||||
case CardinalDirection.East:
|
||||
bodyTypeGraphic.eastGraphic.path = path;
|
||||
bodyTypeGraphic.eastGraphic.sprite = LoadSprite(path); break;
|
||||
case CardinalDirection.South:
|
||||
bodyTypeGraphic.southGraphic.path = path;
|
||||
bodyTypeGraphic.southGraphic.sprite = LoadSprite(path); break;
|
||||
default:
|
||||
bodyTypeGraphic.eastGraphic.path = path;
|
||||
bodyTypeGraphic.eastGraphic.sprite = LoadSprite(path); break;
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasValidHeadGraphicPath(CardinalDirection facing)
|
||||
{
|
||||
string path;
|
||||
|
||||
switch (facing)
|
||||
{
|
||||
case CardinalDirection.North: path = headGraphics.northGraphic.path; break;
|
||||
case CardinalDirection.East: path = headGraphics.eastGraphic.path; break;
|
||||
case CardinalDirection.South: path = headGraphics.southGraphic.path; break;
|
||||
default: path = headGraphics.eastGraphic.path; break;
|
||||
}
|
||||
|
||||
if (path == null || path.Any() == false || File.Exists(path) == false || Path.GetExtension(path) != ".png") return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool HasValidBodyTypeGraphicPath(CardinalDirection facing, string bodyType = "None")
|
||||
{
|
||||
MultiDirectionalGraphic bodyTypeGraphic = bodyTypeGraphics.FirstOrDefault(x => x.bodyType == bodyType);
|
||||
|
||||
if (bodyTypeGraphic == null)
|
||||
{
|
||||
bodyTypeGraphic = new MultiDirectionalGraphic(bodyType);
|
||||
bodyTypeGraphics.Add(bodyTypeGraphic);
|
||||
}
|
||||
|
||||
string path;
|
||||
|
||||
switch (facing)
|
||||
{
|
||||
case CardinalDirection.North: path = bodyTypeGraphic.northGraphic.path; break;
|
||||
case CardinalDirection.East: path = bodyTypeGraphic.eastGraphic.path; break;
|
||||
case CardinalDirection.South: path = bodyTypeGraphic.southGraphic.path; break;
|
||||
default: path = bodyTypeGraphic.eastGraphic.path; break;
|
||||
}
|
||||
|
||||
if (path == null || path.Any() == false || File.Exists(path) == false || Path.GetExtension(path) != ".png") return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Sprite LoadSprite(string path)
|
||||
{
|
||||
if (path == null || path.Any() == false || File.Exists(path) == false || Path.GetExtension(path) != ".png") return null;
|
||||
|
||||
byte[] pngBytes = File.ReadAllBytes(path);
|
||||
|
||||
Texture2D tex = new Texture2D(2, 2);
|
||||
tex.LoadImage(pngBytes);
|
||||
|
||||
Sprite sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 85.0f);
|
||||
|
||||
return sprite;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/AnimationComponents/AlienRaceDef.cs.meta
Normal file
11
Assets/Scripts/AnimationComponents/AlienRaceDef.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5b8a2db320a85494c882518c143b73f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,7 +1,10 @@
|
|||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
[Serializable]
|
||||
public class AlienRaceOffset
|
||||
{
|
||||
public string defName;
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
[Serializable]
|
||||
public class MultiDirectionalGraphic
|
||||
{
|
||||
public string bodyType = "None";
|
||||
public DirectionalGraphic northGraphic = new DirectionalGraphic();
|
||||
public DirectionalGraphic eastGraphic = new DirectionalGraphic();
|
||||
public DirectionalGraphic southGraphic = new DirectionalGraphic();
|
||||
|
||||
public MultiDirectionalGraphic() { }
|
||||
|
||||
public MultiDirectionalGraphic(string bodyType)
|
||||
{
|
||||
this.bodyType = bodyType;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 86cb79b8d4c053f4a981ed17b86ae9bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue