-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extended Vehicle Customization #387
base: master
Are you sure you want to change the base?
Changes from all commits
896a469
3edf0f7
07cf73d
7dfdb96
7be56dd
0dc5c1f
ea29cb3
e78a3de
ba3d0a3
7e7cc65
b35d0e1
3c398b0
724e143
f2bae4e
23bc0cf
474ecfd
216044c
c2dc516
2ee77ac
ef5bf7e
0caa83e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: Kex | ||
* Changes the textures, animation sources and/or mass of a given vehicle. | ||
* Based on BIS_fnc_initVehicle, but can be applied multiple times without issues. | ||
* In contrast to BIS_fnc_initVehicle, if texture is passed as an array, | ||
* it can also alternatively be an array of texture paths (i.e. output of getObjectTextures). | ||
* | ||
* Arguments: | ||
* 0: Vehicle <OBJECT> | ||
* 1: Texture <BOOLEAN|ARRAY|STRING> | ||
* 2: Animation <BOOLEAN|ARRAY|STRING> | ||
* 3: Mass <BOOLEAN|NUMBER> | ||
* 4: Instant animation <BOOLEAN> | ||
* | ||
* Return Value: | ||
* None | ||
* | ||
* Example: | ||
* [vehicle player, [texturePath1, texturePath2], [animationSource1, animationPhase1]] call zen_common_fnc_customizeVehicle | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_vehicle", ["_texture", false, [false, [], ""]], ["_animation", false, [false, [], ""]], ["_mass", false, [false, 0]], ["_instantAnimation", true, [false]]]; | ||
|
||
private _vehicleType = typeOf _vehicle; | ||
|
||
// Fix: BIS_fnc_initVehicle cannot animate doors multiple times | ||
if (_animation isEqualType []) then { | ||
for "_i" from 0 to (count _animation - 2) step 2 do { | ||
private _configName = _animation select _i; | ||
private _source = getText (configFile >> "CfgVehicles" >> _vehicleType >> "animationSources" >> _configName >> "source"); | ||
private _phase = _animation select (_i + 1); | ||
switch (_source) do { | ||
case "door": { | ||
_vehicle animateDoor [_configName, _phase, _instantAnimation]; | ||
}; | ||
case "user": { | ||
_vehicle animateSource [_configName, _phase, _instantAnimation]; | ||
}; | ||
default { | ||
_vehicle animate [_configName, _phase, _instantAnimation]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
if (_texture isEqualType [] && {count _texture < 2 || {(_texture select 1) isEqualType ""}}) then { | ||
[_vehicle, nil, nil, _mass] call BIS_fnc_initVehicle; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requires targetEvent #558 |
||
{ | ||
_vehicle setObjectTextureGlobal [_forEachIndex, _x]; | ||
} forEach _texture; | ||
} else { | ||
[_vehicle, _texture, nil, _mass] call BIS_fnc_initVehicle; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment above |
||
}; | ||
|
||
nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary when function has return value of "None". |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: Kex | ||
* Return vehicle customization settings. | ||
* Based on BIS_fnc_getVehicleCustomization. | ||
* In contrast to BIS_fnc_getVehicleCustomization, it works properly for doors | ||
* and textures are returned as an array of texture paths (i.e. output of getObjectTextures). | ||
* | ||
* Arguments: | ||
* 0: Vehicle <OBJECT> | ||
* | ||
* Return Value: | ||
* Array of texture paths and array of animations <ARRAY> | ||
* | ||
* Example: | ||
* [vehicle player] call zen_common_fnc_getVehicleCustomization | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_vehicle"]; | ||
|
||
private _vehicleType = typeOf _vehicle; | ||
private _vehicleConfig = configFile >> "CfgVehicles" >> _vehicleType; | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can use |
||
|
||
private _animations = []; | ||
{ | ||
private _config = _x; | ||
private _configName = toLower configName _config; | ||
private _source = toLower getText (_config >> "source"); | ||
|
||
if (_source in WHITELIST_ANIMATION_SOURCES && {BLACKLIST_ANIMATION_INNAMES findIf {_x in _configName} == -1 && {BLACKLIST_ANIMATION_ATTRIBUTES findIf {isClass (_config >> _x)} == -1}}) then { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multi-line: if (
_source in // ...
&& {}
&& {}
) then { |
||
private _phase = switch (_source) do { | ||
case "door": { | ||
_vehicle doorPhase _configName; | ||
}; | ||
case "user": { | ||
_vehicle animationSourcePhase _configName; | ||
}; | ||
default { | ||
_vehicle animationPhase _configName; | ||
}; | ||
}; | ||
// Some sources will return negative values | ||
if (_phase >= 0) then { | ||
_animations append [_configName, _phase]; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing semicolon. |
||
}; | ||
} forEach configProperties [_vehicleConfig >> "animationSources", "isClass _x", true]; | ||
|
||
private _textures = getObjectTextures _vehicle; | ||
|
||
[_textures, _animations] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: Kex | ||
* Defines custom texture variant for all vehicles that inherit from the given vehicle type. | ||
* | ||
* Arguments: | ||
* 0: Base vehicle type <STRING> | ||
* 1: Texture variant name <STRING> | ||
* 2: Path of texture for each hidden selection <ARRAY> | ||
* | ||
* Return Value: | ||
* None | ||
* | ||
* Example: | ||
* [vehicleType, variantName, [texturePath1, texturePath2]] call zen_garage_fnc_defineCustomTexture | ||
* | ||
* Public: Yes | ||
*/ | ||
|
||
params ["_baseVehicleType", "_variantName", "_texture"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this function is public, should do type checking in |
||
|
||
if (isNil QGVAR(customVehicleTextures)) then { | ||
GVAR(customVehicleTextures) = [] call CBA_fnc_createNamespace; | ||
}; | ||
|
||
{ | ||
private _vehicleType = configName _x; | ||
// Clear garage cache | ||
GVAR(vehicleDataCache) setVariable [_vehicleType, nil]; | ||
|
||
if (isNil {GVAR(customVehicleTextures) getVariable _vehicleType}) then { | ||
GVAR(customVehicleTextures) setVariable [_vehicleType, []]; | ||
}; | ||
private _textures = GVAR(customVehicleTextures) getVariable _vehicleType; | ||
_textures pushBack [_texture, _variantName]; | ||
} forEach (format ["configName _x isKindOf '%1'", _baseVehicleType] configClasses (configFile >> "CfgVehicles")); | ||
|
||
nil |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,29 +25,34 @@ private _vehicleType = typeOf _vehicle; | |
private _vehicleData = GVAR(vehicleDataCache) getVariable _vehicleType; | ||
|
||
if (isNil "_vehicleData") then { | ||
_vehicleData = []; | ||
|
||
private _vehicleConfig = configFile >> "CfgVehicles" >> _vehicleType; | ||
private _vehicleFaction = faction _vehicle; | ||
|
||
private _animations = []; | ||
([_vehicle] call EFUNC(common,getVehicleCustomization)) params ["", "_currentAnimations"]; | ||
for "_i" from 0 to (count _currentAnimations - 2) step 2 do { | ||
private _configName = _currentAnimations select _i; | ||
private _displayName = getText (_vehicleConfig >> "animationSources" >> _configName >> "displayName"); | ||
if (_displayName isEqualTo "") then { | ||
_displayName = (_configName splitString "_") joinString " "; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary parentheses. |
||
}; | ||
_animations pushBack [_configName, _displayName]; | ||
}; | ||
|
||
private _textures = []; | ||
{ | ||
private _entries = []; | ||
|
||
{ | ||
private _displayName = getText (_x >> "displayName"); | ||
private _factions = getArray (_x >> "factions"); | ||
|
||
if ( | ||
_displayName != "" | ||
&& {getNumber (_x >> "scope") == 2 || {!isNumber (_x >> "scope")}} | ||
&& {_factions isEqualTo [] || {_factions findIf {_x == _vehicleFaction} > -1}} | ||
) then { | ||
_entries pushBack [configName _x, _displayName]; | ||
}; | ||
} forEach configProperties [_x, "isClass _x", true]; | ||
|
||
_vehicleData pushBack _entries; | ||
} forEach [_vehicleConfig >> "animationSources", _vehicleConfig >> "textureSources"]; | ||
private _configName = configName _x; | ||
private _displayName = getText (_x >> "displayName"); | ||
if (_displayName isEqualTo "") then { | ||
_displayName = (_configName splitString "_") joinString " "; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary parentheses. |
||
}; | ||
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would prefer a blank lines before and after the |
||
_textures pushBack [_configName, _displayName]; | ||
} forEach configProperties [_vehicleConfig >> "textureSources", "isClass _x", true]; | ||
|
||
// Adding custom definitions | ||
private _customTextures = GVAR(customVehicleTextures) getVariable [_vehicleType, []]; | ||
_textures append _customTextures; | ||
|
||
_vehicleData = [_animations, _textures]; | ||
|
||
GVAR(vehicleDataCache) setVariable [_vehicleType, _vehicleData]; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
configOf