-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-add utils, changed modules , changed factory , added tuning vehicle …
…methods
- Loading branch information
1 parent
0b26d95
commit 3bc6e6f
Showing
8 changed files
with
164 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,75 @@ | ||
using AltV.Net; | ||
using System.Drawing; | ||
using AltV.Atlas.Vehicles.Enums; | ||
using AltV.Atlas.Vehicles.Models; | ||
using AltV.Atlas.Vehicles.Utils; | ||
using AltV.Net; | ||
using AltV.Net.Data; | ||
using AltV.Net.Enums; | ||
namespace AltV.Atlas.Vehicles.Factories.Entities; | ||
|
||
public class AtlasTuningVehicle : AtlasVehicle | ||
{ | ||
public List<VehicleMod> InstalledMods { get; } = new( ); | ||
public EColorMaterial PrimaryColorMaterial { get; private set; } = EColorMaterial.DefaultAlloy; | ||
public EColorMaterial SecondaryColorMaterial { get; private set; } = EColorMaterial.DefaultAlloy; | ||
|
||
public AtlasTuningVehicle( ICore core, IntPtr nativePointer, uint id ) : base( core, nativePointer, id ) | ||
{ | ||
} | ||
public AtlasTuningVehicle( uint vehicleId, ICore core, IntPtr nativePointer, uint id ) : base( vehicleId, core, nativePointer, id ) | ||
|
||
public void SetPrimaryMaterial( EColorMaterial material ) | ||
{ | ||
var oldColor = PrimaryColorRgb; | ||
PrimaryColor = ( byte ) material; | ||
PrimaryColorRgb = oldColor; | ||
} | ||
|
||
public void SetSecondaryMaterial( EColorMaterial material ) | ||
{ | ||
var oldColor = PrimaryColorRgb; | ||
PrimaryColor = ( byte ) material; | ||
PrimaryColorRgb = oldColor; | ||
} | ||
|
||
public void SetPrimaryRgb( string rgb ) | ||
{ | ||
if( !rgb.TryParseRgb( out var color ) ) | ||
return; | ||
|
||
PrimaryColorRgb = new Rgba( color.R, color.G, color.B, color.A ); | ||
} | ||
|
||
public void SetSecondaryRgb( string rgb ) | ||
{ | ||
if( !rgb.TryParseRgb( out var color ) ) | ||
return; | ||
|
||
SecondaryColorRgb = new Rgba( color.R, color.G, color.B, color.A ); | ||
} | ||
|
||
public bool InstallMod( VehicleMod vehicleMod, bool force = false ) | ||
{ | ||
var maxIndex = GetModsCount( ( byte ) vehicleMod.ModType ); | ||
|
||
if( vehicleMod.Index > maxIndex && !force ) | ||
{ | ||
return false; | ||
} | ||
|
||
var result = SetMod( ( byte ) vehicleMod.ModType, ( byte ) vehicleMod.Index ); | ||
InstalledMods.Add( vehicleMod ); | ||
return result; | ||
} | ||
|
||
public IEnumerable<( VehicleMod mod, bool result )> InstallMods( IEnumerable<VehicleMod> vehicleMods ) | ||
{ | ||
return ( from vehicleMod in vehicleMods let result = InstallMod( vehicleMod ) select ( vehicleMod, result ) ).ToList( ); | ||
} | ||
|
||
public bool RemoveMod( VehicleModType vehicleModType ) | ||
{ | ||
var result = SetMod( ( byte ) vehicleModType, 0 ); | ||
InstalledMods.RemoveAll( x => x.ModType == vehicleModType ); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using AltV.Net.Enums; | ||
namespace AltV.Atlas.Vehicles.Models; | ||
|
||
public class VehicleMod | ||
{ | ||
/// <summary> | ||
/// Constructor to create a VehicleMod | ||
/// </summary> | ||
/// <param name="vehicleModType">The type of the mod</param> | ||
/// <param name="index">The index of the mod</param> | ||
public VehicleMod( VehicleModType vehicleModType, uint index ) | ||
{ | ||
ModType = vehicleModType; | ||
Index = index; | ||
} | ||
/// <summary> | ||
/// Type of the vehicle mod | ||
/// </summary> | ||
public VehicleModType ModType { get; set; } | ||
|
||
/// <summary> | ||
/// Index of the vehicle mod | ||
/// </summary> | ||
public uint Index { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Drawing; | ||
namespace AltV.Atlas.Vehicles.Utils; | ||
|
||
public static class Utility | ||
{ | ||
/// <summary> | ||
/// Tries to parse a string to a rgb color | ||
/// </summary> | ||
/// <param name="rgb">The rgb value</param> | ||
/// <param name="color">The color value</param> | ||
/// <returns>Returns if the parsing was successful</returns> | ||
public static bool TryParseRgb( this string rgb, out Color color ) | ||
{ | ||
color = Color.Empty; | ||
|
||
try | ||
{ | ||
color = ColorTranslator.FromHtml( rgb ); | ||
return true; | ||
} | ||
catch( Exception ex ) | ||
{ | ||
Console.WriteLine( $"Error parsing color string: {ex.Message}" ); | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters