Skip to content

Commit

Permalink
colormodes! now switch from the UI
Browse files Browse the repository at this point in the history
added option to switch color modes from ingame (b4 only from editor)
also refactored the way colors are selected - before it was a beautifully organized script, now its just an integer (because i needed it to cycle with modulo)
  • Loading branch information
marmust committed Nov 23, 2023
1 parent edbbc8c commit 9759455
Show file tree
Hide file tree
Showing 9 changed files with 1,289 additions and 676 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public class InputSystem : MonoBehaviour
{
public List<Transform> HoldOnTo;
public List<Vector3> InitPositions;
public VarHolder vars;
public UiSystem YouISystem;

private float is_boosting = 1;
private float totalXRotation = 0f;
Expand All @@ -20,12 +22,23 @@ private void Awake()
void Update()
{
// handle physics throttle
VarHolder vars = GetComponent<VarHolder>();
if (vars.SecondsPerPhysicsUpdate <= vars.SlowestPhysicsUpdates)
{
vars.SecondsPerPhysicsUpdate += (vars.SlowestPhysicsUpdates - vars.SecondsPerPhysicsUpdate + 1) / 2f * Time.deltaTime;
}

if (Input.GetKeyDown(KeyCode.Q))
{
vars.ColorModeIDX = (vars.ColorModeIDX + 1) % 4;
YouISystem.OnColorModeChange();
}

if (Input.GetKeyDown(KeyCode.E))
{
vars.ColorModeIDX = (vars.ColorModeIDX + 3) % 4;
YouISystem.OnColorModeChange();
}

if (Input.GetKey(KeyCode.G))
{
if (vars.SecondsPerPhysicsUpdate >= vars.FastestPhysicsUpdates)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Assets.scripts.misc;
using System;
using TMPro;
using UnityEngine;
Expand All @@ -12,7 +11,8 @@ public class NodeColorHandler : MonoBehaviour
public NodePhysicsHandler PhysicsHandler;
public NodeStructureHandler StructureHandler;

public Assets.scripts.misc.ColorMode ColorModeSwitchFlag;
private float ColorRefreshCooldown = 0.1f;
//private float lastUpdateTime = Time.time;

private void Awake()
{
Expand All @@ -22,15 +22,9 @@ private void Awake()

PhysicsHandler = gameObject.GetComponent<NodePhysicsHandler>();
StructureHandler = gameObject.GetComponent<NodeStructureHandler>();
}

ColorModeSwitchFlag = vars.ColorMode;

// take care of newborn nodes (so when they spawn they immediatly get correct color)
// (without waiting for colormode switch)
UpdateColors();
}

public void SetColor(Color color, bool ChangeLinerenderer = true)
public void SetColor(Color color, bool ChangeLinerenderer = true)
{
sprite.color = color;

Expand All @@ -43,60 +37,66 @@ public void SetColor(Color color, bool ChangeLinerenderer = true)

private void Update()
{
// detect colormode switch
if (ColorModeSwitchFlag != vars.ColorMode)
{
ColorModeSwitchFlag = vars.ColorMode;
//if (Time.time - lastUpdateTime >= ColorRefreshCooldown)
//{
UpdateColors();
}
// lastUpdateTime = Time.time;
//}
}

public void UpdateColors()
{
if (vars.ColorMode == Assets.scripts.misc.ColorMode.in_range)
{
if (PhysicsHandler.in_camera_physics_range)
{
SetColor(new Color(1.0f, 0.27f, 0.27f, 1.0f));
}
else
{
SetColor(new Color(1.0f, 1.0f, 1.0f, 0.2f));
}
}

if (vars.ColorMode == Assets.scripts.misc.ColorMode.is_scanned)
{
SetColor(new Color(1.0f, 1.0f, 1.0f, 0.2f));

if (StructureHandler.expanded)
{
SetColor(new Color(0.54f, 0.68f, 1.0f, 1.0f), false);
}
else
{
SetColor(new Color(1.0f, 1.0f, 1.0f, 0.2f));
}
}
// 0 - none (all white)
// 1 - in_range (red if in physics range)
// 2 - is_scanned (blue if has been scanned)
// 3 - url_length (the shorter the URL, the greener)

if (vars.ColorMode == Assets.scripts.misc.ColorMode.url_length)
{
if (gameObject.name != "mould")
{
// length - hue function: \frac{1}{0.5\max\left(x,\ 20\right)-f} <<< copy paste to desmos (f=9)
int length = StructureHandler.node_url.Length;
float hue = 1 / (0.1f * Math.Max(length, 20) - 1.0f);
public void UpdateColors()
{
if (vars.ColorModeIDX == 1)
{
if (PhysicsHandler.in_camera_physics_range)
{
SetColor(new Color(1.0f, 0.27f, 0.27f, 1.0f));
}
else
{
SetColor(new Color(1.0f, 1.0f, 1.0f, 0.2f));
}
}

if (vars.ColorModeIDX == 2)
{
SetColor(new Color(1.0f, 1.0f, 1.0f, 0.2f));

if (StructureHandler.expanded)
{
SetColor(new Color(0.54f, 0.68f, 1.0f, 1.0f), false);
}
else
{
SetColor(new Color(1.0f, 1.0f, 1.0f, 0.2f));
}
}

if (vars.ColorModeIDX == 3)
{
if (gameObject.name != "mould")
{
SetColor(new Color(1.0f, 1.0f, 1.0f, 0.2f));

// length - hue function: \frac{1}{0.2\max\left(x,\ 20\right)-f} <<< copy paste to desmos (f=3)
int length = StructureHandler.node_url.Length;
float hue = 1 / (0.2f * Math.Max(length, 30) - 5);

SetColor(new Color(0.0f, 1.0f, 0.3f, hue));
}
}
SetColor(new Color(0.3f, 1.0f, 0.3f, hue), false);
}
}

if (vars.ColorMode == Assets.scripts.misc.ColorMode.none)
{
SetColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
}
if (vars.ColorModeIDX == 0)
{
SetColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
}

}
}

// for later use:
//public void propogate_by_branch_mode(Color parent_color)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void Awake()
node_mould_object = GameObject.Find("mould");
PhysicsHandler = gameObject.GetComponent<NodePhysicsHandler>();
ColorHandler = gameObject.GetComponent<NodeColorHandler>();
}
}

// !! FIRST READ expand_node() THEN READ void update() !!

Expand Down Expand Up @@ -244,7 +244,6 @@ public void ExpandNode()
string host = separations[0];
separations.Remove(host);


// We now have the host (hopefully)
// We can look it up on the DNS to see if it's valid
IPHostEntry dnslookup;
Expand All @@ -257,11 +256,7 @@ public void ExpandNode()
scanError = "Invalid hostname";
return;
}


