-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDM_WAED Enchant Duplicator.fsx
146 lines (116 loc) · 3.62 KB
/
DM_WAED Enchant Duplicator.fsx
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#r "nuget: TextCopy"
open System.IO
open System.Text.RegularExpressions
open System
type OutFilePrompt =
| WantsVanilla = 1
| WantsSummermyst = 2
let getOutFile () =
printfn "Select the destination file:"
printfn "\t1) Vanilla WAED"
printfn "\t2) Summermyst WAED"
match Console.ReadLine()
|> Int32.Parse
|> enum<OutFilePrompt>
with
| OutFilePrompt.WantsVanilla -> "WAED Enchantments.esp"
| OutFilePrompt.WantsSummermyst -> "WAED Enchantments - Summermyst.esp"
| x -> failwith $"({x}) is not a valid option"
type EnchFX =
{ name: string
magnitude: float
area: int
duration: int }
let getEffects text =
let ms = Regex(@"(?ms)\*\*\*S(.*?)\*\*\*E").Matches(text)
let effects =
[| for m in ms do
m.Groups[1].Value |]
|> Array.map (fun s ->
s.Trim().Split("\n")
|> Array.map (fun s2 -> s2.Trim()))
|> Array.map (fun a ->
let v n = a[n][a[ n ].IndexOf(": ") + 2 ..]
{ name = a[0]
magnitude = v 1 |> Double.Parse
area = v 2 |> Int32.Parse
duration = v 3 |> Int32.Parse })
|> Array.map (fun fx ->
"""
fx := ElementAssign(fxs, HighInteger, nil, false);
SetElementEditValues(fx, 'EFID', '___name___');
SetElementEditValues(fx, 'EFIT\Magnitude', ___magnitude___);
SetElementEditValues(fx, 'EFIT\Area', ___area___);
SetElementEditValues(fx, 'EFIT\Duration', ___duration___);"""
.Replace("___name___", fx.name)
.Replace("___magnitude___", fx.magnitude.ToString())
.Replace("___area___", fx.area.ToString())
.Replace("___duration___", fx.duration.ToString()))
|> Array.fold (fun acc s -> acc + "\n" + s) ""
effects.Trim()
let effects = TextCopy.ClipboardService.GetText() |> getEffects
printfn "%s\n%s\n" effects ("".PadRight(50, '*'))
let outFile = getOutFile ()
let getEnchantName () =
printfn "What is the enchant name (FULL)?"
Console.ReadLine()
|> Globalization
.CultureInfo(
"en-US",
false
)
.TextInfo
.ToTitleCase
let generateEdid enchName =
"DM_Ench_"
+ Regex(@"\s+").Replace(enchName, "")
+ "_Var"
let full = getEnchantName ()
let edid = generateEdid full
let contents =
"""
unit DM_WAED_AddEnchantments;
{
*** Autogenerated ***
Hotkey: Shift+F3
}
interface
uses xEditApi;
implementation
function FileByName(s: string): IInterface;
var
i: integer;
begin
Result := nil;
for i := 0 to FileCount - 1 do
if GetFileName(FileByIndex(i)) = s then begin
Result := FileByIndex(i);
Exit;
end;
end;
procedure CopyToWaed(e: IInterface);
var
newRecord, fxs, fx: IInterface;
begin
newRecord := wbCopyElementToFile(e, FileByName('___outFile___'), true, true);
// Clear base enchanment so this can't be learned
SetElementEditValues(newRecord, 'ENIT\Base Enchantment', '');
SetElementEditValues(newRecord, 'ENIT\Worn Restrictions', '');
// Rename
SetElementEditValues(newRecord, 'EDID', '___edid___');
SetElementEditValues(newRecord, 'FULL', '___full___');
// Add new effects
fxs := ElementByPath(newRecord, 'Effects');
___fxs___
end;
function Process(e: IInterface): Integer;
begin
if Signature(e) = 'ENCH' then CopyToWaed(e);
end;
end.
"""
.Replace("___fxs___", effects)
.Replace("___outFile___", outFile)
.Replace("___edid___", edid)
.Replace("___full___", full)
File.WriteAllText(Path.Combine(__SOURCE_DIRECTORY__, "DM_WAED_AddEnchantments.pas"), contents)