Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Danilo1301 committed Jul 15, 2024
1 parent 279bce9 commit a51c424
Show file tree
Hide file tree
Showing 38 changed files with 887 additions and 386 deletions.
2 changes: 1 addition & 1 deletion GiroflexVSL/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include $(CLEAR_VARS)
LOCAL_CPP_EXTENSION := .cpp .cc
LOCAL_CPP_FEATURES += exceptions
LOCAL_MODULE := GiroflexVSL
LOCAL_SRC_FILES := main.cpp mod/logger.cpp mod/config.cpp json_reader.cpp json_value.cpp json_writer.cpp Log.cpp Mod.cpp menu/Draw.cpp menu/Menu.cpp menu/Item.cpp menu/Window.cpp menu/CleoMenu.cpp Input.cpp windows/WindowTest.cpp Vehicles.cpp Vehicle.cpp Globals.cpp LightGroup.cpp ModelInfo.cpp ModelInfos.cpp windows/WindowMain.cpp windows/WindowLightGroups.cpp windows/WindowSettings.cpp windows/WindowEditing.cpp Patterns.cpp LightGroupDatas.cpp windows/WindowWhiteCorona.cpp windows/WindowShadow.cpp windows/WindowPointLight.cpp windows/WindowFlare.cpp ModConfig.cpp iniconfig/INIFile.cpp iniconfig/INISection.cpp SoundSystem.cpp windows/WindowSelectPanel.cpp windows/WindowSoundPanel.cpp windows/SoundPanelButton.cpp windows/WindowSoundPanelSettings.cpp windows/WindowPanel.cpp ConvertOldVersion.cpp windows/WindowRotate.cpp audiosystem.cpp SirenSystem.cpp Widgets.cpp GiroflexVSL.cpp VehicleDummy.cpp windows/WindowLed.cpp sdk/Image.cpp
LOCAL_SRC_FILES := main.cpp mod/logger.cpp mod/config.cpp json_reader.cpp json_value.cpp json_writer.cpp Log.cpp Mod.cpp menu/Draw.cpp menu/Menu.cpp menu/Item.cpp menu/Window.cpp menu/CleoMenu.cpp Input.cpp windows/WindowTest.cpp Vehicles.cpp Vehicle.cpp Globals.cpp LightGroup.cpp ModelInfo.cpp ModelInfos.cpp windows/WindowMain.cpp windows/WindowLightGroups.cpp windows/WindowSettings.cpp windows/WindowEditing.cpp Patterns.cpp LightGroupDatas.cpp windows/WindowWhiteCorona.cpp windows/WindowShadow.cpp windows/WindowPointLight.cpp windows/WindowFlare.cpp ModConfig.cpp iniconfig/INIFile.cpp iniconfig/INISection.cpp SoundSystem.cpp windows/WindowSelectPanel.cpp windows/WindowSoundPanel.cpp windows/SoundPanelButton.cpp windows/WindowSoundPanelSettings.cpp windows/WindowPanel.cpp ConvertOldVersion.cpp windows/WindowRotate.cpp audiosystem.cpp SirenSystem.cpp Widgets.cpp GiroflexVSL.cpp VehicleDummy.cpp windows/WindowLed.cpp sdk/Image.cpp windows/WindowPatterns.cpp
LOCAL_CFLAGS += -O2 -mfloat-abi=softfp -DNDEBUG -std=c++17
LOCAL_C_INCLUDES += ./include
LOCAL_LDLIBS += -llog
Expand Down
287 changes: 287 additions & 0 deletions GiroflexVSL/LightGroup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
#include "LightGroup.h"

#include "Patterns.h"
#include "Log.h"

LightGroup::LightGroup()
{

}

LightGroup::~LightGroup()
{
Destroy();
}

Point* LightGroup::AddPoint()
{
Point* point = new Point();
points.push_back(point);

Update();

return point;
}

void LightGroup::SetNumberOfPoints(int amount)
{
while(points.size() < amount)
{
AddPoint();
}
while(points.size() > amount)
{
RemovePoint(points[points.size() - 1]);
}
}

void LightGroup::RemovePoint(Point* point)
{
auto it = std::find(points.begin(), points.end(), point);
if (it == points.end()) return;
points.erase(it);
delete point;
}

void LightGroup::RemoveAllPoints()
{
while (points.size() > 0)
RemovePoint(points[0]);
}

