finished gate book

This commit is contained in:
klemek
2020-12-22 19:11:55 +01:00
parent ac85bdcdf2
commit 13718af6da
9 changed files with 232 additions and 45 deletions
+4 -4
View File
@@ -69,10 +69,10 @@ namespace CompuLogic.UI
{
if (PointerManager.Instance.Interacting != _lastMouseInteracting)
{
//TODO animate go down
GateBar.SetActive(!PointerManager.Instance.Interacting);
MovingBar.SetActive(PointerManager.Instance.MovingObject);
_lastMouseInteracting = PointerManager.Instance.Interacting;
//TODO animate go down
GateBar.SetActive(!PointerManager.Instance.Interacting);
MovingBar.SetActive(PointerManager.Instance.MovingObject);
_lastMouseInteracting = PointerManager.Instance.Interacting;
}
}
+8 -5
View File
@@ -48,10 +48,13 @@ namespace CompuLogic.Workspace
{
Text.text = Name;
var rect = Text.GetComponent<RectTransform>();
rect.localRotation = (Mathf.Abs(Orientation.y) > Mathf.Epsilon) ? Quaternion.AngleAxis(90f, Vector3.forward) : Quaternion.identity;
rect.localPosition = new Vector3(Orientation.x, Orientation.y, 0f) * TextSpace;
Text.alignment = (Orientation.x < -Mathf.Epsilon || Orientation.y < -Mathf.Epsilon) ? TextAlignmentOptions.MidlineRight : TextAlignmentOptions.MidlineLeft;
var rotate = (Mathf.Abs(Orientation.y) > Mathf.Epsilon && Name.Length > 1);
rect.localRotation = rotate ? Quaternion.AngleAxis(90f, Vector3.forward) : Quaternion.identity;
rect.localPosition = new Vector3(Orientation.x, Orientation.y, 0f) * -TextSpace;
if (!rotate && Mathf.Abs(Orientation.y) > Mathf.Epsilon)
Text.alignment = (Orientation.y < -Mathf.Epsilon) ? TextAlignmentOptions.Bottom : TextAlignmentOptions.Top;
else
Text.alignment = (Orientation.x < -Mathf.Epsilon || Orientation.y < -Mathf.Epsilon) ? TextAlignmentOptions.MidlineLeft : TextAlignmentOptions.MidlineRight;
}
}
}
@@ -95,7 +98,7 @@ namespace CompuLogic.Workspace
Utils.RandomName($"{Gate.GateType}_{Name}", gameObject);
_scale = Sprite.transform.localScale;
Cables = new List<Cable>();
Orientation = Orientation.normalized;
//Orientation = Orientation.normalized;
}
// Update is called once per frame
+8 -8
View File
@@ -137,14 +137,14 @@ namespace CompuLogic.Workspace
else
{
var startOr = StartAnchor.Orientation;
var endOr = StartAnchor.Orientation;
var endOr = EndAnchor.Orientation;
_line.positionCount = 4;
_line.SetPosition(0, startPos);
if (Mathf.Abs(startOr.x) > 0)
if (Mathf.Abs(startOr.x) > Mathf.Epsilon)
{
if (Mathf.Abs(endOr.x) > 0)
if (Mathf.Abs(endOr.x) > Mathf.Epsilon)
{
var middle = (startPos.x + endPos.x) / 2;
_line.SetPosition(1, new Vector3(middle, startPos.y, startPos.z));
@@ -152,13 +152,13 @@ namespace CompuLogic.Workspace
}
else
{
_line.SetPosition(1, new Vector3(startPos.x, endPos.y, startPos.z));
_line.SetPosition(2, new Vector3(startPos.x, endPos.y, startPos.z));
_line.SetPosition(1, new Vector3(endPos.x, startPos.y, startPos.z));
_line.SetPosition(2, new Vector3(endPos.x, startPos.y, startPos.z));
}
}
else
{
if (Mathf.Abs(endOr.x) > 0)
if (Mathf.Abs(endOr.x) > Mathf.Epsilon)
{
var middle = (startPos.y + endPos.y) / 2;
_line.SetPosition(1, new Vector3(startPos.x, middle, startPos.z));
@@ -166,8 +166,8 @@ namespace CompuLogic.Workspace
}
else
{
_line.SetPosition(1, new Vector3(endPos.x, startPos.y, startPos.z));
_line.SetPosition(2, new Vector3(endPos.x, startPos.y, startPos.z));
_line.SetPosition(1, new Vector3(startPos.x, endPos.y, startPos.z));
_line.SetPosition(2, new Vector3(startPos.x, endPos.y, startPos.z));
}
}
@@ -158,7 +158,7 @@ namespace CompuLogic.Workspace
public string Orientation { get; set; }
public bool Big { get; set; }
public Vector2 OrientationV => new Vector2(
Orientation == "W" ? 1 : (Orientation == "E" ? -1 : 0),
Orientation == "W" ? -1 : (Orientation == "E" ? 1 : 0),
Orientation == "N" ? 1 : (Orientation == "S" ? -1 : 0)
);
@@ -331,7 +331,7 @@ namespace CompuLogic.Workspace.Gates
internal class MuxGate : StatelessGateDefinition
{
public override string[] Inputs { get; } = new string[] { "E", "S", "D", "D" };
public override string[] Inputs { get; } = new string[] { "E", "S", "D0", "D1" };
public override string[] Outputs { get; } = new string[] { "Y" };
internal override Func<InputState, OutputState> Function => (input) =>
@@ -350,7 +350,7 @@ namespace CompuLogic.Workspace.Gates
internal class DemuxGate : StatelessGateDefinition
{
public override string[] Inputs { get; } = new string[] { "E", "S", "D" };
public override string[] Outputs { get; } = new string[] { "Y", "Y" };
public override string[] Outputs { get; } = new string[] { "Y0", "Y1" };
internal override Func<InputState, OutputState> Function => (input) =>
{
@@ -367,7 +367,7 @@ namespace CompuLogic.Workspace.Gates
internal class Mux2bGate : StatelessGateDefinition
{
public override string[] Inputs { get; } = new string[] { "E", "S", "S", "D", "D", "D", "D" };
public override string[] Inputs { get; } = new string[] { "E", "S0", "S1", "D0", "D1", "D2", "D3" };
public override string[] Outputs { get; } = new string[] { "Y" };
internal override Func<InputState, OutputState> Function => (input) =>
@@ -393,8 +393,8 @@ namespace CompuLogic.Workspace.Gates
internal class Demux2bGate : StatelessGateDefinition
{
public override string[] Inputs { get; } = new string[] { "E", "S", "S", "D" };
public override string[] Outputs { get; } = new string[] { "Y", "Y", "Y", "Y" };
public override string[] Inputs { get; } = new string[] { "E", "S0", "S1", "D" };
public override string[] Outputs { get; } = new string[] { "Y0", "Y1", "Y2", "Y3" };
internal override Func<InputState, OutputState> Function => (input) =>
{
@@ -414,8 +414,8 @@ namespace CompuLogic.Workspace.Gates
internal class Enc2b4bGate : StatelessGateDefinition
{
public override string[] Inputs { get; } = new string[] { "D", "D" };
public override string[] Outputs { get; } = new string[] { "Y", "Y", "Y", "Y" };
public override string[] Inputs { get; } = new string[] { "D0", "D1" };
public override string[] Outputs { get; } = new string[] { "Y0", "Y1", "Y2", "Y3" };
internal override Func<InputState, OutputState> Function => (input) =>
{
@@ -433,8 +433,8 @@ namespace CompuLogic.Workspace.Gates
internal class Dec4b2bGate : StatelessGateDefinition
{
public override string[] Inputs { get; } = new string[] { "D", "D", "D", "D"};
public override string[] Outputs { get; } = new string[] { "Y", "Y" };
public override string[] Inputs { get; } = new string[] { "D0", "D1", "D2", "D3"};
public override string[] Outputs { get; } = new string[] { "Y0", "Y1" };
internal override Func<InputState, OutputState> Function => (input) =>
{
@@ -484,7 +484,7 @@ namespace CompuLogic.Workspace.Gates
internal class SIPO4bGate : StatefulGateDefinition
{
public override string[] Inputs { get; } = new string[] { "CLK", "D" };
public override string[] Outputs { get; } = new string[] { "Q", "Q", "Q", "Q" };
public override string[] Outputs { get; } = new string[] { "Q0", "Q1", "Q2", "Q3" };
private bool _q0;
private bool _q1;
@@ -510,8 +510,8 @@ namespace CompuLogic.Workspace.Gates
internal class PIPO4bGate : StatefulGateDefinition
{
public override string[] Inputs { get; } = new string[] { "CLK", "D", "D", "D", "D" };
public override string[] Outputs { get; } = new string[] { "Q", "Q", "Q", "Q" };
public override string[] Inputs { get; } = new string[] { "CLK", "D0", "D1", "D2", "D3" };
public override string[] Outputs { get; } = new string[] { "Q0", "Q1", "Q2", "Q3" };
private bool _q0;
private bool _q1;
@@ -545,7 +545,7 @@ namespace CompuLogic.Workspace.Gates
internal class Counter2bGate : StatefulGateDefinition
{
public override string[] Inputs { get; } = new string[] { "CLK", "RST" };
public override string[] Outputs { get; } = new string[] { "Q", "Q" };
public override string[] Outputs { get; } = new string[] { "Q0", "Q1" };
private bool _q0;
private bool _q1;
@@ -576,7 +576,7 @@ namespace CompuLogic.Workspace.Gates
internal class Counter4bGate : StatefulGateDefinition
{
public override string[] Inputs { get; } = new string[] { "CLK", "RST" };
public override string[] Outputs { get; } = new string[] { "Q", "Q", "Q", "Q" };
public override string[] Outputs { get; } = new string[] { "Q0", "Q1", "Q2", "Q3" };
private bool _q0;
private bool _q1;
@@ -599,8 +599,8 @@ namespace CompuLogic.Workspace.Gates
}
else
{
_q3 = (_q3 || _q2 && _q1 && _q0) && (!_q3 && !_q2 && !_q1 && !_q0);
_q2 = (_q2 || _q1 && _q0) && (!_q2 && !_q1 && !_q0);
_q3 = (_q3 || _q2 && _q1 && _q0) && !(_q3 && _q2 && _q1 && _q0);
_q2 = (_q2 || _q1 && _q0) && !(_q2 && _q1 && _q0);
_q1 = _q0 ^ _q1;
_q0 = !_q0;
}
+6 -6
View File
@@ -35,12 +35,12 @@
HalfSub = 520,
FullSub = 530,
// 600 - Data
Mux = 610,
Demux = 620,
Mux2b = 630,
Demux2b = 640,
Enc2b4b = 650,
Dec4b2b = 660,
Mux = 600,
Demux = 610,
Mux2b = 620,
Demux2b = 630,
Enc2b4b = 640,
Dec4b2b = 650,
// 700 - Registers
SISO4b = 700,
SIPO4b = 710,
+13 -3
View File
@@ -20,15 +20,25 @@ namespace CompuLogic
#region Private Properties
private bool _activate;
#endregion
#region Unity Methods
private void Start()
{
_activate = GetComponent<TextMeshPro>().text.Contains("\x305");
}
private void FixedUpdate()
{
var subText = GetComponentInChildren<TMP_SubMesh>();
if(subText != null && Mathf.Abs(subText.transform.localPosition.magnitude) < Mathf.Epsilon)
subText.transform.localPosition = SubTextOffset;
if (_activate)
{
var subText = GetComponentInChildren<TMP_SubMesh>();
if(subText != null && Mathf.Abs(subText.transform.localPosition.magnitude) < Mathf.Epsilon)
subText.transform.localPosition = SubTextOffset;
}
}
#endregion
+175 -1
View File
@@ -199,4 +199,178 @@ list:
- CLK 0.5 5.5 W
output:
- Q 4.5 1.5 E
- Q̅ 4.5 5.5 E
- Q̅ 4.5 5.5 E
500:
name: Half Add.
width: 5
height: 5
input:
- A 0.5 1.5 W
- B 0.5 3.5 W
output:
- S 4.5 1.5 E
- C 4.5 3.5 E
510:
name: Full Add.
width: 5
height: 7
input:
- A 0.5 1.5 W
- B 0.5 3.5 W
- Cɪ 0.5 5.5 W
output:
- S 4.5 1.5 E
- C 4.5 5.5 E
520:
name: Half Sub.
width: 5
height: 5
input:
- A 0.5 1.5 W
- B 0.5 3.5 W
output:
- S 4.5 1.5 E
- C 4.5 3.5 E
530:
name: Full Sub.
width: 5
height: 7
input:
- A 0.5 1.5 W
- B 0.5 3.5 W
- Cɪ 0.5 5.5 W
output:
- S 4.5 1.5 E
- C 4.5 5.5 E
600:
name: Mux.
width: 7
height: 7
input:
- D0 0.5 1.5 W
- D1 0.5 3.5 W
- E 2.5 6.5 S
- S 4.5 6.5 S
output:
- Y 6.5 2.5 E
610:
name: Demux.
width: 7
height: 7
input:
- D 0.5 2.5 W
- E 2.5 6.5 S
- S 4.5 6.5 S
output:
- Y0 6.5 1.5 E
- Y1 6.5 3.5 E
620:
name: 2bits Mux.
width: 7
height: 7
input:
- D0 0.5 1.5 W
- D1 0.5 2.5 W
- D2 0.5 3.5 W
- D3 0.5 4.5 W
- E 2.5 6.5 S
- S0 3.5 6.5 S
- S1 4.5 6.5 S
output:
- Y 6.5 3.5 E
630:
name: 2bits Demux.
width: 7
height: 7
input:
- D 0.5 3.5 W
- E 2.5 6.5 S
- S0 3.5 6.5 S
- S1 4.5 6.5 S
output:
- Y0 6.5 1.5 E
- Y1 6.5 2.5 E
- Y2 6.5 3.5 E
- Y3 6.5 4.5 E
640:
name: 2b./4b. Enc.
width: 5
height: 6
input:
- D0 0.5 1.5 W
- D1 0.5 4.5 W
output:
- Y0 4.5 1.5 E
- Y1 4.5 2.5 E
- Y2 4.5 3.5 E
- Y3 4.5 4.5 E
650:
name: 2b./4b. Dec.
width: 5
height: 6
input:
- D0 0.5 1.5 W
- D1 0.5 2.5 W
- D2 0.5 3.5 W
- D3 0.5 4.5 W
output:
- Y0 4.5 1.5 E
- Y1 4.5 4.5 E
700:
name: 4bits SISO
width: 7
height: 7
input:
- D 0.5 1.5 W
- CLK 3.5 6.5 S
output:
- Q 6.5 1.5 E
710:
name: 4bits SIPO
width: 7
height: 7
input:
- D 0.5 1.5 W
- CLK 3.5 6.5 S
output:
- Q0 6.5 1.5 E
- Q1 6.5 2.5 E
- Q2 6.5 3.5 E
- Q3 6.5 4.5 E
720:
name: 4bits PIPO
width: 7
height: 7
input:
- D0 0.5 1.5 W
- D1 0.5 2.5 W
- D2 0.5 3.5 W
- D3 0.5 4.5 W
- CLK 3.5 6.5 S
output:
- Q0 6.5 1.5 E
- Q1 6.5 2.5 E
- Q2 6.5 3.5 E
- Q3 6.5 4.5 E
800:
name: 2bits Count.
width: 6
height: 5
input:
- CLK 1.5 4.5 S
- RST 2.5 4.5 S
output:
- Q0 5.5 1.5 E
- Q1 5.5 3.5 E
810:
name: 4bits Count.
width: 6
height: 6
input:
- CLK 1.5 5.5 S
- RST 2.5 5.5 S
output:
- Q0 5.5 1.5 E
- Q1 5.5 2.5 E
- Q2 5.5 3.5 E
- Q3 5.5 4.5 E
+1 -1
View File
@@ -1,6 +1,6 @@
TODO
-(1) finish gate book
-(1) mux/demux svg
-(1) show current gate name when moving
-(1) change fonts
-(3) cable overlap (same/diff circuit)
-(5) cable management