Code refactor

This commit is contained in:
AbstractConcept 2022-10-27 00:56:04 -05:00
parent cd4711a8e5
commit 757badf4f6
517 changed files with 2534 additions and 2221 deletions

View file

@ -21,21 +21,21 @@ namespace RimWorldAnimationStudio
{
Reset();
AlienRaceDef alienRaceDef = GetCurrentRaceDef();
if (alienRaceDef == null) return;
PawnRaceDef pawnRaceDef = GetCurrentRaceDef();
if (pawnRaceDef == null) return;
isHumanoidToggle.SetIsOnWithoutNotify(alienRaceDef.isHumanoid);
isHumanoidToggle.SetIsOnWithoutNotify(pawnRaceDef.isHumanoid);
Text bodyGraphicsTitle = AddCloneObjectToParent(raceSettingsWindow, 2).GetComponent<Text>();
bodyGraphicsTitle.text = "Body graphic filepaths";
List<string> allTags = alienRaceDef.isHumanoid ? Tags.bodyTypes : new List<string>() { "None" };
List<string> allTags = pawnRaceDef.isHumanoid ? DefaultTags.bodyTypes : new List<string>() { "None" };
foreach (string bodyType in allTags)
{
string _bodyType = bodyType;
if (alienRaceDef.isHumanoid)
if (pawnRaceDef.isHumanoid)
{
Text bodyTypeTitle = AddCloneObjectToParent(raceSettingsWindow, 2).GetComponent<Text>();
bodyTypeTitle.text = bodyType;
@ -49,15 +49,15 @@ namespace RimWorldAnimationStudio
filepath.GetComponent<Text>().text = facing.ToString();
filepath.transform.Find("FilepathButton").GetComponent<Button>().onClick.AddListener(delegate
{
SetBodyTypeGraphicPath(alienRaceDef, facing, _bodyType);
SetBodyTypeGraphicPath(pawnRaceDef, facing, _bodyType);
});
filepath.transform.FindDeepChild("FilepathLabel").GetComponent<Text>().text = alienRaceDef.GetBodyTypeGraphicPath(facing, _bodyType);
filepath.transform.FindDeepChild("FilepathLabel").GetComponent<Text>().text = pawnRaceDef.GetBodyTypeGraphicPath(facing, _bodyType);
}
AddCloneObjectToParent(raceSettingsWindow, 3);
}
if (alienRaceDef.isHumanoid)
if (pawnRaceDef.isHumanoid)
{
Text headGraphics = AddCloneObjectToParent(raceSettingsWindow, 2).GetComponent<Text>();
headGraphics.text = "Head graphic filepaths";
@ -70,15 +70,15 @@ namespace RimWorldAnimationStudio
filepath.GetComponent<Text>().text = facing.ToString();
filepath.transform.Find("FilepathButton").GetComponent<Button>().onClick.AddListener(delegate
{
SetHeadGraphicPath(alienRaceDef, facing);
SetHeadGraphicPath(pawnRaceDef, facing);
});
filepath.transform.FindDeepChild("FilepathLabel").GetComponent<Text>().text = alienRaceDef.GetHeadGraphicPath(facing);
filepath.transform.FindDeepChild("FilepathLabel").GetComponent<Text>().text = pawnRaceDef.GetHeadGraphicPath(facing);
}
AddCloneObjectToParent(raceSettingsWindow, 3);
}
scaleField.text = string.Format("{0:0.000}", alienRaceDef.scale.ToString());
scaleField.text = string.Format("{0:0.000}", pawnRaceDef.scale.ToString());
}
public void Reset()
@ -88,53 +88,53 @@ namespace RimWorldAnimationStudio
public void SetIsHumanoid()
{
AlienRaceDef alienRaceDef = GetCurrentRaceDef();
if (alienRaceDef == null) return;
PawnRaceDef pawnRaceDef = GetCurrentRaceDef();
if (pawnRaceDef == null) return;
alienRaceDef.isHumanoid = isHumanoidToggle.isOn;
pawnRaceDef.isHumanoid = isHumanoidToggle.isOn;
Initialize();
}
public void SetHeadGraphicPath(AlienRaceDef alienRaceDef, CardinalDirection direction)
public void SetHeadGraphicPath(PawnRaceDef pawnRaceDef, CardinalDirection direction)
{
var paths = StandaloneFileBrowser.OpenFilePanel("Select texture File", "", "png", false);
if (paths == null || paths.Any() == false || File.Exists(paths[0]) == false)
{ Debug.LogWarning("Selected file was null or invalid"); return; }
alienRaceDef.SetHeadGraphicPath(paths[0], direction);
pawnRaceDef.SetHeadGraphicPath(paths[0], direction);
Initialize();
}
public void SetBodyTypeGraphicPath(AlienRaceDef alienRaceDef, CardinalDirection direction, string bodyType)
public void SetBodyTypeGraphicPath(PawnRaceDef pawnRaceDef, CardinalDirection direction, string bodyType)
{
var paths = StandaloneFileBrowser.OpenFilePanel("Select texture File", "", "png", false);
if (paths == null || paths.Any() == false || File.Exists(paths[0]) == false)
{ Debug.LogWarning("Selected file was null or invalid"); return; }
alienRaceDef.SetBodyTypeGraphicPath(paths[0], direction, bodyType);
pawnRaceDef.SetBodyTypeGraphicPath(paths[0], direction, bodyType);
Initialize();
}
public AlienRaceDef GetCurrentRaceDef()
public PawnRaceDef GetCurrentRaceDef()
{
string alienRaceDefName = raceSelectDropdown.value < raceSelectDropdown.options.Count ? raceSelectDropdown.options[raceSelectDropdown.value].text : "Human";
if (alienRaceDefName == null || alienRaceDefName == "") alienRaceDefName = "Human";
string pawnRaceDefName = raceSelectDropdown.value < raceSelectDropdown.options.Count ? raceSelectDropdown.options[raceSelectDropdown.value].text : "Human";
if (pawnRaceDefName == null || pawnRaceDefName == "") pawnRaceDefName = "Human";
return AlienRaceDefs.GetNamed(alienRaceDefName);
return PawnRaceDefs.GetNamed(pawnRaceDefName);
}
public void SetRaceScale()
{
AlienRaceDef alienRaceDef = GetCurrentRaceDef();
if (alienRaceDef == null) return;
PawnRaceDef pawnRaceDef = GetCurrentRaceDef();
if (pawnRaceDef == null) return;
float scale = float.Parse(scaleField.text);
alienRaceDef.scale = Mathf.Clamp(scale, 0.05f, 100f);
pawnRaceDef.scale = Mathf.Clamp(scale, 0.05f, 100f);
}
}
}