init.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. local S
  2. if minetest.get_modpath("intllib") then
  3. S = intllib.Getter()
  4. else
  5. S = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
  6. end
  7. -- Begin support code for AdvTrains Livery Designer
  8. local use_advtrains_livery_designer = minetest.get_modpath( "advtrains_livery_designer" ) and advtrains_livery_designer
  9. local mod_name = "tfl_s7_stock_modpack"
  10. local livery_templates = {
  11. ["advtrains:under_s7dm"] = {
  12. {
  13. name = "London",
  14. designer = "Marnack",
  15. texture_license = "CC-BY-SA-3.0",
  16. texture_creator = "Mainote Plants Lab, with updates by Blockhead and Marnack",
  17. notes = "This template is loosely based on the original livery of the London Underground's S7 and S8 stock.",
  18. base_textures = {"advtrains_london_s7dm.png"},
  19. overlays = {
  20. [1] = {name = "Cab End and Doors", texture = "advtrains_london_s7dm_livery.png"},
  21. [2] = {name = "Side Doors", texture = "advtrains_london_s7dm_common_doors.png"},
  22. [3] = {name = "Base Stripe", texture = "advtrains_london_s7dm_01_stripe.png"},
  23. [4] = {name = "Side Walls", texture = "advtrains_london_s7dm_01_side_walls.png"},
  24. [5] = {name = "Roof", texture = "advtrains_london_s7dm_common_roof.png"},
  25. },
  26. },
  27. },
  28. ["advtrains:under_s7ndm"] = {
  29. {
  30. name = "London",
  31. designer = "Marnack",
  32. texture_license = "CC-BY-SA-3.0",
  33. texture_creator = "Mainote Plants Lab, with updates by Marnack",
  34. notes = "This template is loosely based on the original livery of the London Underground's S7 and S8 stock.",
  35. base_textures = {"advtrains_london_s7ndm.png"},
  36. overlays = {
  37. [1] = {name = "Side Doors", texture = "advtrains_london_s7ndm_livery.png"},
  38. [2] = {name = "Base Stripe", texture = "advtrains_london_s7ndm_01_stripe.png"},
  39. [3] = {name = "Side Walls", texture = "advtrains_london_s7ndm_01_side_walls.png"},
  40. [4] = {name = "Roof", texture = "advtrains_london_s7ndm_common_roof.png"},
  41. },
  42. },
  43. },
  44. }
  45. local predefined_liveries = {
  46. {
  47. name = "Reverse Motif",
  48. notes = "",
  49. livery_design = {
  50. wagon_type = "advtrains:under_s7dm",
  51. livery_template_name = "London",
  52. overlays = {
  53. [1] = {id = 1, color = "#002D73"}, -- Cab End and Doors
  54. -- [2] = {id = 2, color = "#000000"}, -- Side Doors
  55. [3] = {id = 3, color = "#DF002C"}, -- Base Stripe
  56. -- [4] = {id = 4, color = "#000000"}, -- Side Walls
  57. -- [5] = {id = 5, color = "#000000"}, -- Roof
  58. },
  59. },
  60. },
  61. {
  62. name = "Reverse Motif",
  63. notes = "",
  64. livery_design = {
  65. wagon_type = "advtrains:under_s7ndm",
  66. livery_template_name = "London",
  67. overlays = {
  68. [1] = {id = 1, color = "#002D73"}, -- Side Doors
  69. [2] = {id = 2, color = "#DF002C"}, -- Base Stripe
  70. -- [3] = {id = 3, color = "#000000"}, -- Side Walls
  71. -- [4] = {id = 4, color = "#000000"}, -- Roof
  72. },
  73. },
  74. },
  75. {
  76. name = "Retro Red",
  77. notes = "",
  78. livery_design = {
  79. wagon_type = "advtrains:under_s7dm",
  80. livery_template_name = "London",
  81. overlays = {
  82. -- [1] = {id = 1, color = "#000000"}, -- Cab End and Doors
  83. [2] = {id = 2, color = "#F2F2F2"}, -- Side Doors
  84. [3] = {id = 3, color = "#DF002C"}, -- Base Stripe
  85. [4] = {id = 4, color = "#DF002C"}, -- Side Walls
  86. [5] = {id = 5, color = "#BBBBBB"}, -- Roof
  87. },
  88. },
  89. },
  90. {
  91. name = "Retro Red",
  92. notes = "",
  93. livery_design = {
  94. wagon_type = "advtrains:under_s7ndm",
  95. livery_template_name = "London",
  96. overlays = {
  97. [1] = {id = 1, color = "#F2F2F2"}, -- Side Doors
  98. [2] = {id = 2, color = "#DF002C"}, -- Base Stripe
  99. [3] = {id = 3, color = "#DF002C"}, -- Side Walls
  100. [4] = {id = 4, color = "#BBBBBB"}, -- Roof
  101. },
  102. },
  103. },
  104. }
  105. if use_advtrains_livery_designer then
  106. -- Notify player if a newer version of AdvTrains Livery Tools is available or needed.
  107. if not advtrains_livery_designer.is_compatible_mod_version or
  108. not advtrains_livery_designer.is_compatible_mod_version({major = 0, minor = 8, patch = 1}) then
  109. minetest.log("info", "["..mod_name.."] An old version of AdvTrains Livery Tools was detected. Consider updating to the latest version.")
  110. -- Version 0.8.1 is not currently required so just log an informational message.
  111. end
  112. -- This function is called by the advtrains_livery_designer tool whenever
  113. -- the player activates the "Apply" button. This implementation is specific
  114. -- to the s7dm and s7ndm units. A more complex implementation may be needed
  115. -- if other wagons or livery templates are added.
  116. local function apply_wagon_livery_textures(player, wagon, textures)
  117. if wagon and textures and textures[1] then
  118. local data = advtrains.wagons[wagon.id]
  119. data.livery = textures[1]
  120. wagon:set_textures(data)
  121. end
  122. end
  123. -- Register this mod and its livery function with the advtrains_livery_designer tool.
  124. advtrains_livery_designer.register_mod(mod_name, apply_wagon_livery_textures)
  125. -- Register this mod's wagons and livery templates.
  126. for wagon_type, wagon_livery_templates in pairs(livery_templates) do
  127. advtrains_livery_database.register_wagon(wagon_type, mod_name)
  128. for _, livery_template in pairs(wagon_livery_templates) do
  129. advtrains_livery_database.add_livery_template(
  130. wagon_type,
  131. livery_template.name,
  132. livery_template.base_textures,
  133. mod_name,
  134. (livery_template.overlays and #livery_template.overlays) or 0,
  135. livery_template.designer,
  136. livery_template.texture_license,
  137. livery_template.texture_creator,
  138. livery_template.notes
  139. )
  140. if livery_template.overlays then
  141. for overlay_id, overlay in ipairs(livery_template.overlays) do
  142. advtrains_livery_database.add_livery_template_overlay(
  143. wagon_type,
  144. livery_template.name,
  145. overlay_id,
  146. overlay.name,
  147. overlay.slot_idx or 1,
  148. overlay.texture,
  149. overlay.alpha
  150. )
  151. end
  152. end
  153. end
  154. end
  155. -- Register this mod's predefined wagon liveries.
  156. for _, predefined_livery in ipairs(predefined_liveries) do
  157. local livery_design = predefined_livery.livery_design
  158. advtrains_livery_database.add_predefined_livery(
  159. predefined_livery.name,
  160. livery_design,
  161. mod_name,
  162. predefined_livery.notes
  163. )
  164. end
  165. end
  166. local function update_livery(wagon, puncher)
  167. local itemstack = puncher:get_wielded_item()
  168. local item_name = itemstack:get_name()
  169. if use_advtrains_livery_designer and item_name == advtrains_livery_designer.tool_name then
  170. advtrains_livery_designer.activate_tool(puncher, wagon, mod_name)
  171. return true
  172. end
  173. return false
  174. end
  175. -- End of support code for AdvTrains Livery Designer
  176. local function set_livery(self, puncher, itemstack, data)
  177. local meta = itemstack:get_meta()
  178. local color = meta:get_string("paint_color")
  179. if color and color:find("^#%x%x%x%x%x%x$") then
  180. local alpha = tonumber(meta:get_string("alpha"))
  181. if alpha == 0 then
  182. data.livery = self.base_texture
  183. else
  184. data.livery = self.base_texture
  185. .."^("..self.base_livery.."^[colorize:"..color..":255)"
  186. end
  187. self:set_textures(data)
  188. end
  189. end
  190. local function set_textures(self, data)
  191. if data.livery then
  192. self.object:set_properties({textures={data.livery}})
  193. end
  194. end
  195. advtrains.register_wagon("under_s7dm", {
  196. mesh="advtrains_london_s7dm.b3d",
  197. textures = {"advtrains_london_s7dm.png"},
  198. base_texture = "advtrains_london_s7dm.png",
  199. base_livery = "advtrains_london_s7dm_livery.png",
  200. set_textures = set_textures,
  201. set_livery = set_livery,
  202. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  203. return not update_livery(wagon, puncher)
  204. end,
  205. drives_on={default=true},
  206. max_speed=20,
  207. seats = {
  208. {
  209. name=S("Driver stand"),
  210. attach_offset={x=0, y=8, z=19},
  211. view_offset={x=0, y=-1, z=18},
  212. driving_ctrl_access=true,
  213. group="dstand",
  214. },
  215. {
  216. name="1",
  217. attach_offset={x=-4, y=8, z=0},
  218. view_offset={x=0, y=0, z=0},
  219. group="pass",
  220. },
  221. {
  222. name="2",
  223. attach_offset={x=4, y=8, z=0},
  224. view_offset={x=0, y=0, z=0},
  225. group="pass",
  226. },
  227. {
  228. name="3",
  229. attach_offset={x=-4, y=8, z=-8},
  230. view_offset={x=0, y=0, z=0},
  231. group="pass",
  232. },
  233. {
  234. name="4",
  235. attach_offset={x=4, y=8, z=-8},
  236. view_offset={x=0, y=0, z=0},
  237. group="pass",
  238. },
  239. },
  240. seat_groups = {
  241. dstand={
  242. name = "Driver Stand",
  243. access_to = {"pass"},
  244. require_doors_open=true,
  245. driving_ctrl_access=true,
  246. },
  247. pass={
  248. name = "Passenger area",
  249. access_to = {"dstand"},
  250. require_doors_open=true,
  251. },
  252. },
  253. assign_to_seat_group = {"dstand", "pass"},
  254. doors={
  255. open={
  256. [-1]={frames={x=0, y=20}, time=1},
  257. [1]={frames={x=40, y=60}, time=1}
  258. },
  259. close={
  260. [-1]={frames={x=20, y=40}, time=1},
  261. [1]={frames={x=60, y=80}, time=1}
  262. }
  263. },
  264. door_entry={-1},
  265. assign_to_seat_group = {"dstand", "pass"},
  266. visual_size = {x=1, y=1},
  267. wagon_span=2.5,
  268. is_locomotive=true,
  269. collisionbox = {-1.0,-0.5,-2.0, 1.0,2.5,2.0},
  270. drops={"default:steelblock 4"},
  271. }, S("underground_s7dm"), "advtrains_london_s7dm_inv.png")
  272. advtrains.register_wagon("under_s7ndm", {
  273. mesh="advtrains_london_s7ndm.b3d",
  274. textures = {"advtrains_london_s7ndm.png"},
  275. base_texture = "advtrains_london_s7ndm.png",
  276. base_livery = "advtrains_london_s7ndm_livery.png",
  277. set_textures = set_textures,
  278. set_livery = set_livery,
  279. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  280. return not update_livery(wagon, puncher)
  281. end,
  282. drives_on={default=true},
  283. max_speed=20,
  284. seats = {
  285. {
  286. name="1",
  287. attach_offset={x=-4, y=8, z=8},
  288. view_offset={x=0, y=0, z=0},
  289. group="pass",
  290. },
  291. {
  292. name="2",
  293. attach_offset={x=4, y=8, z=8},
  294. view_offset={x=0, y=0, z=0},
  295. group="pass",
  296. },
  297. {
  298. name="1a",
  299. attach_offset={x=-4, y=8, z=0},
  300. view_offset={x=0, y=0, z=0},
  301. group="pass",
  302. },
  303. {
  304. name="2a",
  305. attach_offset={x=4, y=8, z=0},
  306. view_offset={x=0, y=0, z=0},
  307. group="pass",
  308. },
  309. {
  310. name="3",
  311. attach_offset={x=-4, y=8, z=-8},
  312. view_offset={x=0, y=0, z=0},
  313. group="pass",
  314. },
  315. {
  316. name="4",
  317. attach_offset={x=4, y=8, z=-8},
  318. view_offset={x=0, y=0, z=0},
  319. group="pass",
  320. },
  321. },
  322. seat_groups = {
  323. pass={
  324. name = "Passenger area",
  325. access_to = {},
  326. require_doors_open=true,
  327. },
  328. },
  329. assign_to_seat_group = {"pass"},
  330. doors={
  331. open={
  332. [-1]={frames={x=0, y=20}, time=1},
  333. [1]={frames={x=40, y=60}, time=1}
  334. },
  335. close={
  336. [-1]={frames={x=20, y=40}, time=1},
  337. [1]={frames={x=60, y=80}, time=1}
  338. }
  339. },
  340. door_entry={-1, 1},
  341. visual_size = {x=1, y=1},
  342. wagon_span=2.3,
  343. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  344. drops={"default:steelblock 4"},
  345. }, S("underground_s7ndm"), "advtrains_london_s7ndm_inv.png")