VOID_Core: Wrapped some of the flight-specific things in HighLogic.LoadedSceneIs
[VOID.git] /
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
//  VOID_Config.cs
//
//  Author:
//       toadicus <>
//
//  Copyright (c) 2013 toadicus
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using KSP;
using UnityEngine;

namespace VOID
{
	public struct VOID_SaveValue<T> : IVOID_SaveValue
	{
		private T _value;
		private Type _type;

		public T value
		{
			get
			{
				return this._value;
			}
			set
			{
				this._value = value;
			}
		}

		public Type type
		{
			get
			{
				return this._type;
			}
			set
			{
				this._type = value;
			}
		}

		public object AsType
		{
			get
			{
				return (T)this._value;
			}
		}

		public void SetValue(object v)
		{
			this._value = (T)v;
		}

		public static implicit operator T(VOID_SaveValue<T> v)
		{
			return v.value;
		}

		public static implicit operator VOID_SaveValue<T>(T v)
		{
			VOID_SaveValue<T> r = new VOID_SaveValue<T>();
			r.value = v;
			r.type = v.GetType();
			if (VOID_Core.Initialized)
			{
				VOID_Core.Instance.configDirty = true;
			}
			return r;
		}

		public new string ToString()
		{
			return this.value.ToString();
		}
	}

	public interface IVOID_SaveValue
	{
		Type type { get; }
		object AsType { get; }
		void SetValue(object v);
	}

	[AttributeUsage(AttributeTargets.Field)]
	public class AVOID_SaveValue : Attribute
	{
		protected string _name;

		public string Name
		{
			get
			{
				return this._name;
			}
		}

		public AVOID_SaveValue(string fieldName)
		{
			this._name = fieldName;
		}
	}
}