mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Unity serialization rules are stupid
This commit is contained in:
parent
42e6b18845
commit
7e3f4b84ff
@ -1,11 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using ConformalDecals.Util;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
// ReSharper disable NonReadonlyMemberInGetHashCode
|
// ReSharper disable NonReadonlyMemberInGetHashCode
|
||||||
|
|
||||||
namespace ConformalDecals.Text {
|
namespace ConformalDecals.Text {
|
||||||
public struct DecalTextStyle : IEquatable<DecalTextStyle> {
|
public class DecalTextStyle : ScriptableObject, IEquatable<DecalTextStyle> {
|
||||||
public FontStyles FontStyle { get; set; }
|
private FontStyles _fontStyle;
|
||||||
|
private bool _vertical;
|
||||||
|
private float _lineSpacing;
|
||||||
|
private float _characterSpacing;
|
||||||
|
|
||||||
|
public FontStyles FontStyle {
|
||||||
|
get => _fontStyle;
|
||||||
|
set => _fontStyle = value;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Bold {
|
public bool Bold {
|
||||||
get => (FontStyle & FontStyles.Bold) != 0;
|
get => (FontStyle & FontStyles.Bold) != 0;
|
||||||
@ -39,38 +49,69 @@ namespace ConformalDecals.Text {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Vertical { get; set; }
|
public bool Vertical {
|
||||||
|
get => _vertical;
|
||||||
|
set => _vertical = value;
|
||||||
|
}
|
||||||
|
|
||||||
public float LineSpacing { get; set; }
|
public float LineSpacing {
|
||||||
|
get => _lineSpacing;
|
||||||
|
set => _lineSpacing = value;
|
||||||
|
}
|
||||||
|
|
||||||
public float CharacterSpacing { get; set; }
|
public float CharacterSpacing {
|
||||||
|
get => _characterSpacing;
|
||||||
|
set => _characterSpacing = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DecalTextStyle Load(ConfigNode node) {
|
||||||
|
var style = CreateInstance<DecalTextStyle>();
|
||||||
|
style._fontStyle = (FontStyles) ParseUtil.ParseInt(node, "fontStyle", true);
|
||||||
|
style._vertical = ParseUtil.ParseBool(node, "vertical", true);
|
||||||
|
style._lineSpacing = ParseUtil.ParseFloat(node, "lineSpacing", true);
|
||||||
|
style._characterSpacing = ParseUtil.ParseFloat(node, "characterSpacing", true);
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigNode Save() {
|
||||||
|
var node = new ConfigNode("STYLE");
|
||||||
|
node.AddValue("fontStyle", (int) _fontStyle);
|
||||||
|
node.AddValue("vertical", _vertical);
|
||||||
|
node.AddValue("lineSpacing", _lineSpacing);
|
||||||
|
node.AddValue("characterSpacing", _characterSpacing);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Equals(DecalTextStyle other) {
|
public bool Equals(DecalTextStyle other) {
|
||||||
return FontStyle == other.FontStyle && Vertical == other.Vertical &&
|
if (ReferenceEquals(null, other)) return false;
|
||||||
Mathf.Approximately(LineSpacing, other.LineSpacing) &&
|
if (ReferenceEquals(this, other)) return true;
|
||||||
Mathf.Approximately(CharacterSpacing, other.CharacterSpacing);
|
return base.Equals(other) && _fontStyle == other._fontStyle && _vertical == other._vertical && _lineSpacing.Equals(other._lineSpacing) && _characterSpacing.Equals(other._characterSpacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object obj) {
|
public override bool Equals(object obj) {
|
||||||
return obj is DecalTextStyle other && Equals(other);
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
|
return Equals((DecalTextStyle) obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode() {
|
public override int GetHashCode() {
|
||||||
unchecked {
|
unchecked {
|
||||||
var hashCode = (int) FontStyle;
|
int hashCode = base.GetHashCode();
|
||||||
hashCode = (hashCode * 397) ^ Vertical.GetHashCode();
|
hashCode = (hashCode * 397) ^ (int) _fontStyle;
|
||||||
hashCode = (hashCode * 397) ^ LineSpacing.GetHashCode();
|
hashCode = (hashCode * 397) ^ _vertical.GetHashCode();
|
||||||
hashCode = (hashCode * 397) ^ CharacterSpacing.GetHashCode();
|
hashCode = (hashCode * 397) ^ _lineSpacing.GetHashCode();
|
||||||
|
hashCode = (hashCode * 397) ^ _characterSpacing.GetHashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator ==(DecalTextStyle left, DecalTextStyle right) {
|
public static bool operator ==(DecalTextStyle left, DecalTextStyle right) {
|
||||||
return left.Equals(right);
|
return Equals(left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator !=(DecalTextStyle left, DecalTextStyle right) {
|
public static bool operator !=(DecalTextStyle left, DecalTextStyle right) {
|
||||||
return !left.Equals(right);
|
return !Equals(left, right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user