18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-19 08:46:00 +01:00
Files
maszyna/vehicle/gaugeduplicates.h
jerrrrycho d259251373 feat: cab controls can animate duplicate submodels (eu07/maszyna#527)
A control defined again in the same cab section of the .mmd with the
block key "duplicate: yes" no longer replaces the control: the first
definition stays the control (sounds, type, command feedback), and the
duplicate adds a copy with its own submodel, animation type and scale /
offset, following the control's value and active state. The duplicate's
sound keys are ignored so the control is not heard twice, and clicking
any copy works the control. This lets e.g. the ASF cab move its second
master controller and reverser with the first ones.

Without the key a repeated definition still replaces the earlier one,
as some of the game's .mmd files repeat controls with other submodels.
A duplicate with no definition of the control loaded from the current
cab's models before it is just the control.

clear_cab_controls() now also clears ggCompressorListButton, which kept
the previous cab's submodel.

The rule is in vehicle/gaugeduplicates.h, covered by
tests/unit/test_gauge_duplicates.cpp.

(eu07/maszyna#527)
2026-11-07 23:19:53 +01:00

31 lines
1.2 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <string_view>
// cab controls with more than one submodel (eu07/maszyna#527): a definition of a control in the .mmd marked
// "duplicate: yes" adds a copy of the control already defined in the cab, instead of replacing it
namespace gauge_duplicates {
// whether the value of the duplicate: key marks the definition as a duplicate
inline bool is_duplicate(std::string_view const Value) {
return Value == "yes" || Value == "true" || Value == "1";
}
// whether a definition adds a copy to the control rather than replacing it: it is marked as a duplicate, and the
// control is already loaded from one of the 3d models of the cab being loaded (Cab, Lowpoly). a control left over
// from another cab, or not loaded at all (Loadedfrom null), has nothing in this cab to add the copy to
template <typename Model_> bool adds_copy(bool const Duplicate, Model_ const *Loadedfrom, Model_ const *Cab, Model_ const *Lowpoly) {
return Duplicate && Loadedfrom != nullptr && (Loadedfrom == Cab || Loadedfrom == Lowpoly);
}
} // namespace gauge_duplicates