Skip to content

Commit

Permalink
Creation of pick-ups and blips now optional
Browse files Browse the repository at this point in the history
  • Loading branch information
thers committed May 16, 2017
1 parent 2fb7e8f commit 65f98d6
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FRFuel
{
public class Config
{
protected Dictionary<string, string> Entries { get; set; }

public Config(string content)
{
Entries = new Dictionary<string, string>();

if (content == null || content.Length == 0)
{
return;
}

var splitted = content
.Split('\n')
.Where((line) => !line.Trim().StartsWith("#"))
.Select((line) => line.Trim().Split('='))
.Where((line) => line.Length == 2);

foreach (var tuple in splitted)
{
Entries.Add(tuple[0], tuple[1]);
}
}

public string Get(string key, string defaultValue = null)
{
if (Entries.ContainsKey(key))
{
return Entries[key];
}

return defaultValue;
}
}
}
37 changes: 37 additions & 0 deletions FRFuel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class FRFuel : BaseScript

protected Vehicle LastVehicle { get => lastVehicle; set => lastVehicle = value; }
protected Blip CurrentGasStation { get => currentGasStation; set => currentGasStation = value; }

protected Config Config { get; set; }
#endregion

/// <summary>
Expand All @@ -63,6 +65,8 @@ public FRFuel()
#endif
hud = new HUD();

LoadConfig();

jerryCanAnimation = new InLoopOutAnimation(
new Animation(manualRefuelAnimDict, "fire_intro"),
new Animation(manualRefuelAnimDict, "fire"),
Expand Down Expand Up @@ -102,11 +106,39 @@ public FRFuel()
}

#region Init
/// <summary>
/// Loads configuration from file
/// </summary>
protected void LoadConfig()
{
string configContent = null;

try
{
configContent = Function.Call<string>(Hash.LOAD_RESOURCE_FILE, "frfuel", "config.ini");
}
catch(Exception e)
{
// nothing
}

Config = new Config(configContent);

#if DEBUG
Debug.WriteLine($"CreatePickups: {Config.Get("CreatePickups", "true")}");
#endif
}

/// <summary>
/// Creates blips for gas stations
/// </summary>
public void CreateBlips()
{
if (Config.Get("CreateBlips", "true") != "true")
{
return;
}

for (int i = 0; i < GasStations.positions.Length; i++)
{
var blip = World.CreateBlip(GasStations.positions[i]);
Expand All @@ -125,6 +157,11 @@ public void CreateBlips()
/// </summary>
public void CreateJerryCanPickUps()
{
if (Config.Get("CreatePickups", "true") != "true")
{
return;
}

int model = 883325847;

Function.Call(Hash.REQUEST_MODEL, model);
Expand Down
1 change: 1 addition & 0 deletions FRFuel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="InLoopOutAnimation.cs" />
<Compile Include="DevMenu.cs" />
<Compile Include="EntityDecoration.cs" />
Expand Down

0 comments on commit 65f98d6

Please sign in to comment.