Skip to content

Commit

Permalink
add generated track modules / add metadata options / add adjustable p…
Browse files Browse the repository at this point in the history
…latform number mounting
  • Loading branch information
eisfeuer committed Jun 21, 2020
1 parent 22b3314 commit 01e57ca
Show file tree
Hide file tree
Showing 36 changed files with 998 additions and 205 deletions.
21 changes: 19 additions & 2 deletions mod/mod.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local TrackModuleUtils = require('motras_trackmoduleutils')

function data()
return {
info = {
Expand All @@ -20,8 +22,23 @@ function data()
-- values = { _("1"), _("2"), _("3"), _("4"), _("5"), _("6"), _("7"), _("8"), _("9"), _("10"), _("11"), _("12") },
-- defaultIndex = 0,
-- }
}
}
},
},
postRunFn = function(settings, params)
local tracks = api.res.trackTypeRep.getAll()

for sortIndex, trackFileName in ipairs(tracks) do
if trackFileName ~= "standard.lua" and trackFileName ~= "high_speed.lua" then
local track = api.res.trackTypeRep.get(api.res.trackTypeRep.find(trackFileName))

for __, hasCatenary in pairs({false, true}) do
local trackModule = api.type.ModuleDesc.new()
TrackModuleUtils.assignTrackToModule(trackModule, track, trackFileName, hasCatenary, sortIndex)
api.res.moduleRep.add(trackModule.fileName, trackModule, true)
end
end
end
end
}
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local TrackModuleUtils = require('motras_trackmoduleutils')

