diff options
author | Hume2 <teratux.mail@gmail.com> | 2020-07-25 19:07:02 +0200 |
---|---|---|
committer | Gabriel PĂ©rez-Cerezo <gabriel@gpcf.eu> | 2020-07-25 19:07:02 +0200 |
commit | 643d69db9c8270af44eb060bd146e56a386f76d8 (patch) | |
tree | 39790240530c86814236954a261451482e42e864 /advtrains_train_subway/init.lua | |
parent | 7e83b718a6f4e571c70db6b551889005e42e230e (diff) | |
download | advtrains-643d69db9c8270af44eb060bd146e56a386f76d8.tar.gz advtrains-643d69db9c8270af44eb060bd146e56a386f76d8.tar.bz2 advtrains-643d69db9c8270af44eb060bd146e56a386f76d8.zip |
subway trains: display up to two digits
Additionally, as an addition by gpcf, trains having an S as the first
letter of their LN get the number behind the S displayed as a line
number
Diffstat (limited to 'advtrains_train_subway/init.lua')
-rw-r--r-- | advtrains_train_subway/init.lua | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/advtrains_train_subway/init.lua b/advtrains_train_subway/init.lua index c51758d..add961b 100644 --- a/advtrains_train_subway/init.lua +++ b/advtrains_train_subway/init.lua @@ -98,23 +98,46 @@ advtrains.register_wagon("subway_wagon", { custom_on_step = function(self, dtime, data, train) --set line number local line = nil - if train.line then - local lint = string.sub(train.line, 1, 1) - line = tonumber(lint) - if lint=="X" then line="X" end - end - if line and line~=self.line_cache then - local new_line_tex="advtrains_subway_wagon.png^advtrains_subway_wagon_line"..line..".png" - self.object:set_properties({ - textures={new_line_tex}, - }) - self.line_cache=line - elseif self.line_cache~=nil and line==nil then - self.object:set_properties({ - textures=self.textures, - }) - self.line_cache=nil - end + if train.line and self.line_cache ~= train.line then + self.line_cache=train.line + local lint = train.line + if string.sub(train.line, 1, 1) == "S" then + lint = string.sub(train.line,2) + end + if string.len(lint) == 1 then + if lint=="X" then line="X" end + line = tonumber(lint) + elseif string.len(lint) == 2 then + if tonumber(lint) then + line = lint + end + end + if line then + local new_line_tex="advtrains_subway_wagon.png" + if type(line)=="number" or line == "X" then + new_line_tex = new_line_tex.."^advtrains_subway_wagon_line"..line..".png" + else + local num = tonumber(line) + local red = math.fmod(line*67+101, 255) + local green = math.fmod(line*97+109, 255) + local blue = math.fmod(line*73+127, 255) + new_line_tex = new_line_tex..string.format("^(advtrains_subway_wagon_line.png^[colorize:#%X%X%X%X%X%X)^(advtrains_subway_wagon_line%s_.png^advtrains_subway_wagon_line_%s.png", math.floor(red/16), math.fmod(red,16), math.floor(green/16), math.fmod(green,16), math.floor(blue/16), math.fmod(blue,16), string.sub(line, 1, 1), string.sub(line, 2, 2)) + if red + green + blue > 512 then + new_line_tex = new_line_tex .. "^[colorize:#000)" + else + new_line_tex = new_line_tex .. ")" + end + end + self.object:set_properties({ + textures={new_line_tex}, + }) + elseif self.line_cache~=nil and line==nil then + self.object:set_properties({ + textures=self.textures, + }) + self.line_cache=nil + end + end end, }, S("Subway Passenger Wagon"), "advtrains_subway_wagon_inv.png") |