forked from ToadsworthLP/desktoptale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Preset.cs
76 lines (67 loc) · 2.52 KB
/
Preset.cs
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
using System;
using Desktoptale.Characters;
using Microsoft.Xna.Framework;
namespace Desktoptale
{
public class Preset
{
public const int FILE_FORMAT_VERSION = 1;
public int Version { get; set; }
public string Character { get; set; }
public float XPosition { get; set; } = -1;
public float YPosition { get; set; } = -1;
public int Scale { get; set; }
public bool IdleRoaming { get; set; }
public bool UnfocusedInput { get; set; }
public string Window { get; set; }
public string Party { get; set; }
public Preset()
{
Version = FILE_FORMAT_VERSION;
}
public Preset(Settings settings)
{
Version = FILE_FORMAT_VERSION;
Character = settings.Character;
Scale = settings.Scale;
IdleRoaming = settings.IdleRoaming;
UnfocusedInput = settings.UnfocusedInput;
Window = settings.Window;
Party = settings.Party;
}
public Preset(CharacterProperties properties, Func<CharacterType, string> idResolver)
{
Character = idResolver.Invoke(properties.Type);
XPosition = properties.Position.X;
YPosition = properties.Position.Y;
Scale = (int)properties.Scale.X;
IdleRoaming = properties.IdleRoamingEnabled;
UnfocusedInput = properties.UnfocusedInputEnabled;
Window = properties.StayInsideWindow?.ProcessName;
Party = properties.Party?.Name;
}
public void Apply(Settings settings)
{
settings.Character = Character;
settings.Scale = Scale;
settings.IdleRoaming = IdleRoaming;
settings.UnfocusedInput = UnfocusedInput;
settings.Window = Window;
settings.Party = Party;
settings.Validate();
}
public CharacterProperties ToCharacterProperties(Func<string, CharacterType> typeResolver, Func<string, WindowInfo> windowResolver, Func<string, Party> partyResolver)
{
CharacterProperties result = new CharacterProperties(
typeResolver.Invoke(Character),
new Vector2(XPosition, YPosition),
new Vector2(Scale),
IdleRoaming,
UnfocusedInput,
windowResolver.Invoke(Window),
partyResolver.Invoke(Party)
);
return result;
}
}
}