-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTitles2Text.ps1
More file actions
147 lines (130 loc) · 3.24 KB
/
Titles2Text.ps1
File metadata and controls
147 lines (130 loc) · 3.24 KB
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
147
<# Titles2Text.ps1 - Convert titles.txt to titles.ent for use in the game.
Use for changeing env_message titles file to discreet game_text entities
Usage:-
- Place the script in the same directory as titles.txt.
- Run the script from PowerShell or Command Prompt.
- The converted file will be saved as titles.ent
- titles.ent contains the game_text entities which can be imported to a BSP via ripent
- Outerbeast
#>
$titlesPath = ".\titles.txt"
$outPath = ".\titles.ent"
$lines = Get-Content $titlesPath
# Current style dictionary
$style = @{
x = "-1"
y = "-1"
effect = "0"
color = "255 255 255"
color2 = "255 255 255"
fadein = "0.5"
fadeout = "0.5"
holdtime = "2"
fxtime = "0"
}
$entries = @()
$currentTitle = $null
$currentMessage = @()
$inBlock = $false
function CreateGameText($title, $msg, $style)
{
$entity = "{`n"
$entity += '"classname" "game_text"' + "`n"
$entity += '"targetname" "' + $title + '"' + "`n"
$entity += '"message" "' + $msg + '"' + "`n"
foreach( $k in $style.Keys )
{
$entity += '"' + $k + '" "' + $style[$k] + '"' + "`n"
}
$entity += "}`n"
return $entity
}
foreach( $raw in $lines )
{
$line = $raw.Trim()
# Skip comments
if( $line.StartsWith( "//" ) )
{
continue
}
# Handle style commands
if( $line.StartsWith( "$" ) )
{
$parts = $line.Split( " ", 2, "RemoveEmptyEntries" )
$cmd = $parts[0].Substring( 1 ) # remove $
$value = $parts[1]
switch( $cmd )
{
"position"
{
$xy = $value.Split( " " )
$style["x"] = $xy[0]
$style["y"] = $xy[1]
}
"color"
{
$style["color"] = $value
}
"color2"
{
$style["color2"] = $value
}
"effect"
{
$style["effect"] = $value
}
"fadein"
{
$style["fadein"] = $value
}
"fadeout"
{
$style["fadeout"] = $value
}
"holdtime"
{
$style["holdtime"] = $value
}
"fxtime"
{
$style["fxtime"] = $value
}
}
continue
}
# Start of message block
if( $line -eq "{" )
{
$inBlock = $true
continue
}
# End of message block
if( $line -eq "}" )
{
if( $currentTitle )
{
$msg = ( $currentMessage -join "\n" )
$entries += CreateGameText $currentTitle $msg $style
}
$currentTitle = $null
$currentMessage = @()
$inBlock = $false
continue
}
# Inside message block
if( $inBlock )
{
$currentMessage += $line
continue
}
# Title name
if( $line -ne "" )
{
$currentTitle = $line
continue
}
}
# Write output
$entries | Set-Content $outPath
Write-Host "Done! Output written to $outPath"
Read-Host