Skip to content

Commit

Permalink
Merge branch '2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
RealityStop committed Jan 8, 2019
2 parents 7e7a061 + 539a976 commit f55066b
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Bolt.Addons.Community.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
Expand Down
4 changes: 3 additions & 1 deletion src/Fundamentals/Bolt.Addons.Community.Fundamentals.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Units\Deprecated\RandomNumbers.cs" />
<Compile Include="Units\Documenting\CommentUnit.cs" />
<Compile Include="Units\Documenting\MakeGame.cs" />
<Compile Include="Units\Documenting\StuffHappens.cs" />
<Compile Include="Units\Documenting\Todo.cs" />
<Compile Include="Units\FlowEvents\ManualEvent.cs" />
Expand Down Expand Up @@ -72,7 +74,7 @@
<Compile Include="Units\math\Functions\SigmoidFunction.cs" />
<Compile Include="Units\math\Functions\SigmoidFunctionOfRange.cs" />
<Compile Include="Units\math\MathParamNode.cs" />
<Compile Include="Units\math\RandomNumbers.cs" />
<Compile Include="Units\math\RandomNumbersv2.cs" />
<Compile Include="Units\physics\OnParticleTriggerNode.cs" />
<Compile Include="Units\variables\DecrementUnit.cs" />
<Compile Include="Units\variables\IncrementUnit.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
using System.Text;
using UnityEngine;