node_url = $"https://{host}/{String.Join("/", separations)}/";


}
else
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Collections.Generic;

public class UiSystem : MonoBehaviour
{
Expand All @@ -22,12 +23,29 @@ public class UiSystem : MonoBehaviour
public TextMeshProUGUI max_physics_throttle_text;
public TextMeshProUGUI min_physics_throttle_text;

public TextMeshProUGUI ColorModeName;
public TextMeshProUGUI ColorModePurpose;

public RectTransform canvas_rctf;
public RectTransform target_indicator_rctf;
public RectTransform physics_update_rate_throttle;

private Color throttle_red_shift;

// 0 - none (all white)
// 1 - in_range (red if in physics range)
// 2 - is_scanned (blue if has been scanned)
// 3 - url_length (the shorter the URL, the greener)
private List<string> ColorModeNames = new List<string> {"NONE", "IN_RANGE", "IS_SCANNED", "URL_LENGTH"};
private List<string> ColorModePurposes = new List<string> {"all white",
"nodes is 'physics range' are red (helps with optimization)",
"nodes that have been scanned are blue (helps with seeing 'explored regions')",
"the shorter the URL, the greener (helps detect 'main' sites)"};
private List<Color> ColorModeAsociatedColors = new List<Color> {new Color(255f, 255f, 255f, 255f),
new Color(255f, 37f, 37f, 255f),
new Color(138f, 175f, 255f, 255f),
new Color(56f, 255f, 79f, 255f)};

private void Awake()
{
// reset all ui to initial states
Expand Down Expand Up @@ -109,6 +127,12 @@ private void Update()
}
}

public void OnColorModeChange()
{
ChangeText(ColorModeName, ColorModeNames[vars.ColorModeIDX], ColorModeAsociatedColors[vars.ColorModeIDX]);
ChangeText(ColorModePurpose, ColorModePurposes[vars.ColorModeIDX], new Color(100f, 100f, 100f, 256f));
}

public void CollectUrlFromTextBox()
{
string inputted_url = url_inputfield.text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Assets.scripts.misc;
using UnityEngine;

public class VarHolder : MonoBehaviour
Expand All @@ -17,12 +16,17 @@ public class VarHolder : MonoBehaviour
public float RepulsionRadius;
public float TanhSoften;

// for player to control
[Tooltip("The coloring mode for the nodes:" +
"\nin_range - Nodes in physics range are red." +
"\nby_branch - Nodes inherit the color of their parent." +
"\nby_relation - Nodes' color will mutate over time")]
public ColorMode ColorMode = ColorMode.in_range;
// for player to control
[Tooltip("The coloring mode for the nodes:" +
"\nin_range - Nodes in physics range are red." +
"\nby_branch - Nodes inherit the color of their parent." +
"\nby_relation - Nodes' color will mutate over time")]

// 0 - none (all white)
// 1 - in_range (red if in physics range)
// 2 - is_scanned (blue if has been scanned)
// 3 - url_length (the shorter the URL, the greener)
public int ColorModeIDX = 0;
[HideInInspector]
public float SecondsPerPhysicsUpdate;
[Range(0.01f,1f)]
Expand Down

0 comments on commit 9759455

Please sign in to comment.