Skip to content

Commit

Permalink
Update FlatRideBinder
Browse files Browse the repository at this point in the history
- Added option to check if the binder has been applied or not
  • Loading branch information
RobbinBob committed Jul 1, 2024
1 parent 3e0076c commit 94c5487
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions FlatRideUtility/FlatRideBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ public class FlatRideBinder
{
private readonly List<Object> registeredObjects = new List<Object>();
private readonly string binderHash;
// Not sure what this is for
private readonly GameObject hider;

private bool m_IsApplied = false;

/// <summary>
/// Create new <see cref="FlatRideBinder"/> with hash <paramref name="hash"/> for modifying FlatRides
/// </summary>
/// <param name="hash"></param>
public FlatRideBinder(string hash)
{
hider = new GameObject();
binderHash = hash;
}

Expand All @@ -34,6 +33,13 @@ private string GetNameHash(string name)
}


/// <summary>
/// Returns the <see cref="FlatRideBinder"/> patch state.
/// </summary>
/// <returns><see langword="true"/> if applied, otherwise <see langword="false"/>.</returns>
public bool IsApplied() => m_IsApplied;


/// <summary>
/// Adds all data from this binder into the games asset list
/// </summary>
Expand All @@ -46,7 +52,7 @@ public void Apply()
FileIO.Write($"Binding FlatRide of Type: {registeredObjects[i].GetType().FullName} with Name: {registeredObjects[i].name}");
ScriptableSingleton<AssetManager>.Instance.registerObject(registeredObjects[i]);
}
hider.SetActive(false);
m_IsApplied = true;
}
catch (Exception e)
{
Expand All @@ -65,7 +71,7 @@ public void Remove()
{
ScriptableSingleton<AssetManager>.Instance.unregisterObject(registeredObjects[i]);
}
Object.DestroyImmediate(hider);
m_IsApplied = false;
}
catch (Exception e)
{
Expand Down Expand Up @@ -110,23 +116,6 @@ public T RegisterNewFlatRide<T>(string name, string displayname) where T : FlatR
return flatRide;
}
/// <summary>
/// Create a new <see cref="FlatRide"/> of type <typeparamref name="T"/>, attached to <paramref name="rideprefab"/>, Useful for full customization of a <see cref="FlatRide"/>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="name"></param>
/// <param name="displayname"></param>
/// <param name="rideprefab"></param>
/// <returns>The <see cref="FlatRide"/> component</returns>
public T RegisterNewFlatRide<T>(string name, string displayname, GameObject rideprefab) where T : FlatRide
{
T component = rideprefab.AddComponent<T>();
component.name = GetNameHash(name);
component.setDisplayName(displayname);

registeredObjects.Add(component);
return component;
}
/// <summary>
/// Creates a new <see cref="FlatRide"/> of type <typeparamref name="T"/>, setup using a PAE <see cref="AssetPack"/>
/// </summary>
/// <typeparam name="T"></typeparam>
Expand Down

0 comments on commit 94c5487

Please sign in to comment.