Survivalcraft API 1.8.2.3
v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ColorHumanReadableConverter.cs
浏览该文件的文档.
1
namespace
Engine.Serialization
{
2
[
HumanReadableConverter
(typeof(
Color
))]
3
public
class
ColorHumanReadableConverter
:
IHumanReadableConverter
{
4
public
string
ConvertToString
(
object
value) {
5
Color
color = (
Color
)value;
6
return
color.A != byte.MaxValue
7
?
HumanReadableConverter
.ValuesListToString(
','
, color.
R
, color.
G
, color.
B
, color.
A
)
8
:
HumanReadableConverter
.ValuesListToString(
','
, color.
R
, color.
G
, color.
B
);
9
}
10
11
public
object
ConvertFromString
(Type type,
string
data) {
12
if
(data[0] ==
'#'
) {
13
if
(data.Length == 7) {
14
byte
r = (byte)(16 *
HexToDecimal
(data[1]) +
HexToDecimal
(data[2]));
15
byte
g = (byte)(16 *
HexToDecimal
(data[3]) +
HexToDecimal
(data[4]));
16
byte
b = (byte)(16 *
HexToDecimal
(data[5]) +
HexToDecimal
(data[6]));
17
return
new
Color
(r, g, b);
18
}
19
if
(data.Length == 9) {
20
byte
r2 = (byte)(16 *
HexToDecimal
(data[1]) +
HexToDecimal
(data[2]));
21
byte
g2 = (byte)(16 *
HexToDecimal
(data[3]) +
HexToDecimal
(data[4]));
22
byte
b2 = (byte)(16 *
HexToDecimal
(data[5]) +
HexToDecimal
(data[6]));
23
byte
a = (byte)(16 *
HexToDecimal
(data[7]) +
HexToDecimal
(data[8]));
24
return
new
Color
(r2, g2, b2, a);
25
}
26
throw
new
Exception();
27
}
28
int
[] array =
HumanReadableConverter
.ValuesListFromString<
int
>(
','
, data);
29
return
array.Length == 3 ?
new
Color
(array[0], array[1], array[2]) :
30
array.Length == 4 ? (object)
new
Color
(array[0], array[1], array[2], array[3]) :
throw
new
Exception();
31
}
32
33
static
int
HexToDecimal
(
char
digit) {
34
if
(digit >=
'0'
35
&& digit <=
'9'
) {
36
return
digit - 48;
37
}
38
return
digit >=
'A'
&& digit <=
'F'
? digit - 65 + 10 :
39
digit >=
'a'
&& digit <=
'f'
? digit - 97 + 10 :
throw
new
Exception();
40
}
41
}
42
}
Color
Engine.Color Color
定义
CommunityContentScreen.cs:9
Engine.Serialization.ColorHumanReadableConverter
定义
ColorHumanReadableConverter.cs:3
Engine.Serialization.ColorHumanReadableConverter.ConvertFromString
object ConvertFromString(Type type, string data)
定义
ColorHumanReadableConverter.cs:11
Engine.Serialization.ColorHumanReadableConverter.HexToDecimal
static int HexToDecimal(char digit)
定义
ColorHumanReadableConverter.cs:33
Engine.Serialization.ColorHumanReadableConverter.ConvertToString
string ConvertToString(object value)
定义
ColorHumanReadableConverter.cs:4
Engine.Serialization.HumanReadableConverter
定义
HumanReadableConverter.cs:5
Engine.Serialization.IHumanReadableConverter
定义
IHumanReadableConverter.cs:2
Engine.Serialization
定义
Archive.cs:4
Engine.Color
定义
Color.cs:2
Engine.Color.G
byte G
定义
Color.cs:82
Engine.Color.R
byte R
定义
Color.cs:77
Engine.Color.B
byte B
定义
Color.cs:87
Engine.Color.A
byte A
定义
Color.cs:92
SurvivalcraftApi 1.8.2.3
Engine
Engine.Serialization
ColorHumanReadableConverter.cs
制作者
1.16.1