Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* RangeArgument.cs: A new range argument #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/Hackuble.Core/Arguments/RangeArgument.cs
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Hackuble.Arguments
{
public class RangeArgument : AbstractArgument<double>
{
public RangeArgument(string prompt, string description, double defaultValue)
: this(prompt, description, defaultValue, defaultValue - 10, defaultValue +10)
{

}

public RangeArgument(string prompt, string description, double defaultValue, double minValue, double maxValue)
: base(prompt, description, defaultValue)
{
MinValue = minValue;
MaxValue = maxValue;
}

public double MinValue { get; set; }
public double MaxValue { get; set; }

public override void RenderArgumentInput()
{
throw new NotImplementedException();
}
}
}
5 changes: 5 additions & 0 deletions src/Hackuble.Core/Command/DataAccess.cs
Expand Up @@ -34,6 +34,11 @@ public void RegisterBooleanArgument(string name, string description, bool defaul
this.Arguments.Add(new BooleanArgument(name, description, defaultValue));
}

public void RegisterRangeArgument(string name, string description, double defaultValue, double minValue, double maxValue )
{
this.Arguments.Add(new RangeArgument(name, description, defaultValue, minValue, maxValue));
}

public bool GetData<T>(int index, ref T data)
{
if (index < this.Arguments.Count)
Expand Down
52 changes: 52 additions & 0 deletions src/Hackuble.Examples/AddCubeSliders.cs
@@ -0,0 +1,52 @@
using Hackuble.Commands;
using System;
namespace Hackuble.Examples
{
public class AddCubeSliders : AbstractCommand
{
public override string Name => "Add Cube Slider";

public override string Author => "Filipe Brandão";

public override string Description => "Add a cuboid to the scene";

public override string CommandLineName => "cube-slider";

public override string Accent => "#FF96AD";

public override void RegisterInputArguments(DataAccess dataAccess)
{
dataAccess.RegisterRangeArgument("Size X", "The size of the cube in X direction", 20.0, 0.0, 40.0);
dataAccess.RegisterRangeArgument("Size Y", "The size of the cube in Y direction", 20.0, 0.0, 40.0);
dataAccess.RegisterRangeArgument("Size Z", "The size of the cube in Z direction", 20.0, 0.0, 40.0);
dataAccess.RegisterTextArgument("Color", "The color of the cube in Hex Format", "#FF96AD");
}

public override CommandStatus RunCommand(Context context, DataAccess dataAccess)
{
double x = -1;
double y = -1;
double z = -1;
string c = "#ffffff";
if (!dataAccess.GetData<double>(0, ref x))
{
return CommandStatus.Failure;
}
if (!dataAccess.GetData<double>(1, ref y))
{
return CommandStatus.Failure;
}
if (!dataAccess.GetData<double>(2, ref z))
{
return CommandStatus.Failure;
}
if (!dataAccess.GetData<string>(3, ref c))
{
return CommandStatus.Failure;
}

context.AddCube(0, 0, 0, x, y, z, c);
return CommandStatus.Success;
}
}
}
14 changes: 13 additions & 1 deletion src/Hackuble.Web/Shared/NavMenu.razor
Expand Up @@ -117,7 +117,7 @@
var textArg = arg as TextArgument;

<div class="d-flex my-1">
<div class="input-group-prepend" style="min-width:50px">
<div class="input-group-prepend">
<span class="input-group-text">@arg.Prompt</span>
</div>
@*<label>@arg.Prompt</label>*@
Expand All @@ -136,6 +136,18 @@
</div>
</div>
}
else if (arg is RangeArgument)
{
var rangeArg = arg as RangeArgument;
<div class="d-flex my-1">
<div class="input-group-prepend">
<span class="input-group-text">@arg.Prompt: @rangeArg.CurrentValue</span>
</div>
<div class="form-control">
<input type="range" @bind="rangeArg.CurrentValue" min="@rangeArg.MinValue." max="@rangeArg.MaxValue" />
</div>
</div>
}
}
}
}
Expand Down