From ac85bdcdf2ec4ebb60c6aa73e7d7f0019d509ff1 Mon Sep 17 00:00:00 2001 From: klemek Date: Tue, 22 Dec 2020 18:03:27 +0100 Subject: [PATCH] clocks --- Assets/Prefabs/UI/Base UI Button.prefab | 4 +- Assets/Scenes/Workspace.unity | 1 + Assets/Scripts/Workspace/ClockGate.cs | 70 ++++++++++ Assets/Scripts/Workspace/ClockGate.cs.meta | 11 ++ Assets/Scripts/Workspace/Gate.cs | 31 +++-- Assets/Scripts/Workspace/GatePrefabFactory.cs | 2 + .../Workspace/Gates/GateDefinitionList.cs | 10 +- Assets/Scripts/Workspace/Gates/GateType.cs | 4 + Assets/Texts/gates.yaml | 36 +++++ Assets/Textures/Gates/clk.png | Bin 0 -> 996 bytes Assets/Textures/Gates/clk.png.meta | 130 ++++++++++++++++++ SVG/Gates/clk.svg | 36 +++++ TODO.txt | 1 - 13 files changed, 317 insertions(+), 19 deletions(-) create mode 100755 Assets/Scripts/Workspace/ClockGate.cs create mode 100755 Assets/Scripts/Workspace/ClockGate.cs.meta create mode 100644 Assets/Textures/Gates/clk.png create mode 100755 Assets/Textures/Gates/clk.png.meta create mode 100755 SVG/Gates/clk.svg diff --git a/Assets/Prefabs/UI/Base UI Button.prefab b/Assets/Prefabs/UI/Base UI Button.prefab index bfe5e15..a946f7c 100755 --- a/Assets/Prefabs/UI/Base UI Button.prefab +++ b/Assets/Prefabs/UI/Base UI Button.prefab @@ -109,8 +109,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: -1.5} + m_SizeDelta: {x: -10, y: -7} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &6470588784042037404 CanvasRenderer: diff --git a/Assets/Scenes/Workspace.unity b/Assets/Scenes/Workspace.unity index ab1efcd..928abcf 100755 --- a/Assets/Scenes/Workspace.unity +++ b/Assets/Scenes/Workspace.unity @@ -539,6 +539,7 @@ MonoBehaviour: - {fileID: 21300000, guid: b77c21ad464eb5c45a4a1f8f0f276965, type: 3} - {fileID: 21300000, guid: 3aa2b0925144bb54193b25bf37dddf91, type: 3} - {fileID: 21300000, guid: 9ade58a4f17ab5a49bebda61d08ee88e, type: 3} + - {fileID: 21300000, guid: b5f750949f494f64b8baf51ddce0cddc, type: 3} --- !u!4 &535412053 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Workspace/ClockGate.cs b/Assets/Scripts/Workspace/ClockGate.cs new file mode 100755 index 0000000..da9f7d0 --- /dev/null +++ b/Assets/Scripts/Workspace/ClockGate.cs @@ -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 + } + +} diff --git a/Assets/Scripts/Workspace/ClockGate.cs.meta b/Assets/Scripts/Workspace/ClockGate.cs.meta new file mode 100755 index 0000000..2cf4438 --- /dev/null +++ b/Assets/Scripts/Workspace/ClockGate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e96ac3a8b8e052746ab27ed052bf1f13 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Workspace/Gate.cs b/Assets/Scripts/Workspace/Gate.cs index 1bbcab7..d1407af 100755 --- a/Assets/Scripts/Workspace/Gate.cs +++ b/Assets/Scripts/Workspace/Gate.cs @@ -20,9 +20,9 @@ namespace CompuLogic.Workspace { get { - if(_anchors == null) - _anchors = GetComponentsInChildren().ToList(); - return _anchors; + if(_anchors == null) + _anchors = GetComponentsInChildren().ToList(); + return _anchors; } } public IEnumerable InputAnchors => Anchors.Where(a => a.IsInput); @@ -30,30 +30,31 @@ namespace CompuLogic.Workspace public BoxCollider2D Box { get { - if (_box == null) - _box = GetComponentInChildren(); - return _box; + if (_box == null) + _box = GetComponentInChildren(); + return _box; } } public GateSprite Sprite { get { - if(_sprite == null) - _sprite = GetComponentInChildren(); - return _sprite; + if(_sprite == null) + _sprite = GetComponentInChildren(); + 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 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; } } diff --git a/Assets/Scripts/Workspace/GatePrefabFactory.cs b/Assets/Scripts/Workspace/GatePrefabFactory.cs index bee74bf..576e474 100755 --- a/Assets/Scripts/Workspace/GatePrefabFactory.cs +++ b/Assets/Scripts/Workspace/GatePrefabFactory.cs @@ -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 Output { get; set; } public List InputAnchors => Input.Select(i => i.Split(new char[0])).Select(GateBookItemAnchor.Get).ToList(); public List OutputAnchors => Output.Select(i => i.Split(new char[0])).Select(GateBookItemAnchor.Get).ToList(); + public List Properties; } public class GateBookItemAnchor diff --git a/Assets/Scripts/Workspace/Gates/GateDefinitionList.cs b/Assets/Scripts/Workspace/Gates/GateDefinitionList.cs index af2f273..32d35f2 100755 --- a/Assets/Scripts/Workspace/Gates/GateDefinitionList.cs +++ b/Assets/Scripts/Workspace/Gates/GateDefinitionList.cs @@ -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 diff --git a/Assets/Scripts/Workspace/Gates/GateType.cs b/Assets/Scripts/Workspace/Gates/GateType.cs index f64ff2c..a8044df 100755 --- a/Assets/Scripts/Workspace/Gates/GateType.cs +++ b/Assets/Scripts/Workspace/Gates/GateType.cs @@ -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, diff --git a/Assets/Texts/gates.yaml b/Assets/Texts/gates.yaml index b61fdae..102c527 100755 --- a/Assets/Texts/gates.yaml +++ b/Assets/Texts/gates.yaml @@ -13,6 +13,42 @@ list: class: OutputGate input: - A 1.5 1.5 W big + 120: + skin: clk + name: CLK 1Hz + width: 3 + height: 3 + class: ClockGate + output: + - Q 2.5 1.5 E + properties: [ 1 ] + 130: + skin: clk + name: CLK 5Hz + width: 3 + height: 3 + class: ClockGate + output: + - Q 2.5 1.5 E + properties: [ 0.2 ] + 140: + skin: clk + name: CLK 10Hz + width: 3 + height: 3 + class: ClockGate + output: + - Q 2.5 1.5 E + properties: [ 0.1 ] + 150: + skin: clk + name: CLK 50Hz + width: 3 + height: 3 + class: ClockGate + output: + - Q 2.5 1.5 E + properties: [ 0.02 ] 200: skin: buffer width: 3 diff --git a/Assets/Textures/Gates/clk.png b/Assets/Textures/Gates/clk.png new file mode 100644 index 0000000000000000000000000000000000000000..acab177ab80356dafb5f84da64e06c955e15a913 GIT binary patch literal 996 zcmeAS@N?(olHy`uVBq!ia0y~yVAKI&4mO}jWo=(6kYX$ja(7}_cTVOd0|WCsPZ!6K ziaBrZ9LzmzAmHj~9PnS)SXZNO;nmG)T0fSz+X~d|1?nLIJa~WYOM~#YFANnEqRk(s zS1}xjY+_B}5SySF;n0@AC`l5h(1(A=t$X`Ao>#9aeXW1P{#+~BMv-GZ#d?75Uy!=i z)b`=DZ}%<>%N@k){EC-#6aDuKeBU%ny(kf1K*jAc&U$rp-~N}gW5@_o;yrcD(6-_G znyt&!4?M+h(e!sVm+n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TODO.txt b/TODO.txt index a78be6a..e36f5ca 100755 --- a/TODO.txt +++ b/TODO.txt @@ -2,7 +2,6 @@ TODO -(1) finish gate book -(1) mux/demux svg -(1) change fonts --(3) clocks (1Hz, 5Hz, 10Hz, etc.) -(3) cable overlap (same/diff circuit) -(5) cable management -(5) buses