function data()
return {
updateFn = function(result, transform, tag, slotId, addModelFn, params, closureParams)
local track = result.motras:register(slotId)
track:handle(function (moduleResult)
local snapLeft = not track:getGrid():has(track:getGridX() - 1, track:getGridY())
local snapRight = not track:getGrid():has(track:getGridX() + 1, track:getGridY())
TrackModuleUtils.makeTrack(track, closureParams.trackType, closureParams.catenary, snapLeft, snapRight)
end)
end,
getModelsFn = function()
return { }
end
}
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ function data()
value = 29001,
},
metadata = {
motras = {
poleRadius = 0.05
}
},
updateFn = function(result, transform, tag, slotId, addModelFn, params)
local asset = result.motras:register(slotId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function data()
},
description = {
name = _("platform_number_sign_and_clock"),
description = _("truss_mountable") .. "\n" .. _("suitable_for_curved_roof"),
description = _("truss_mountable") .. "\n" .. _("suitable_for_curved_roof") .. "\n" .. _("manual_placement"),
icon = "ui/construction/station/rail/motras/decoration_platform_number_and_clock_truss_mounted_era_c.tga"
},
availability = {
Expand All @@ -143,6 +143,8 @@ function data()
local lableForBottomTrack = ''
local lableForTopTrack = ''

local variant = ((params.modules[slotId].variant or 0) % 4)

if decoration:getAssetId() == 34 or decoration:getAssetId() == 46 then
local bottomTrack = gridElement:getGrid():get(decoration:getGridX(), decoration:getGridY() - 2)
local topTrack = gridElement:getNeighborTop()
Expand All @@ -165,13 +167,12 @@ function data()
end
end

if decoration:getAssetId() == 46 then
if (decoration:getAssetId() == 46 and variant == 0) or variant == 1 then
addTopPlatformNumberAndClock(result, transform, lableForTopTrack, tag)
addBottomPlatformNumberAndClock(result, transform, lableForBottomTrack, tag)
end
if hasTrackTop and not hasTrackBottom then
elseif (hasTrackTop and not hasTrackBottom and variant == 0) or variant == 2 then
addTopPlatformNumberAndClock(result, transform, lableForTopTrack, tag)
elseif hasTrackBottom and not hasTrackTop then
elseif (hasTrackBottom and not hasTrackTop and variant == 0) or variant == 3 then
addBottomPlatformNumberAndClock(result, transform, lableForBottomTrack, tag)
else
addTopPlatformNumberAndClock(result, transform, lableForTopTrack, tag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function data()
},
description = {
name = _("platform_number_sign"),
description = _("truss_mountable"),
description = _("truss_mountable") .. "\n" .. _("manual_placement"),
icon = "ui/construction/station/rail/motras/decoration_platform_numbers_truss_mounted_2_era_c.tga"
},
availability = {
Expand All @@ -89,6 +89,8 @@ function data()
local lableForBottomTrack = ''
local lableForTopTrack = ''

local variant = ((params.modules[slotId].variant or 0) % 4)

if decoration:getAssetId() == 34 or decoration:getAssetId() == 46 then
local bottomTrack = gridElement:getGrid():get(decoration:getGridX(), decoration:getGridY() - 2)
local topTrack = gridElement:getNeighborTop()
Expand All @@ -114,13 +116,12 @@ function data()
local hasTrackTop = gridElement:getNeighborTop():isTrack()
local hasTrackBottom = gridElement:getNeighborBottom():isTrack()

if decoration:getAssetId() == 46 then
if (decoration:getAssetId() == 46 and variant == 0) or variant == 1 then
addTopPlatformNumber(result, transform, lableForTopTrack, tag)
addBottomPlatformNumber(result, transform, lableForBottomTrack, tag)
end
if hasTrackTop and not hasTrackBottom then
elseif (hasTrackTop and not hasTrackBottom and variant == 0) or variant == 2 then
addTopPlatformNumber(result, transform, lableForTopTrack, tag)
elseif hasTrackBottom and not hasTrackTop then
elseif (hasTrackBottom and not hasTrackTop and variant == 0) or variant == 3 then
addBottomPlatformNumber(result, transform, lableForBottomTrack, tag)
else
addTopPlatformNumber(result, transform, lableForTopTrack, tag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ function data()
},
metadata = {
platform_roof = true,
motras = {
poleRadius = 0.17
}
},
updateFn = function(result, transform, tag, slotId, addModelFn, params)
local asset = result.motras:register(slotId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ function data()
},
metadata = {
platform_roof = true,
motras = {
poleRadius = 0.17
}
},
updateFn = function(result, transform, tag, slotId, addModelFn, params)
local asset = result.motras:register(slotId, { groups = {'roof_ug_era_3_curved'}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ function data()
value = 3,
},
metadata = {
motras = {
electrified = false,
highspeed = true,
toggleElectrificationTo = "station/rail/modules/motras_track_train_high_speed_catenary.module",
toggleHighspeedTo = "station/rail/modules/motras_track_train_normal.module"
}
motras_electrified = false,
motras_highspeed = true,
motras_toggleElectrificationTo = "station/rail/modules/motras_track_train_high_speed_catenary.module",
motras_toggleHighspeedTo = "station/rail/modules/motras_track_train_normal.module",
motras_speedLimit = 300.0 / 3.6,
},
updateFn = function(result, transform, tag, slotId, addModelFn, params)
local track = result.motras:register(slotId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ function data()
value = 4,
},
metadata = {
motras = {
electrified = true,
highspeed = true,
toggleElectrificationTo = "station/rail/modules/motras_track_train_high_speed.module",
toggleHighspeedTo = "station/rail/modules/motras_track_train_normal_catenary.module"
}
motras_electrified = true,
motras_highspeed = true,
motras_toggleElectrificationTo = "station/rail/modules/motras_track_train_high_speed.module",
motras_toggleHighspeedTo = "station/rail/modules/motras_track_train_normal_catenary.module",
motras_speedLimit = 300.0 / 3.6,
},
updateFn = function(result, transform, tag, slotId, addModelFn, params)
local track = result.motras:register(slotId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ function data()
value = 1,
},
metadata = {
motras = {
electrified = false,
highspeed = false,
toggleElectrificationTo = "station/rail/modules/motras_track_train_normal_catenary.module",
toggleHighspeedTo = "station/rail/modules/motras_track_train_high_speed.module"
}
motras_electrified = false,
motras_highspeed = false,
motras_toggleElectrificationTo = "station/rail/modules/motras_track_train_normal_catenary.module",
motras_toggleHighspeedTo = "station/rail/modules/motras_track_train_high_speed.module",
motras_speedLimit = 120.0 / 3.6,
},
updateFn = function(result, transform, tag, slotId, addModelFn, params)
local track = result.motras:register(slotId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ function data()
value = 2,
},
metadata = {
motras = {
electrified = true,
highspeed = false,
toggleElectrificationTo = "station/rail/modules/motras_track_train_normal.module",
toggleHighspeedTo = "station/rail/modules/motras_track_train_high_speed_catenary.module"
}
motras_electrified = true,
motras_highspeed = false,
motras_toggleElectrificationTo = "station/rail/modules/motras_track_train_normal.module",
motras_toggleHighspeedTo = "station/rail/modules/motras_track_train_high_speed_catenary.module",
motras_speedLimit = 120.0 / 3.6,
},
updateFn = function(result, transform, tag, slotId, addModelFn, params)
local track = result.motras:register(slotId)
Expand Down
5 changes: 1 addition & 4 deletions mod/res/construction/station/rail/motras.con
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ function data()
values = { "0", "1" },
default_index = 0
}}
-- local commonApiTracks = ParamUtils.addCommonApiTrackParams(params)

return {
type = 'RAIL_STATION',
Expand Down Expand Up @@ -349,7 +348,7 @@ function data()
{
key = "motras_tracks",
name = _("Tracks"),
values = { _("1"), _("2"), _("3"), _("4"), _("5"), _("6"), _("7"), _("8"), _("9"), _("10"), _("11"), _("12") },
values = { _("1"), _("2"), _("3"), _("4"), _("5"), _("6"), _("7"), _("8"), _("9"), _("10"), _("11"), _("12"), _("13"), _("14"), _("15"), _("16"), _("17"), _("18") },
defaultIndex = 0,
},
UgParamUtils.makeTrackTypeParam(),
Expand Down Expand Up @@ -446,8 +445,6 @@ function data()
end,
updateFn = function(params)
local station = Station:new{
customTrack1 = params.motras_track_commonapi_1 and commonApiTracks[params.motras_track_commonapi_1 + 1],
customTrack2 = params.motras_track_commonapi_2 and commonApiTracks[params.motras_track_commonapi_2 + 1],
displayedNameMapper = params.motras_use_track_ids > 0 and TrackIdMapper:new{} or PlatformIdMapper:new{}
}
station:initializeAndRegisterAll(params.modules or {})
Expand Down
16 changes: 15 additions & 1 deletion mod/res/scripts/motras_asset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,27 @@ function Asset:call(result)
end

function Asset:setOptions(options)
self.options = options
for key, value in pairs(options) do
self:setOption(key, value)
end
end

function Asset:setOption(key, value)
if not self.options then
self.options = {}
end

self.options[key] = value
end

function Asset:getOption(option, default)
return self.options and self.options[option] or default
end

function Asset:getPoleRadius()
return self:getOption('poleRadius', 0)
end

function Asset:registerDecoration(assetDecorationId, assetDecorationSlot, options)
local decorationType = assetDecorationSlot.type

Expand Down
12 changes: 11 additions & 1 deletion mod/res/scripts/motras_asset_decoration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ function AssetDecoration:getParentGridElement()
end

function AssetDecoration:setOptions(options)
self.options = options
for key, value in pairs(options) do
self:setOption(key, value)
end
end

function AssetDecoration:setOption(key, value)
if not self.options then
self.options = {}
end

self.options[key] = value
end

function AssetDecoration:getOption(option, default)
Expand Down
2 changes: 1 addition & 1 deletion mod/res/scripts/motras_asset_decoration_slot_cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end
function AssetDecorationSlotCache:bindAssetDecorationSlotsToAsset(asset)
for assetDecorationType, assetDecorationSlotList in pairs(self:getAllAssetDecorationSlotsForAsset(asset)) do
for assetDecorationId, assetDecorationSlot in pairs(assetDecorationSlotList) do
asset:registerDecoration(assetDecorationId, assetDecorationSlot)
asset:registerDecoration(assetDecorationId, assetDecorationSlot, assetDecorationSlot:getOptions())
end
end
end
Expand Down
25 changes: 25 additions & 0 deletions mod/res/scripts/motras_asset_decoration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,31 @@ describe("AssetDecoration", function ()
end)
end)

describe('setOptions', function ()
it('set options', function ()
local testStation = Station:new{}
testStation:initializeAndRegister(Slot.makeId({type = t.PLATFORM, gridX = 0, gridY = 0}))
testStation:initializeAndRegister(Slot.makeId({type = t.ASSET, gridX = 0, gridY = 0, assetId = 2}))
local testDeco = testStation:initializeAndRegister(Slot.makeId({type = t.ASSET_DECORATION, gridX = 0, gridY = 0, assetId = 2, assetDecorationId = 2}))

testDeco:setOptions({opt1 = 'val1', opt2 = 'val2'})
assert.are.equal('val1', testDeco:getOption('opt1'))
assert.are.equal('val2', testDeco:getOption('opt2'))
end)

it('keeps old options', function ()
local testStation = Station:new{}
testStation:initializeAndRegister(Slot.makeId({type = t.PLATFORM, gridX = 0, gridY = 0}))
testStation:initializeAndRegister(Slot.makeId({type = t.ASSET, gridX = 0, gridY = 0, assetId = 2}))
local testDeco = testStation:initializeAndRegister(Slot.makeId({type = t.ASSET_DECORATION, gridX = 0, gridY = 0, assetId = 2, assetDecorationId = 2}))

testDeco:setOption('opt1', 'val1')
testDeco:setOptions({opt2 = 'val2'})
assert.are.equal('val1', testDeco:getOption('opt1'))
assert.are.equal('val2', testDeco:getOption('opt2'))
end)
end)

describe('handle / call', function ()
it ("does not change anything when handle function is not definded", function ()
local result = {
Expand Down
2 changes: 1 addition & 1 deletion mod/res/scripts/motras_asset_slot_cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end

function AssetSlotCache:bindAssetSlotsToGridElement(gridElement, assetDecorationSlotCache)
for i, assetSlot in ipairs(self:getAllAssetSlotsForGridElement(gridElement)) do
local asset = gridElement:registerAsset(assetSlot.assetId, assetSlot)
local asset = gridElement:registerAsset(assetSlot.assetId, assetSlot, assetSlot:getOptions())
if assetDecorationSlotCache then
assetDecorationSlotCache:bindAssetDecorationSlotsToAsset(asset)
end
Expand Down
31 changes: 30 additions & 1 deletion mod/res/scripts/motras_asset_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Asset', function ()
local station = Station:new{}
local platform = station:initializeAndRegister(Slot.makeId({type = t.PLATFORM, gridX = 2, gridY = 4}))
local assetSlot = Slot:new{id = Slot.makeId({type = t.ROOF, gridX = 2, gridY = 4, assetId = 1})}
local asset = Asset:new{slot = assetSlot, parent = platform, options = {height = 23}}
local asset = Asset:new{slot = assetSlot, parent = platform, options = {height = 23, poleRadius = 2}}
local decorationAssetSlot = Slot:new{id = Slot.makeId({type = t.ASSET_DECORATION, gridX = 2, gridY = 4, assetId = 1, assetDecorationId = 2 })}
local decoration = asset:registerDecoration(2, decorationAssetSlot, {anOption = 'value'})

Expand Down Expand Up @@ -83,6 +83,29 @@ describe('Asset', function ()
end)
end)

describe('setOptions', function ()
it('set options', function ()
local station = Station:new{}
station:initializeAndRegister(Slot.makeId({type = t.PLATFORM, gridX = 0, gridY = 0}))
local testAsset = station:initializeAndRegister(Slot.makeId({type = t.ASSET, gridX = 0, gridY = 0, assetId = 1}))

testAsset:setOptions({opt1 = 'val1', opt2 = 'val2'})
assert.are.equal('val1', testAsset:getOption('opt1'))
assert.are.equal('val2', testAsset:getOption('opt2'))
end)

it('keeps old options', function ()
local station = Station:new{}
station:initializeAndRegister(Slot.makeId({type = t.PLATFORM, gridX = 0, gridY = 0}))
local testAsset = station:initializeAndRegister(Slot.makeId({type = t.ASSET, gridX = 0, gridY = 0, assetId = 1}))

testAsset:setOption('opt1', 'val1')
testAsset:setOptions({opt2 = 'val2'})
assert.are.equal('val1', testAsset:getOption('opt1'))
assert.are.equal('val2', testAsset:getOption('opt2'))
end)
end)

describe('handle / call', function ()
it ("does not change anything when handle function is not definded", function ()
local result = {
Expand Down Expand Up @@ -222,4 +245,10 @@ describe('Asset', function ()
end)
end)

describe('getPoleRadius', function ()
it ('returns pole radius', function ()
assert.are.equal(2, asset:getPoleRadius())
end)
end)

end)
Loading

0 comments on commit 01e57ca

Please sign in to comment.