Extract a BuildingTask base from ConstructionTask and DeconstructionTask #126
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
ConstructionTaskandDeconstructionTaskare about 70% the same code. Pull the shared part into an abstractBuildingTaskbefore #73 adds a third task type that targets a building.The duplication
In
entities/tasks/construction_task.gdandentities/tasks/deconstruction_task.gd:building_id: int = -1._can_start,_workandon_completeeach open with the samectx == null or ctx.buildings == nullguard, then fetch the building and check it isn't null. That is six copies of the same lookup between the two classes._workcomputes progress the same way in both:1.0 if total <= 0.0 else 1.0 - work_remaining / total, thenset_build_progress(). Only the source oftotaldiffers (build_work_ticks()againstdeconstruct_work_ticks()).Knock-on duplication in
entities/buildings/buildings.gd:place()(lines 91-97) andmark_for_demolition()(lines 276-283) set up a task the same way:building_id,target_cell = building.entrance,work_remaining,label._task_for()(lines 449-461) needs a two-branchmatch var c when c is …only because the two classes have no common parent.Proposed shape
Once that exists:
_task_for()becomes a singleif task is BuildingTask and task.building_id == building_id.Buildingscan become a factory or an_init(building). Whether that is worth doing is a call to make during implementation.Decisions for Liam
DeconstructionTaskwrites demolition progress intobuild_progress, which is a known gap from PR #122. The refactor is the natural place to decide between:demolish_progressfield;build_progresscounting down;on_cancel.DeconstructionTask.on_cancel()ispass, so any cancel route other thanunmark_for_demolition()leaves a building marked with no task behind it (another known gap from #122). Clearingmarked_for_demolitionthere would make it hold whichever route cancels the task, #85 included._task_blocked/_task_unblockedinBuildingsshould widen toBuildingTask. Today only construction can be blocked in a way the view shows.Acceptance criteria
BuildingTaskexists, and both task types extend itctx/building guardBuildings._task_for()has no per-type branchestest_construction_task.gdandtest_deconstruction_task.gdpass unchanged, apart from whatever decisions 1 and 2 changeDeconstructionTaskthroughTaskManager.cancel()clears the markRelated: #72, #73, #85. The bugs and cleanup from the same review are #124 and #125.