Skip to content

Commit 416cd8c

Browse files
committed
feat(HandlingEditor): add more stuff
- Add options to import/export handling presets. - Add preset list sort + search UI widgets.
1 parent f02fd70 commit 416cd8c

23 files changed

Lines changed: 573 additions & 164 deletions

File tree

SSV2/includes/data/handling_presets.lua

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,51 @@ local BIKES_BIT <const> = Enums.eVehicleType.VEHICLE_TYPE_BIKE
2121
---@type array<HandlingPresetData>
2222
return {
2323
{
24-
name = "VEH_NO_ENGINE_BRAKE",
25-
description = "VEH_NO_ENGINE_BRAKE_TT",
26-
is_translator_name = true,
27-
auto_apply = true,
28-
deltas = { [Enums.eHandlingEditorTypes.TYPE_HF] = { ["FREEWHEEL_NO_GAS"] = true } },
29-
allowed_vehicle_types = 1 << CARS_BIT | 1 << BIKES_BIT,
24+
name = "VEH_NO_ENGINE_BRAKE",
25+
description = "VEH_NO_ENGINE_BRAKE_TT",
26+
is_translator_name = true,
27+
auto_apply = true,
28+
deltas = { [Enums.eHandlingEditorTypes.TYPE_HF] = { ["FREEWHEEL_NO_GAS"] = true } },
29+
vehicle_bitset = 1 << CARS_BIT | 1 << BIKES_BIT,
3030
},
3131
{
32-
name = "VEH_WHEELIE",
33-
description = "VEH_WHEELIE_TT",
34-
is_translator_name = true,
35-
auto_apply = false,
36-
deltas = { [Enums.eHandlingEditorTypes.TYPE_AF] = { ["CAN_WHEELIE"] = true } },
37-
allowed_vehicle_types = 1 << CARS_BIT,
32+
name = "VEH_WHEELIE",
33+
description = "VEH_WHEELIE_TT",
34+
is_translator_name = true,
35+
auto_apply = false,
36+
deltas = { [Enums.eHandlingEditorTypes.TYPE_AF] = { ["CAN_WHEELIE"] = true } },
37+
vehicle_bitset = 1 << CARS_BIT,
3838
},
3939
{
40-
name = "VEH_KERS_BOOST",
41-
description = "VEH_KERS_BOOST_TT",
42-
is_translator_name = true,
43-
auto_apply = false,
44-
deltas = { [Enums.eHandlingEditorTypes.TYPE_HF] = { ["HAS_KERS"] = true } },
45-
allowed_vehicle_types = 1 << CARS_BIT
40+
name = "VEH_KERS_BOOST",
41+
description = "VEH_KERS_BOOST_TT",
42+
is_translator_name = true,
43+
auto_apply = false,
44+
deltas = { [Enums.eHandlingEditorTypes.TYPE_HF] = { ["HAS_KERS"] = true } },
45+
vehicle_bitset = 1 << CARS_BIT
4646
},
4747
{
48-
name = "VEH_ROCKET_BOOST",
49-
description = "VEH_ROCKET_BOOST_TT",
50-
is_translator_name = true,
51-
auto_apply = false,
52-
deltas = { [Enums.eHandlingEditorTypes.TYPE_MIF] = { ["HAS_ROCKET_BOOST"] = true } },
53-
allowed_vehicle_types = 1 << CARS_BIT | 1 << BIKES_BIT
48+
name = "VEH_ROCKET_BOOST",
49+
description = "VEH_ROCKET_BOOST_TT",
50+
is_translator_name = true,
51+
auto_apply = false,
52+
deltas = { [Enums.eHandlingEditorTypes.TYPE_MIF] = { ["HAS_ROCKET_BOOST"] = true } },
53+
vehicle_bitset = 1 << CARS_BIT | 1 << BIKES_BIT
5454
},
5555
{
56-
name = "VEH_JUMP",
57-
description = "VEH_JUMP_TT",
58-
is_translator_name = true,
59-
auto_apply = false,
60-
deltas = { [Enums.eHandlingEditorTypes.TYPE_MIF] = { ["JUMPING_CAR"] = true, ["HAS_PARACHUTE"] = true, } },
61-
allowed_vehicle_types = 1 << CARS_BIT
56+
name = "VEH_JUMP",
57+
description = "VEH_JUMP_TT",
58+
is_translator_name = true,
59+
auto_apply = false,
60+
deltas = { [Enums.eHandlingEditorTypes.TYPE_MIF] = { ["JUMPING_CAR"] = true, ["HAS_PARACHUTE"] = true, } },
61+
vehicle_bitset = 1 << CARS_BIT
6262
},
6363
{
64-
name = "VEH_OFFROAD_ABILITIES",
65-
description = "VEH_OFFROAD_ABILITIES_TT",
66-
is_translator_name = true,
67-
auto_apply = false,
68-
deltas = {
64+
name = "VEH_OFFROAD_ABILITIES",
65+
description = "VEH_OFFROAD_ABILITIES_TT",
66+
is_translator_name = true,
67+
auto_apply = false,
68+
deltas = {
6969
[Enums.eHandlingEditorTypes.TYPE_HF] = {
7070
["OFFROAD_ABILITIES"] = true,
7171
["OFFROAD_ABILITIES_X2"] = true,
@@ -83,14 +83,14 @@ return {
8383
},
8484
[Enums.eHandlingEditorTypes.TYPE_MIF] = { ["INCREASE_LOW_SPEED_TORQUE"] = true, },
8585
},
86-
allowed_vehicle_types = 1 << CARS_BIT
86+
vehicle_bitset = 1 << CARS_BIT
8787
},
8888
{
89-
name = "VEH_FORCE_NO_TC",
90-
description = "VEH_FORCE_NO_TC_TT",
91-
is_translator_name = true,
92-
auto_apply = false,
93-
deltas = {
89+
name = "VEH_FORCE_NO_TC",
90+
description = "VEH_FORCE_NO_TC_TT",
91+
is_translator_name = true,
92+
auto_apply = false,
93+
deltas = {
9494
[Enums.eHandlingEditorTypes.TYPE_HF] = { ["FORCE_NO_TC_OR_SC"] = true },
9595
[Enums.eHandlingEditorTypes.TYPE_AF] = {
9696
["HOLD_GEAR_WITH_WHEELSPIN"] = true,
@@ -104,23 +104,23 @@ return {
104104
["DONT_HOLD_LOW_GEARS_WHEN_ENGINE_UNDER_LOAD"] = false,
105105
},
106106
},
107-
allowed_vehicle_types = 1 << CARS_BIT | 1 << BIKES_BIT
107+
vehicle_bitset = 1 << CARS_BIT | 1 << BIKES_BIT
108108
},
109109
{
110-
name = "VEH_LOW_SPEED_WHEELIE",
111-
description = "VEH_LOW_SPEED_WHEELIE_TT",
112-
is_translator_name = true,
113-
auto_apply = false,
114-
deltas = {
110+
name = "VEH_LOW_SPEED_WHEELIE",
111+
description = "VEH_LOW_SPEED_WHEELIE_TT",
112+
is_translator_name = true,
113+
auto_apply = false,
114+
deltas = {
115115
[Enums.eHandlingEditorTypes.TYPE_HF] = { ["LOW_SPEED_WHEELIES"] = true } },
116-
allowed_vehicle_types = 1 << BIKES_BIT
116+
vehicle_bitset = 1 << BIKES_BIT
117117
},
118118
{
119-
name = "VEH_RAMP",
120-
description = "VEH_RAMP_TT",
121-
is_translator_name = true,
122-
auto_apply = false,
123-
deltas = {
119+
name = "VEH_RAMP",
120+
description = "VEH_RAMP_TT",
121+
is_translator_name = true,
122+
auto_apply = false,
123+
deltas = {
124124
[Enums.eHandlingEditorTypes.TYPE_MIF] = {
125125
["CRUSHES_OTHER_VEHICLES"] = true,
126126
["HAS_INCREASED_RAMMING_FORCE"] = true,
@@ -131,6 +131,6 @@ return {
131131
["RAMP_MOD"] = true,
132132
},
133133
},
134-
allowed_vehicle_types = 1 << CARS_BIT
134+
vehicle_bitset = 1 << CARS_BIT
135135
},
136136
}

SSV2/includes/features/extra/entity_forge/EntityForge.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,9 +1453,9 @@ function EntityForge:ImportCreation(data)
14531453
return
14541454
end
14551455

1456-
---@type ForgeEntityPlainTable
1457-
local abomination = Serializer:Decode(Serializer:XOR(Serializer:B64Decode(data)))
1458-
if (type(abomination) ~= "table") then
1456+
---@type boolean, ForgeEntityPlainTable?
1457+
local ok, res = Serializer:Decode(Serializer:XOR(Serializer:B64Decode(data)))
1458+
if (not ok) then
14591459
Notifier:ShowError(
14601460
"EntityForge",
14611461
"Import Error: Incorrect data type!",
@@ -1465,7 +1465,7 @@ function EntityForge:ImportCreation(data)
14651465
return
14661466
end
14671467

1468-
return abomination
1468+
return res
14691469
end
14701470

14711471
return EntityForge:init()

SSV2/includes/features/vehicle/stancer.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,19 @@ function Stancer:CanApplyDrawData()
201201
return self.m_entity:HasWheelDrawData() and wheel_idx ~= -1
202202
end
203203

204-
function Stancer:ResetDeltas()
204+
---@param deleteQueue? boolean
205+
function Stancer:ResetDeltas(deleteQueue)
205206
for _, v in ipairs(StancerData.decorators) do
206207
self.m_deltas[Enums.eWheelAxle.FRONT][v.key] = 0.0
207208
self.m_deltas[Enums.eWheelAxle.REAR][v.key] = 0.0
208209
end
209210

210211
self.m_suspension_height.m_current = 0.0
211212
self.m_suspension_height.m_last_seen = 0.0
213+
214+
if (deleteQueue) then
215+
self:RemoveReference()
216+
end
212217
end
213218

214219
function Stancer:Reset()
@@ -248,14 +253,15 @@ function Stancer:Reset()
248253
end
249254
end
250255

251-
---@param handle handle
256+
---@param handle? handle
252257
function Stancer:RemoveReference(handle)
258+
handle = handle or self.m_entity:GetHandle()
253259
Decorator:RemoveEntity(handle)
254260
end
255261

256262
function Stancer:Cleanup()
257263
self:Reset()
258-
self:RemoveReference(self.m_entity:GetHandle())
264+
self:RemoveReference()
259265
self.m_cached_model_hash = nil
260266
self.m_cached_model_name = nil
261267
end
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
-- Copyright (C) 2026 SAMURAI (xesdoog) & Contributors.
2+
-- This file is part of Samurai's Scripts.
3+
--
4+
-- Permission is hereby granted to copy, modify, and redistribute
5+
-- this code as long as you respect these conditions:
6+
-- * Credit the owner and contributors.
7+
-- * Provide a copy of or a link to the original license (GPL-3.0 or later); see LICENSE.md or <https://www.gnu.org/licenses/>.
8+
9+
10+
local RED <const> = Color.RED
11+
local PURPLE <const> = Color("purple")
12+
local ORANGE <const> = Color("orange")
13+
local REF_COUNT = 0
14+
15+
local TokenTypes <const> = {
16+
["boolean"] = "boolean",
17+
["nil"] = "nil",
18+
["number"] = "number",
19+
["string"] = "string",
20+
["table"] = "table",
21+
default = "unk"
22+
}
23+
24+
local TokenColors <const> = {
25+
["boolean"] = Color.BLUE,
26+
["nil"] = PURPLE,
27+
["number"] = Color("yellow"):Brighten(0.4),
28+
["string"] = ORANGE,
29+
default = PURPLE
30+
}
31+
32+
---@class TableRendererToken
33+
---@field m_type "number"|"string"|"boolean"|"table"|"unk"
34+
---@field m_color Color
35+
local TableRendererToken <const> = {}
36+
TableRendererToken.__index = TableRendererToken
37+
38+
function TableRendererToken.new(value)
39+
local _type = type(value)
40+
return setmetatable({
41+
m_type = Match(_type, TokenTypes),
42+
m_color = Match(_type, TokenColors)
43+
}, TableRendererToken)
44+
end
45+
46+
---@class TableRenderer
47+
---@field private m_uid joaat_t
48+
local TableRenderer <const> = {}
49+
TableRenderer.__index = TableRenderer
50+
51+
---@return TableRenderer
52+
function TableRenderer.new()
53+
REF_COUNT = REF_COUNT + 1
54+
local uid = joaat("TABLE_RENDERER_" .. REF_COUNT)
55+
return setmetatable({ m_uid = uid }, TableRenderer)
56+
end
57+
58+
---@private
59+
---@param value anyval
60+
---@param isKey boolean
61+
function TableRenderer:DrawObject(value, isKey)
62+
local token = TableRendererToken.new(value)
63+
local txtCol = token.m_color
64+
local v = type(value) == "string" and _F('"%s"', value) or tostring(value)
65+
if (not isKey) then
66+
ImGui.TextColored(txtCol.r, txtCol.g, txtCol.b, txtCol.a, v)
67+
return
68+
end
69+
70+
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, 0, 0)
71+
ImGui.TextColored(PURPLE.r, PURPLE.g, PURPLE.b, PURPLE.a, "[")
72+
ImGui.SameLine()
73+
ImGui.TextColored(txtCol.r, txtCol.g, txtCol.b, txtCol.a, v)
74+
ImGui.SameLine()
75+
ImGui.TextColored(PURPLE.r, PURPLE.g, PURPLE.b, PURPLE.a, "]")
76+
ImGui.PopStyleVar()
77+
end
78+
79+
---@param value any
80+
---@param depth integer
81+
---@param seen? set<table>
82+
function TableRenderer:DrawValue(value, depth, seen)
83+
seen = seen or {}
84+
local valueType = type(value)
85+
86+
if (valueType ~= "table") then
87+
self:DrawObject(value, false)
88+
return
89+
end
90+
91+
if (seen[value]) then
92+
ImGui.TextColored(RED.r, RED.g, RED.b, RED.a, "<circular_reference>")
93+
return
94+
end
95+
96+
seen[value] = true
97+
98+
ImGui.Text("{")
99+
ImGui.Indent()
100+
101+
for k, v in pairs(value) do
102+
self:DrawObject(k, true)
103+
ImGui.SameLine()
104+
ImGui.Text("=")
105+
ImGui.SameLine()
106+
self:DrawValue(v, depth + 1, seen)
107+
end
108+
109+
ImGui.Unindent()
110+
ImGui.Text("}")
111+
end
112+
113+
---@param data table
114+
---@param size vec2
115+
function TableRenderer:Draw(data, size)
116+
ImGui.PushStyleColor(ImGuiCol.ChildBg, 0.01, 0.0, 0.0, 1.0)
117+
ImGui.PushStyleVar(ImGuiStyleVar.ScrollbarSize, 11.3)
118+
ImGui.PushID(self.m_uid)
119+
ImGui.BeginChildEx("##tableRenderer", size, ImGuiChildFlags.Borders)
120+
self:DrawValue(data, 0, {})
121+
ImGui.EndChild()
122+
ImGui.PopStyleColor()
123+
ImGui.PopStyleVar()
124+
ImGui.PopID()
125+
end
126+
127+
return TableRenderer

0 commit comments

Comments
 (0)