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 ConformalDecals.Util;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
// ReSharper disable NonReadonlyMemberInGetHashCode
|
||||
|
||||
namespace ConformalDecals.Text {
|
||||
public struct DecalTextStyle : IEquatable<DecalTextStyle> {
|
||||
public FontStyles FontStyle { get; set; }
|
||||
public class DecalTextStyle : ScriptableObject, IEquatable<DecalTextStyle> {
|
||||
private FontStyles _fontStyle;
|
||||
private bool _vertical;
|
||||
private float _lineSpacing;
|
||||
private float _characterSpacing;
|
||||
|
||||
public FontStyles FontStyle {
|
||||
get => _fontStyle;
|
||||
set => _fontStyle = value;
|
||||
}
|
||||
|
||||
public bool Bold {
|
||||
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) {
|
||||
return FontStyle == other.FontStyle && Vertical == other.Vertical &&
|
||||
Mathf.Approximately(LineSpacing, other.LineSpacing) &&
|
||||
Mathf.Approximately(CharacterSpacing, other.CharacterSpacing);
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return base.Equals(other) && _fontStyle == other._fontStyle && _vertical == other._vertical && _lineSpacing.Equals(other._lineSpacing) && _characterSpacing.Equals(other._characterSpacing);
|
||||
}
|
||||
|
||||
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() {
|
||||
unchecked {
|
||||
var hashCode = (int) FontStyle;
|
||||
hashCode = (hashCode * 397) ^ Vertical.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ LineSpacing.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ CharacterSpacing.GetHashCode();
|
||||
int hashCode = base.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ (int) _fontStyle;
|
||||
hashCode = (hashCode * 397) ^ _vertical.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ _lineSpacing.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ _characterSpacing.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DecalTextStyle left, DecalTextStyle right) {
|
||||
return left.Equals(right);
|
||||
return Equals(left, 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