void LightGroup::Update()
{
//patterns.clear();

auto compatiblePatterns = Patterns::GetCompatiblePatterns(points.size());

std::vector<std::string> idsToRemove;
for(auto p : patterns)
{
auto id = p.first;

auto pattern = Patterns::GetPatternById(id);

auto it = std::find(compatiblePatterns.begin(), compatiblePatterns.end(), pattern);
if(it == compatiblePatterns.end())
{
idsToRemove.push_back(id);
}
}

for(auto id : idsToRemove)
{
patterns.erase(id);
}

for(auto pattern : compatiblePatterns)
{
Log::Level(LOG_LEVEL::LOG_BOTH) << "Checking pattern " + pattern->id << std::endl;

auto it = patterns.find(pattern->id);
bool hasPattern = it != patterns.end();

if(!hasPattern)
{
Log::Level(LOG_LEVEL::LOG_BOTH) << "Doesnt have pattern, adding defualt value" << std::endl;

patterns[pattern->id] = true;
}
}
}

void LightGroup::Destroy()
{
RemoveAllPoints();
}

Json::Value LightGroup::ToJSON()
{
Json::Value value = Json::objectValue;

value["offset"] = CVectorToJSON(offset);

//points
value["points"] = Json::arrayValue;
for (auto point : points) {
value["points"].append( point->ToJSON() );
}

value["distance"] = distance;
value["curve"] = curve;

value["color1"] = ColorToJSON(color1);
value["color2"] = ColorToJSON(color2);
value["color3"] = ColorToJSON(color3);

value["patternOffset"] = patternOffset;

value["radius"] = radius;

value["renderShadow"] = renderShadow;
value["shadowIntensity"] = shadowIntensity;
value["shadowSize"] = shadowSize;
value["shadowPositionX"] = shadowPositionX;
value["shadowPositionY"] = shadowPositionY;
value["shadowTexture"] = shadowTexture;
value["shadowRotation"] = shadowRotation;
value["shadowFlipTextures"] = shadowFlipTextures;

value["renderPointLight"] = renderPointLight;
value["pointLightIntensity"] = pointLightIntensity;
value["pointLightDistance"] = pointLightDistance;

value["nearClip"] = nearClip;

//value["usePointPositionInsteadOfIndex"] = usePointPositionInsteadOfIndex;

value["useSmallWhiteCorona"] = useSmallWhiteCorona;
value["smallWhiteCoronaScale"] = smallWhiteCoronaScale;
value["smallWhiteCoronaTexture"] = smallWhiteCoronaTexture;
value["smallWhiteCoronaColor"] = ColorToJSON(smallWhiteCoronaColor);

value["freezeLights"] = freezeLights;

value["useFlare"] = useFlare;
value["flareIntensity"] = flareIntensity;
value["flareDistance"] = flareDistance;
value["flareTexture"] = flareTexture;

value["coronaTexture"] = coronaTexture;

value["lightSlotId"] = lightSlotId;

value["alwaysEnabled"] = alwaysEnabled;
//value["enableOnSpawn"] = enableOnSpawn;
value["enableWithLights"] = enableWithLights;


value["rotate"] = rotate;
value["rotateDistance"] = rotateDistance;
value["rotateSpeed"] = rotateSpeed;
value["rotateInverse"] = rotateInverse;

value["useLightbarLEDs"] = useLightbarLEDs;
value["useNormalLEDs"] = useNormalLEDs;
value["normalLEDStartIndex"] = normalLEDStartIndex;

value["ledColor1Enabled"] = ColorToJSON(ledColor1Enabled);
value["ledColor2Enabled"] = ColorToJSON(ledColor2Enabled);
value["ledColor3Enabled"] = ColorToJSON(ledColor3Enabled);
value["ledColorDisabled"] = ColorToJSON(ledColorDisabled);

Json::Value patternsValue = Json::objectValue;
for(auto p : patterns)
{
auto id = p.first;
auto value = p.second;

patternsValue[id] = value;
}
value["patterns"] = patternsValue;

return value;
}