namespace Bolt.Addons.Community.Fundamentals
namespace Bolt.Addons.Community.Fundamentals.Deprecated
{
/// <summary>
/// Takes a given float input (0-1) and scales it across the specified range.
/// </summary>
[UnitCategory("Community\\Collections\\Lists")]
[RenamedFrom("Bolt.Addons.Community.Fundamentals.RandomNumbers")]
[RenamedFrom("Bolt.Addons.Community.Custom_Units.Math.RandomNumbers")]
[UnitTitle("Random Numbers")]
[TypeIcon(typeof(IList))]
[Obsolete]
[UnitOrder(20)]
public class RandomNumbers : Unit
{
Expand Down Expand Up @@ -62,7 +61,7 @@ public RandomNumbers() : base() { }

protected override void Definition()
{
input = ControlInput(nameof(input),x=>Enter(x));
input = ControlInput(nameof(input), x => Enter(x));
count = ValueInput<int>(nameof(count), 10);
unique = ValueInput<bool>(nameof(unique), true);
exit = ControlOutput(nameof(exit));
Expand Down Expand Up @@ -101,7 +100,7 @@ private void BuildList(Flow flow)
//If we need unique integers, we have to ensure there are enough choices
if (createUnique && integer)
{

}
if (integer)
{
Expand Down Expand Up @@ -129,7 +128,7 @@ private void PopulateList<T>(bool unique, int count, IList list, Func<T> p)
{
HashSet<T> uniqueNumbers = new HashSet<T>();

while(list.Count < count)
while (list.Count < count)
{
T newNumber = p();
if (unique)
Expand Down
71 changes: 71 additions & 0 deletions src/Fundamentals/Units/Documenting/MakeGame.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//using Bolt.Community.Addons.Utility;
//using Ludiq;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;

//namespace Bolt.Addons.Community.Fundamentals.Units.Documenting
//{
// [UnitCategory("Community\\Documentation")]
// [UnitShortTitle("Make Game")]
// [UnitTitle("Make Game")]
// public class MakeGame : Unit
// {

// [UnitHeaderInspectable]
// [UnitButton("TriggerButton")]
// public UnitButton go;


// /// <summary>
// /// The action to execute if the condition is true.
// /// </summary>
// [DoNotSerialize]
// [PortLabel("Success!")]
// public ControlOutput success { get; private set; }



// /// <summary>
// /// The action to execute if the condition is true.
// /// </summary>
// [DoNotSerialize]
// [PortLabel("Give Up")]
// public ControlOutput giveUp { get; private set; }



// /// <summary>
// /// The action to execute if the condition is true.
// /// </summary>
// [DoNotSerialize]
// [PortLabel("Why is this so hard?")]
// public ControlOutput hard { get; private set; }


// /// <summary>
// /// The action to execute if the condition is true.
// /// </summary>
// [DoNotSerialize]
// [PortLabel("There's a button for this?")]
// public ControlOutput button { get; private set; }


// /// <summary>
// /// The action to execute if the condition is true.
// /// </summary>
// [DoNotSerialize]
// [PortLabel("I can haz MMORPG?")]
// public ControlOutput mmorpg { get; private set; }

// protected override void Definition()
// {
// success = ControlOutput(nameof(success));
// giveUp = ControlOutput(nameof(giveUp));
// hard = ControlOutput(nameof(hard));
// button = ControlOutput(nameof(button));
// mmorpg = ControlOutput(nameof(mmorpg));
// }
// }
//}
16 changes: 9 additions & 7 deletions src/Fundamentals/Units/Logic/Branching/BranchParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,17 @@ bool NumericComparison(float a, float b, bool allowEquals)

private ControlOutput Branch(Flow flow)
{
if (GetValue(flow))
flow.Invoke(exitTrue);
else
flow.Invoke(exitFalse);

if (showNext)
return exitNext;
{
if (GetValue(flow))
flow.Invoke(exitTrue);
else
flow.Invoke(exitFalse);

return null;
return exitNext;
}
else
return GetValue(flow) ? exitTrue : exitFalse;
}
}
}
179 changes: 179 additions & 0 deletions src/Fundamentals/Units/Math/RandomNumbersv2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
using Ludiq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Bolt.Addons.Community.Fundamentals
{
/// <summary>
/// Returns a list of random numbers from the specified range.
/// </summary>
[UnitCategory("Community\\Collections\\Lists")]
[UnitTitle("Random Numbers")]
[TypeIcon(typeof(IList))]
[UnitOrder(20)]
public class RandomNumbersv2 : Unit
{
public RandomNumbersv2() : base() { }

/// <summary>
/// Flow In
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ControlInput input { get; private set; }

[DoNotSerialize]
public ValueInput count { get; private set; }

[DoNotSerialize]
public ValueInput minimum { get; private set; }

[DoNotSerialize]
public ValueInput maximum { get; private set; }

[DoNotSerialize]
[PortLabelHidden]
public ValueOutput output { get; private set; }


//Flow Out
[DoNotSerialize]
[PortLabelHidden]
public ControlOutput exit { get; private set; }

/// <summary>
/// Whether the compared inputs are numbers.
/// </summary>
[Serialize]
[Inspectable]
[InspectorToggleLeft]
public bool integer { get; set; } = false;

/// <summary>
/// Whether the compared inputs are numbers.
/// </summary>
[Serialize]
[Inspectable]
[InspectorToggleLeft]
public bool aotList { get; set; } = false;


/// <summary>
/// Whether the compared inputs are numbers.
/// </summary>
[Serialize]
[Inspectable]
[InspectorToggleLeft]
public bool unique { get; set; } = true;


// IList _list = new List<object>();
IList _list;

protected override void Definition()
{
input = ControlInput(nameof(input), x => Enter(x));
count = ValueInput<int>(nameof(count), 10);
exit = ControlOutput(nameof(exit));

if (integer)
{
minimum = ValueInput<int>(nameof(minimum), 0);
maximum = ValueInput<int>(nameof(maximum), 100);
output = ValueOutput<IList>(nameof(output), (x) => { if (_list == null) BuildList(x); return _list; });
}
else
{
minimum = ValueInput<float>(nameof(minimum), 0);
maximum = ValueInput<float>(nameof(maximum), 100);
output = ValueOutput<IList>(nameof(output), (x) => { if (_list == null) BuildList(x); return _list; });
}

Succession(input, exit);

Requirement(count, input);
Requirement(minimum, input);

Requirement(count, output);
Requirement(minimum, output);
}

private void BuildList(Flow flow)
{
int num = flow.GetValue<int>(count);

ManageList(num);

if (integer)
{
int min = flow.GetValue<int>(minimum);
int max = flow.GetValue<int>(maximum);

//If we need unique integers, we have to ensure there are enough choices
if (unique)
if (max - min < num)
{
throw new ArgumentException("Random Number generation failed. Unique range is too small for the number of elements specified.");
}

PopulateList(unique, num, _list, () => { return UnityEngine.Random.Range(min, max); });
}
else
{

float min = flow.GetValue<float>(minimum);
float max = flow.GetValue<float>(maximum);
PopulateList(unique, num, _list, () => { return UnityEngine.Random.Range(min, max); });
}

}

private void ManageList(int num)
{
if (_list == null)
{
if (aotList)
{
_list = new AotList(num);
}
else
{
if (integer)
_list = new List<object>(num);
}
}

_list.Clear();
}

private void PopulateList<T>(bool unique, int count, IList list, Func<T> p)
{
HashSet<T> uniqueNumbers = new HashSet<T>();

while (list.Count < count)
{
T newNumber = p();
if (unique)
{
if (!uniqueNumbers.Contains(newNumber))
{
uniqueNumbers.Add(newNumber);
list.Add(newNumber);
}
}
else
list.Add(newNumber);
}
}

private ControlOutput Enter(Flow flow)
{
BuildList(flow);
return exit;
}
}
}
2 changes: 1 addition & 1 deletion src/Utility/Bolt.Addons.Community.Utility.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down

0 comments on commit f55066b

Please sign in to comment.