From 806f78e3dbd8fd6daf1eec84c814f23039583010 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 8 Jun 2024 22:41:23 -0700 Subject: [PATCH] adapt to canonicalized structures --- gui/advfort.lua | 12 ++++++------ internal/quickfort/build.lua | 8 ++++---- trackstop.lua | 11 ++--------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/gui/advfort.lua b/gui/advfort.lua index 864bcd8a1b..7f17afb8fe 100644 --- a/gui/advfort.lua +++ b/gui/advfort.lua @@ -1420,20 +1420,20 @@ function track_stop_configure(bld) --TODO: dedicated widget with nice interface local choices={"Friction","Dumping"} local function chosen(index,choice) if choice.text=="Friction" then - dialog.showInputPrompt("Choose friction","Friction",nil,tostring(bld.friction),function ( txt ) + dialog.showInputPrompt("Choose friction","Friction",nil,tostring(bld.track_stop_info.friction),function ( txt ) local num=tonumber(txt) --TODO allow only vanilla friction settings if num then - bld.friction=num + bld.track_stop_info.friction=num end end) else dialog.showListPrompt("Dumping direction", "Choose dumping:",COLOR_WHITE,dump_choices,function ( index,choice) if choice.x then - bld.track_flags.use_dump=true - bld.dump_x_shift=choice.x - bld.dump_y_shift=choice.y + bld.track_stop_info.track_flags.use_dump=true + bld.track_stop_info.dump_x_shift=choice.x + bld.track_stop_info.dump_y_shift=choice.y else - bld.track_flags.use_dump=false + bld.track_stop_info.track_flags.use_dump=false end end) end diff --git a/internal/quickfort/build.lua b/internal/quickfort/build.lua index cdc60738ab..96e1313a23 100644 --- a/internal/quickfort/build.lua +++ b/internal/quickfort/build.lua @@ -346,7 +346,7 @@ local function do_trackstop_props(db_entry, props) (props.friction == '50000' or props.friction == '10000' or props.friction == '500' or props.friction == '50' or props.friction == '10') then - db_entry.props.friction = tonumber(props.friction) + ensure_key(db_entry.props, 'track_stop_info').friction = tonumber(props.friction) props.friction = nil end if props.take_from then @@ -632,13 +632,13 @@ local function make_transform_trackstop_fn(vector, friction) return make_transform_building_fn(vector, trackstop_revmap, post_fn) end local function make_trackstop_entry(direction, friction) - local label, fields, transform = 'No Dump', {friction=friction}, nil + local label, fields, transform = 'No Dump', {track_stop_info={friction=friction}}, nil if direction then - ensure_key(fields, 'track_flags').use_dump = true + ensure_key(fields.track_stop_info, 'track_flags').use_dump = true for k,v in pairs(direction) do local trackstop_data_entry = trackstop_data[k][v] label = trackstop_data_entry.label - fields[k] = v + fields.track_stop_info[k] = v transform = make_transform_trackstop_fn( trackstop_data_entry.vector, friction) end diff --git a/trackstop.lua b/trackstop.lua index c1ae132a36..c5607a57cb 100644 --- a/trackstop.lua +++ b/trackstop.lua @@ -63,14 +63,8 @@ TrackStopOverlay.ATTRS{ frame_background=gui.CLEAR_PEN, } -function TrackStopOverlay:getFriction() - return dfhack.gui.getSelectedBuilding().friction -end - function TrackStopOverlay:setFriction(friction) - local building = dfhack.gui.getSelectedBuilding() - - building.friction = FRICTION_MAP[friction] + dfhack.gui.getSelectedBuilding().track_stop_info.friction = FRICTION_MAP[friction] end function TrackStopOverlay:getDumpDirection() @@ -121,9 +115,8 @@ function TrackStopOverlay:setDumpDirection(direction) end function TrackStopOverlay:render(dc) - local building = dfhack.gui.getSelectedBuilding() - local friction = building.friction local friction_cycle = self.subviews.friction + local friction = dfhack.gui.getSelectedBuilding().track_stop_info.friction friction_cycle:setOption(FRICTION_MAP_REVERSE[friction])