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
|
function split_seps(str, arr) {
delete arr
begin = 1
idx = 1
for (k = 1; k <= length(str); ++k) {
ch = substr(str, k, 1)
if (ch ~ "[=; ]") {
arr[idx++] = substr(str, begin, k-begin)
arr[idx++] = ch
begin = k+1
++k
} else if (k == length(str)) {
arr[idx++] = substr(str, begin, k-begin+1)
}
}
return idx-1
}
function conv_col(c) {
n = 0 + c
n = n / 255.0
return sprintf("%.3f", n)
}
function conv_line(pattern) {
i = 1
num = split_seps($0, split_string)
while (i <= num) {
if (split_string[i] ~ pattern) {
j = 0
while (j < 4) {
i++
if (split_string[i] ~ "[=; ]") continue
j++
if (! (split_string[i] ~ /^[0-9]+/)) {
--i
break
}
split_string[i] = conv_col(split_string[i])
}
}
++i
}
$0 = ""
for (i = 1; i <= num; ++i) {
$0 = $0 split_string[i]
}
}
/^AmbientColor/ || /^FogColor/ {
conv_line("air|water")
}
/^VehicleColor/ || /^InsectColor/ || /^GreeneryColor/ {
conv_line("color")
}
/^Background/ {
conv_line("up|down|cloudUp|cloudDown")
}
/^TerrainWater/ {
conv_line("diffuse|ambient|color")
}
/^TerrainCloud/ {
conv_line("diffuse|ambient")
}
/^GroundSpot/ {
conv_line("color")
}
/^MapColor/ {
conv_line("floor|water")
}
# Don't change WaterAddColor, CreateSpot, CreateLight as they are OK
{ print }
|