void LightGroup::FromJSON(Json::Value value)
{
offset = ValidateCVector(value["offset"], offset);

for (int i = 0; i < (int)value["points"].size(); i++)
{
auto point = AddPoint();
point->FromJSON(value["points"][i]);
}

distance = ValidateValue(value["distance"], distance).asFloat();
curve = ValidateValue(value["curve"], curve).asFloat();

color1 = ValidateColor(value["color1"], color1);
color2 = ValidateColor(value["color2"], color2);
color3 = ValidateColor(value["color3"], color3);

patternOffset = ValidateValue(value["patternOffset"], patternOffset).asInt();

radius = ValidateValue(value["radius"], radius).asFloat();

renderShadow = ValidateValue(value["renderShadow"], renderShadow).asBool();
shadowIntensity = ValidateValue(value["shadowIntensity"], shadowIntensity).asFloat();
shadowSize = ValidateValue(value["shadowSize"], shadowSize).asFloat();
shadowPositionX = ValidateValue(value["shadowPositionX"], shadowPositionX).asFloat();
shadowPositionY = ValidateValue(value["shadowPositionY"], shadowPositionY).asFloat();
shadowTexture = ValidateValue(value["shadowTexture"], shadowTexture).asInt();
shadowRotation = ValidateValue(value["shadowRotation"], shadowRotation).asFloat();
shadowFlipTextures = ValidateValue(value["shadowFlipTextures"], shadowFlipTextures).asBool();

renderPointLight = ValidateValue(value["renderPointLight"], renderPointLight).asBool();
pointLightIntensity = ValidateValue(value["pointLightIntensity"], pointLightIntensity).asFloat();
pointLightDistance = ValidateValue(value["pointLightDistance"], pointLightDistance).asFloat();

nearClip = ValidateValue(value["nearClip"], nearClip).asFloat();

//usePointPositionInsteadOfIndex = ValidateValue(value["usePointPositionInsteadOfIndex"], usePointPositionInsteadOfIndex).asBool();

useSmallWhiteCorona = ValidateValue(value["useSmallWhiteCorona"], useSmallWhiteCorona).asBool();
smallWhiteCoronaScale = ValidateValue(value["smallWhiteCoronaScale"], smallWhiteCoronaScale).asFloat();
smallWhiteCoronaTexture = ValidateValue(value["smallWhiteCoronaTexture"], smallWhiteCoronaTexture).asInt();
smallWhiteCoronaColor = ValidateColor(value["smallWhiteCoronaColor"], smallWhiteCoronaColor);

freezeLights = ValidateValue(value["freezeLights"], freezeLights).asBool();

useFlare = ValidateValue(value["useFlare"], useFlare).asBool();
flareIntensity = ValidateValue(value["flareIntensity"], flareIntensity).asFloat();
flareDistance = ValidateValue(value["flareDistance"], flareDistance).asFloat();
flareTexture = ValidateValue(value["flareTexture"], flareTexture).asInt();

coronaTexture = ValidateValue(value["coronaTexture"], coronaTexture).asInt();

lightSlotId = ValidateValue(value["lightSlotId"], lightSlotId).asInt();

alwaysEnabled = ValidateValue(value["alwaysEnabled"], alwaysEnabled).asBool();
//enableOnSpawn = ValidateValue(value["enableOnSpawn"], enableOnSpawn).asBool();
enableWithLights = ValidateValue(value["enableWithLights"], enableWithLights).asBool();

rotate = ValidateValue(value["rotate"], rotate).asBool();
rotateDistance = ValidateValue(value["rotateDistance"], rotateDistance).asFloat();
rotateSpeed = ValidateValue(value["rotateSpeed"], rotateSpeed).asFloat();
rotateInverse = ValidateValue(value["rotateInverse"], rotateInverse).asBool();

useLightbarLEDs = ValidateValue(value["useLightbarLEDs"], useLightbarLEDs).asBool();
useNormalLEDs = ValidateValue(value["useNormalLEDs"], useNormalLEDs).asBool();
normalLEDStartIndex = ValidateValue(value["normalLEDStartIndex"], normalLEDStartIndex).asInt();

ledColor1Enabled = ValidateColor(value["ledColor1Enabled"], ledColor1Enabled);
ledColor2Enabled = ValidateColor(value["ledColor2Enabled"], ledColor2Enabled);
ledColor3Enabled = ValidateColor(value["ledColor3Enabled"], ledColor3Enabled);
ledColorDisabled = ValidateColor(value["ledColorDisabled"], ledColorDisabled);

Json::Value patternsValue = value["patterns"];
if(!patternsValue.isNull())
{
for(auto id : patternsValue.getMemberNames())
{
auto value = patternsValue[id].asBool();

patterns[id] = value;
}
}
}

std::vector<Pattern*> LightGroup::GetPatterns()
{
std::vector<Pattern*> compatiblePatterns;

for(auto p : patterns)
{
auto id = p.first;
auto value = p.second;

auto pattern = Patterns::GetPatternById(id);

if(!value) continue;

compatiblePatterns.push_back(pattern);
}

return compatiblePatterns;
}
Loading

0 comments on commit a51c424

Please sign in to comment.