clocks
This commit is contained in:
Executable
+70
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CompuLogic.Workspace
|
||||
{
|
||||
public class ClockGate : Gate
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public bool State { get; set; } = true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private Anchor OutputAnchor {
|
||||
get
|
||||
{
|
||||
if (_outputAnchor == null)
|
||||
_outputAnchor = Anchors.FirstOrDefault(g => g.Name == "Q");
|
||||
return _outputAnchor;
|
||||
}
|
||||
}
|
||||
private Anchor _outputAnchor;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Utils.RandomName("Input", gameObject);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void UpdateState()
|
||||
{
|
||||
if ((Sprite.Hovering || OutputAnchor.Hovering) && PointerManager.Instance.DoubleClick())
|
||||
{
|
||||
State = !State;
|
||||
}
|
||||
|
||||
if (State)
|
||||
{
|
||||
OutputAnchor.Activated = Mathf.Repeat(Time.time, CustomProperties[0]) >= CustomProperties[0] * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e96ac3a8b8e052746ab27ed052bf1f13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -20,9 +20,9 @@ namespace CompuLogic.Workspace
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_anchors == null)
|
||||
_anchors = GetComponentsInChildren<Anchor>().ToList();
|
||||
return _anchors;
|
||||
if(_anchors == null)
|
||||
_anchors = GetComponentsInChildren<Anchor>().ToList();
|
||||
return _anchors;
|
||||
}
|
||||
}
|
||||
public IEnumerable<Anchor> InputAnchors => Anchors.Where(a => a.IsInput);
|
||||
@@ -30,30 +30,31 @@ namespace CompuLogic.Workspace
|
||||
public BoxCollider2D Box {
|
||||
get
|
||||
{
|
||||
if (_box == null)
|
||||
_box = GetComponentInChildren<BoxCollider2D>();
|
||||
return _box;
|
||||
if (_box == null)
|
||||
_box = GetComponentInChildren<BoxCollider2D>();
|
||||
return _box;
|
||||
}
|
||||
}
|
||||
public GateSprite Sprite
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_sprite == null)
|
||||
_sprite = GetComponentInChildren<GateSprite>();
|
||||
return _sprite;
|
||||
if(_sprite == null)
|
||||
_sprite = GetComponentInChildren<GateSprite>();
|
||||
return _sprite;
|
||||
}
|
||||
}
|
||||
public GateDefinition Definition
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_definition == null)
|
||||
_definition = GateDefinition.Get(GateType, this);
|
||||
return _definition;
|
||||
if(_definition == null)
|
||||
_definition = GateDefinition.Get(GateType, this);
|
||||
return _definition;
|
||||
}
|
||||
}
|
||||
public string UIName { get; set; }
|
||||
public List<float> CustomProperties;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -89,7 +90,7 @@ namespace CompuLogic.Workspace
|
||||
return !Definition.HasState && (
|
||||
InputAnchors.Contains(target) ||
|
||||
InputAnchors.Any(a => a.HasInputAnchor(target))
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -101,8 +102,8 @@ namespace CompuLogic.Workspace
|
||||
var state = Definition.GetState(this).ToInt();
|
||||
if (state != _lastState)
|
||||
{
|
||||
Definition.Compute(this);
|
||||
_lastState = state;
|
||||
Definition.Compute(this);
|
||||
_lastState = state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace CompuLogic.Workspace
|
||||
}
|
||||
|
||||
gate.GateType = (GateType)key;
|
||||
gate.CustomProperties = item.Properties;
|
||||
|
||||
gate.UIName = string.IsNullOrEmpty(item.Name) ? gate.GateType.ToString() : item.Name;
|
||||
|
||||
@@ -146,6 +147,7 @@ namespace CompuLogic.Workspace
|
||||
public List<string> Output { get; set; }
|
||||
public List<GateBookItemAnchor> InputAnchors => Input.Select(i => i.Split(new char[0])).Select(GateBookItemAnchor.Get).ToList();
|
||||
public List<GateBookItemAnchor> OutputAnchors => Output.Select(i => i.Split(new char[0])).Select(GateBookItemAnchor.Get).ToList();
|
||||
public List<float> Properties;
|
||||
}
|
||||
|
||||
public class GateBookItemAnchor
|
||||
|
||||
@@ -15,12 +15,20 @@ namespace CompuLogic.Workspace.Gates
|
||||
|
||||
#endregion
|
||||
|
||||
#region 100 - Special
|
||||
#region 100 - I/O
|
||||
|
||||
internal class INGate : NoneGate { }
|
||||
|
||||
internal class OUTGate : NoneGate { }
|
||||
|
||||
internal class CLK1Gate : NoneGate { }
|
||||
|
||||
internal class CLK2Gate : NoneGate { }
|
||||
|
||||
internal class CLK3Gate : NoneGate { }
|
||||
|
||||
internal class CLK4Gate : NoneGate { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 200 - Basic
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
// 100 - I/O
|
||||
IN = 100,
|
||||
OUT = 110,
|
||||
CLK1 = 120,
|
||||
CLK2 = 130,
|
||||
CLK3 = 140,
|
||||
CLK4 = 150,
|
||||
// 200 - Basic
|
||||
BUF = 200,
|
||||
AND = 210,
|
||||
|
||||
Reference in New Issue
Block a user