Compare commits
1 Commits
master
...
wip/invert
| Author | SHA1 | Date |
|---|---|---|
|
|
dbfc6eb56b |
|
|
@ -55,48 +55,40 @@ kbd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Layout ─────────────────────────────────────────────────────── */
|
/* ── Layout ─────────────────────────────────────────────────────── */
|
||||||
|
/* The canvas fills the screen; the bars, the parts dock and the side panel float over it. */
|
||||||
.app {
|
.app {
|
||||||
display: grid;
|
|
||||||
grid-template-rows: 48px 1fr;
|
|
||||||
height: 100dvh;
|
|
||||||
}
|
|
||||||
|
|
||||||
.workspace {
|
|
||||||
--left: 236px;
|
|
||||||
--right: 300px;
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: var(--left) 1fr var(--right);
|
|
||||||
min-height: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.workspace.no-left {
|
|
||||||
--left: 36px !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.workspace.no-right {
|
|
||||||
--right: 36px !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stage {
|
|
||||||
position: relative;
|
position: relative;
|
||||||
min-width: 0;
|
height: 100dvh;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workspace {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stage {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.palette,
|
|
||||||
.inspector {
|
.inspector {
|
||||||
background: var(--panel);
|
position: absolute;
|
||||||
min-height: 0;
|
z-index: 25;
|
||||||
|
top: 58px;
|
||||||
|
right: 10px;
|
||||||
|
bottom: 10px;
|
||||||
|
width: 316px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
min-height: 0;
|
||||||
|
background: rgb(19 24 31 / 0.96);
|
||||||
.palette {
|
backdrop-filter: blur(8px);
|
||||||
border-right: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
}
|
border-radius: 12px;
|
||||||
|
box-shadow: 0 18px 50px rgb(0 0 0 / 0.45);
|
||||||
.inspector {
|
overflow: hidden;
|
||||||
border-left: 1px solid var(--border);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.scroll {
|
.scroll {
|
||||||
|
|
@ -107,51 +99,144 @@ kbd {
|
||||||
scrollbar-color: var(--border) transparent;
|
scrollbar-color: var(--border) transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 1100px) {
|
|
||||||
.workspace {
|
|
||||||
--left: 210px;
|
|
||||||
--right: 260px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 820px) {
|
@media (max-width: 820px) {
|
||||||
.workspace {
|
|
||||||
grid-template-columns: 1fr;
|
|
||||||
grid-template-rows: 1fr 40%;
|
|
||||||
}
|
|
||||||
.palette {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.inspector {
|
.inspector {
|
||||||
border-left: 0;
|
top: auto;
|
||||||
border-top: 1px solid var(--border);
|
left: 8px;
|
||||||
|
right: 8px;
|
||||||
|
width: auto;
|
||||||
|
height: 45%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Toolbar ────────────────────────────────────────────────────── */
|
/* ── Top bar ────────────────────────────────────────────────────── */
|
||||||
.toolbar {
|
.hud {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 30;
|
||||||
|
top: 10px;
|
||||||
|
left: 10px;
|
||||||
|
right: 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 10px;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 2px;
|
||||||
|
min-width: 0;
|
||||||
|
height: 38px;
|
||||||
|
padding: 0 4px;
|
||||||
|
background: rgb(19 24 31 / 0.92);
|
||||||
|
backdrop-filter: blur(8px);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 6px 20px rgb(0 0 0 / 0.3);
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-btn {
|
||||||
|
position: relative;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
height: 30px;
|
||||||
|
min-width: 30px;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 0 7px;
|
||||||
|
border-radius: 7px;
|
||||||
|
color: var(--text);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-btn:hover:not(:disabled) {
|
||||||
|
background: var(--panel-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-btn.active {
|
||||||
|
color: var(--accent);
|
||||||
|
background: rgb(76 194 255 / 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-btn:disabled {
|
||||||
|
opacity: 0.35;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-btn.brand {
|
||||||
|
color: var(--on);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-project {
|
||||||
|
max-width: 200px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-sep {
|
||||||
|
width: 1px;
|
||||||
|
height: 18px;
|
||||||
|
margin: 0 4px;
|
||||||
|
background: var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-circuit {
|
||||||
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
|
||||||
gap: 12px;
|
|
||||||
padding: 0 10px;
|
|
||||||
background: var(--panel);
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.brand {
|
.hud-circuit select {
|
||||||
display: flex;
|
appearance: none;
|
||||||
align-items: center;
|
max-width: 220px;
|
||||||
gap: 8px;
|
height: 30px;
|
||||||
font-weight: 700;
|
padding: 0 24px 0 8px;
|
||||||
letter-spacing: -0.01em;
|
border-radius: 7px;
|
||||||
color: var(--on);
|
background: transparent;
|
||||||
padding-right: 6px;
|
color: var(--text);
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.brand span {
|
.hud-circuit select:hover {
|
||||||
|
background: var(--panel-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-circuit svg {
|
||||||
|
position: absolute;
|
||||||
|
right: 6px;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-select {
|
||||||
|
height: 28px;
|
||||||
|
padding: 0 4px;
|
||||||
|
border-radius: 7px;
|
||||||
|
background: var(--panel-2);
|
||||||
|
border: 1px solid var(--border);
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-sim {
|
||||||
|
padding: 0 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-sim .status {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 760px) {
|
||||||
|
.hud-sim {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.hud-project {
|
||||||
|
max-width: 90px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tb-btn {
|
.tb-btn {
|
||||||
|
|
@ -1615,8 +1700,8 @@ kbd {
|
||||||
|
|
||||||
.zoom-controls {
|
.zoom-controls {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 12px;
|
left: 10px;
|
||||||
bottom: 12px;
|
bottom: 10px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 2px;
|
gap: 2px;
|
||||||
|
|
@ -1662,7 +1747,7 @@ kbd {
|
||||||
.toast {
|
.toast {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
bottom: 24px;
|
bottom: 104px;
|
||||||
transform: translateX(-50%);
|
transform: translateX(-50%);
|
||||||
z-index: 60;
|
z-index: 60;
|
||||||
padding: 8px 14px;
|
padding: 8px 14px;
|
||||||
|
|
@ -2292,7 +2377,7 @@ kbd {
|
||||||
/* ── Right panel tabs ───────────────────────────────────────────── */
|
/* ── Right panel tabs ───────────────────────────────────────────── */
|
||||||
.itabs {
|
.itabs {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(4, 1fr);
|
grid-template-columns: repeat(4, 1fr) auto;
|
||||||
border-bottom: 1px solid var(--border);
|
border-bottom: 1px solid var(--border);
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
@ -2643,48 +2728,23 @@ kbd {
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
}
|
}
|
||||||
|
|
||||||
.itabs {
|
.itabs .itabs-tools {
|
||||||
grid-template-columns: 30px repeat(4, 1fr);
|
|
||||||
}
|
|
||||||
|
|
||||||
.rail {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 2px;
|
padding: 0 4px;
|
||||||
padding-top: 6px;
|
|
||||||
background: var(--panel);
|
|
||||||
min-height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.rail.left {
|
|
||||||
border-right: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.rail.right {
|
|
||||||
border-left: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.rail-btn {
|
|
||||||
display: grid;
|
|
||||||
place-items: center;
|
|
||||||
width: 28px;
|
|
||||||
height: 28px;
|
|
||||||
border-radius: 6px;
|
|
||||||
color: var(--muted);
|
|
||||||
}
|
|
||||||
|
|
||||||
.rail-btn:hover {
|
|
||||||
background: var(--panel-2);
|
|
||||||
color: var(--text);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tabs .collapse-btn,
|
|
||||||
.itabs .collapse-btn {
|
.itabs .collapse-btn {
|
||||||
flex: 0 0 30px;
|
flex: 0 0 26px;
|
||||||
flex-direction: row;
|
width: 26px;
|
||||||
|
height: 26px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border-bottom: 2px solid transparent;
|
border: 0;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.itabs .collapse-btn.active {
|
||||||
|
color: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ribbon cable: sleeve, dark core, one thin line per wire in its own colour. */
|
/* Ribbon cable: sleeve, dark core, one thin line per wire in its own colour. */
|
||||||
|
|
@ -3819,3 +3879,440 @@ table.board {
|
||||||
.menu-board .name-row .field {
|
.menu-board .name-row .field {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── Parts dock (bottom) ────────────────────────────────────────── */
|
||||||
|
.dock {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 28;
|
||||||
|
left: 50%;
|
||||||
|
bottom: 10px;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
width: min(940px, calc(100% - 20px));
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* With the side panel open, the dock keeps to the space left of it. */
|
||||||
|
.workspace.with-panel .dock {
|
||||||
|
left: calc((100% - 336px) / 2);
|
||||||
|
width: min(940px, calc(100% - 356px));
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock > * {
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 2px;
|
||||||
|
max-width: 100%;
|
||||||
|
padding: 4px;
|
||||||
|
overflow-x: auto;
|
||||||
|
scrollbar-width: none;
|
||||||
|
background: rgb(19 24 31 / 0.94);
|
||||||
|
backdrop-filter: blur(8px);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow: 0 10px 30px rgb(0 0 0 / 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-cat {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 3px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
min-width: 74px;
|
||||||
|
padding: 6px 8px 5px;
|
||||||
|
border-radius: 9px;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--muted);
|
||||||
|
transition:
|
||||||
|
background 0.12s,
|
||||||
|
color 0.12s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-cat:hover,
|
||||||
|
.dock-cat.active {
|
||||||
|
color: var(--text);
|
||||||
|
background: var(--panel-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-cat.active {
|
||||||
|
box-shadow: inset 0 -2px 0 var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-cat.task > svg {
|
||||||
|
color: var(--lamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-count {
|
||||||
|
position: absolute;
|
||||||
|
top: 3px;
|
||||||
|
right: 6px;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 9px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-sep {
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 1px;
|
||||||
|
height: 30px;
|
||||||
|
margin: 0 4px;
|
||||||
|
background: var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-search {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 150px;
|
||||||
|
height: 40px;
|
||||||
|
padding: 0 10px;
|
||||||
|
border-radius: 9px;
|
||||||
|
color: var(--muted);
|
||||||
|
cursor: text;
|
||||||
|
transition: width 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-search.open,
|
||||||
|
.dock-search:focus-within {
|
||||||
|
width: 220px;
|
||||||
|
background: var(--panel-2);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-search input {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
background: transparent;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text);
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-flyout {
|
||||||
|
width: 100%;
|
||||||
|
background: rgb(19 24 31 / 0.96);
|
||||||
|
backdrop-filter: blur(8px);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow: 0 16px 40px rgb(0 0 0 / 0.45);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-flyout.pinned {
|
||||||
|
border-color: rgb(76 194 255 / 0.35);
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
min-height: 34px;
|
||||||
|
padding: 4px 8px 0 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-title {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-note {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-tabs {
|
||||||
|
display: flex;
|
||||||
|
gap: 2px;
|
||||||
|
overflow-x: auto;
|
||||||
|
scrollbar-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-tabs button {
|
||||||
|
flex-shrink: 0;
|
||||||
|
padding: 4px 9px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-tabs button:hover {
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-tabs button.active {
|
||||||
|
background: var(--panel-2);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-tabs .count {
|
||||||
|
margin-left: 3px;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-progress {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-progress .bar {
|
||||||
|
width: 120px;
|
||||||
|
height: 5px;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: var(--bg);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-progress .bar span {
|
||||||
|
display: block;
|
||||||
|
height: 100%;
|
||||||
|
background: var(--on);
|
||||||
|
}
|
||||||
|
|
||||||
|
.strip-wrap {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.strip {
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 8px 12px 12px;
|
||||||
|
overflow-x: auto;
|
||||||
|
scroll-behavior: smooth;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: var(--border) transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.strip-empty {
|
||||||
|
padding: 28px 8px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.strip-arrow {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 2;
|
||||||
|
top: 0;
|
||||||
|
bottom: 6px;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
width: 32px;
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.strip-arrow.left {
|
||||||
|
left: 0;
|
||||||
|
background: linear-gradient(90deg, rgb(19 24 31) 40%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.strip-arrow.right {
|
||||||
|
right: 0;
|
||||||
|
background: linear-gradient(270deg, rgb(19 24 31) 40%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-slot {
|
||||||
|
position: relative;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 104px;
|
||||||
|
height: 104px;
|
||||||
|
padding: 6px 6px 7px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 10px;
|
||||||
|
background: var(--panel-2);
|
||||||
|
text-align: center;
|
||||||
|
cursor: grab;
|
||||||
|
transition:
|
||||||
|
border-color 0.12s,
|
||||||
|
transform 0.12s,
|
||||||
|
background 0.12s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile:hover,
|
||||||
|
.tile.active {
|
||||||
|
border-color: var(--accent);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile.placing {
|
||||||
|
border-color: var(--accent);
|
||||||
|
background: rgb(76 194 255 / 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile.blocked {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile.blocked:hover {
|
||||||
|
transform: none;
|
||||||
|
border-color: var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-art {
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
flex: 1;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 0;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-thumb {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
max-height: 58px;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-thumb .node.ghost {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-thumb text {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-name {
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.2;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-meta {
|
||||||
|
font-size: 10px;
|
||||||
|
line-height: 1;
|
||||||
|
color: var(--muted);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-lock {
|
||||||
|
position: absolute;
|
||||||
|
top: 6px;
|
||||||
|
right: 6px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-edit {
|
||||||
|
position: absolute;
|
||||||
|
top: 4px;
|
||||||
|
right: 4px;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: var(--panel);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
color: var(--muted);
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.12s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-slot:hover .tile-edit,
|
||||||
|
.tile-edit:focus-visible {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-edit:hover {
|
||||||
|
color: var(--text);
|
||||||
|
border-color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile.add {
|
||||||
|
border-style: dashed;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile.task {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile.task.solved .tile-art {
|
||||||
|
color: var(--on);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile.task.weekly .tile-art,
|
||||||
|
.tile.task.puzzle .tile-art {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile.task.locked {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile.task.current {
|
||||||
|
border-color: var(--lamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-enter-active,
|
||||||
|
.flyout-leave-active {
|
||||||
|
transition:
|
||||||
|
opacity 0.14s,
|
||||||
|
transform 0.14s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flyout-enter-from,
|
||||||
|
.flyout-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(8px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-show {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 28;
|
||||||
|
left: 50%;
|
||||||
|
bottom: 10px;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 5px 12px;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--muted);
|
||||||
|
background: rgb(19 24 31 / 0.92);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dock-show:hover {
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.flyout-enter-active,
|
||||||
|
.flyout-leave-active,
|
||||||
|
.tile {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ const link = computed(() => {
|
||||||
return l && end ? { n: l.at + 1, total: l.queue.length, label: end.label, dir: end.dir } : null
|
return l && end ? { n: l.at + 1, total: l.queue.length, label: end.label, dir: end.dir } : null
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** The side panel: kept open, or open while something is selected. */
|
||||||
|
const panel = computed(() => ed.sidebars.right || ed.selection.value.length + ed.wireSel.value.length > 0)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const stop = ed.startLoop()
|
const stop = ed.startLoop()
|
||||||
onBeforeUnmount(stop)
|
onBeforeUnmount(stop)
|
||||||
|
|
@ -34,18 +37,17 @@ watch(
|
||||||
<template>
|
<template>
|
||||||
<div class="app">
|
<div class="app">
|
||||||
<EditorMainMenu v-if="ed.screen.value === 'menu'" />
|
<EditorMainMenu v-if="ed.screen.value === 'menu'" />
|
||||||
<template v-else>
|
<div v-else class="workspace" :class="{ 'with-panel': panel, 'with-dock': ed.sidebars.left }">
|
||||||
<EditorToolbar />
|
|
||||||
<div class="workspace" :class="{ 'no-left': !ed.sidebars.left, 'no-right': !ed.sidebars.right }">
|
|
||||||
<EditorPalette v-if="ed.sidebars.left" />
|
|
||||||
<EditorRail v-else side="left" />
|
|
||||||
<main class="stage">
|
<main class="stage">
|
||||||
<EditorCanvas />
|
<EditorCanvas />
|
||||||
</main>
|
</main>
|
||||||
<EditorInspector v-if="ed.sidebars.right" />
|
<EditorToolbar />
|
||||||
<EditorRail v-else side="right" />
|
<EditorInspector v-show="panel" />
|
||||||
|
<EditorDock v-if="ed.sidebars.left" />
|
||||||
|
<button v-else class="dock-show" title="Show the parts ([)" @click="ed.toggleSidebar('left', true)">
|
||||||
|
<Icon name="lucide:chevron-up" class="size-4" /> Parts
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
|
||||||
<Transition name="fade">
|
<Transition name="fade">
|
||||||
<div v-if="ed.notice.value" class="toast" :class="ed.notice.value.kind">{{ ed.notice.value.text }}</div>
|
<div v-if="ed.notice.value" class="toast" :class="ed.notice.value.kind">{{ ed.notice.value.text }}</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|
|
||||||
|
|
@ -174,10 +174,18 @@ function bounds(nodes: CircuitNode[]) {
|
||||||
return { x0, y0, x1, y1 }
|
return { x0, y0, x1, y1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The part of the screen the bars at the top and the parts dock at the bottom leave free. */
|
||||||
|
function freeArea() {
|
||||||
|
const top = 56
|
||||||
|
const bottom = ed.sidebars.left ? 92 : 16
|
||||||
|
return { h: Math.max(100, size.h - top - bottom), cy: top + (size.h - top - bottom) / 2 }
|
||||||
|
}
|
||||||
|
|
||||||
function fit() {
|
function fit() {
|
||||||
const nodes = def.value.nodes
|
const nodes = def.value.nodes
|
||||||
|
const area = freeArea()
|
||||||
if (!nodes.length) {
|
if (!nodes.length) {
|
||||||
ed.views[def.value.id] = { x: size.w / 2, y: size.h / 2, zoom: 1.25 }
|
ed.views[def.value.id] = { x: size.w / 2, y: area.cy, zoom: 1.25 }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const { x0, y0, x1, y1 } = bounds(nodes)
|
const { x0, y0, x1, y1 } = bounds(nodes)
|
||||||
|
|
@ -185,7 +193,7 @@ function fit() {
|
||||||
ed.views[def.value.id] = {
|
ed.views[def.value.id] = {
|
||||||
zoom,
|
zoom,
|
||||||
x: size.w / 2 - ((x0 + x1) / 2) * G * zoom,
|
x: size.w / 2 - ((x0 + x1) / 2) * G * zoom,
|
||||||
y: size.h / 2 - ((y0 + y1) / 2) * G * zoom,
|
y: area.cy - ((y0 + y1) / 2) * G * zoom,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,7 +203,7 @@ function fitZoom(): number {
|
||||||
if (!nodes.length) return 1
|
if (!nodes.length) return 1
|
||||||
const { x0, y0, x1, y1 } = bounds(nodes)
|
const { x0, y0, x1, y1 } = bounds(nodes)
|
||||||
const pad = 2
|
const pad = 2
|
||||||
return Math.min(size.w / ((x1 - x0 + 2 * pad) * G), size.h / ((y1 - y0 + 2 * pad) * G))
|
return Math.min(size.w / ((x1 - x0 + 2 * pad) * G), freeArea().h / ((y1 - y0 + 2 * pad) * G))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Zooming out goes at least far enough to see the whole circuit with room around it. */
|
/** Zooming out goes at least far enough to see the whole circuit with room around it. */
|
||||||
|
|
@ -1257,6 +1265,13 @@ function openMenuAt(target: Element, at: Pt, x: number, y: number) {
|
||||||
}
|
}
|
||||||
const onThing = !!(nodeId || wireId || junction)
|
const onThing = !!(nodeId || wireId || junction)
|
||||||
const entries = build(onThing ? { kind: 'selection' } : { kind: 'canvas', at }, canvasOps)
|
const entries = build(onThing ? { kind: 'selection' } : { kind: 'canvas', at }, canvasOps)
|
||||||
|
// On an input pin: its bubble first (the same as Alt + click, which some desktops take for themselves).
|
||||||
|
const pin = target.closest('[data-pin][data-dir="in"]')?.getAttribute('data-pin')
|
||||||
|
const n = nodeId ? nodeMap.value.get(nodeId) : undefined
|
||||||
|
if (pin && n && INVERTIBLE.has(n.kind)) {
|
||||||
|
const on = n.invert?.includes(pin)
|
||||||
|
entries.unshift({ label: on ? 'Take the bubble off this input' : 'Invert this input', icon: 'lucide:circle-dot', keys: 'Alt+click', run: () => ed.toggleInvert(n, pin) }, 'sep')
|
||||||
|
}
|
||||||
menu.value = entries.length ? { x: x + 2, y: y + 2, entries } : null
|
menu.value = entries.length ? { x: x + 2, y: y + 2, entries } : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1538,7 +1553,7 @@ defineExpose({ fit, zoomAt })
|
||||||
|
|
||||||
<div v-if="!def.nodes.length" class="empty-hint">
|
<div v-if="!def.nodes.length" class="empty-hint">
|
||||||
<p class="font-semibold">Empty circuit</p>
|
<p class="font-semibold">Empty circuit</p>
|
||||||
<p>Drag parts in from the left, or press <kbd>N</kbd> for a NAND gate.</p>
|
<p>Pick parts from the bar at the bottom, or press <kbd>N</kbd> for a NAND gate.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="zoom-controls" @pointerdown.stop>
|
<div class="zoom-controls" @pointerdown.stop>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,428 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
// The parts dock at the bottom, like a city builder's: a row of categories;
|
||||||
|
// pointing at one shows its parts in a strip above (scroll it sideways with
|
||||||
|
// the wheel). Click a part, then the canvas, or drag it where it goes.
|
||||||
|
// Clicking a category keeps it open. Typing searches every part.
|
||||||
|
import { shortCount } from '~/lib/logic/analyze'
|
||||||
|
import { CHALLENGES } from '~/lib/logic/challenges'
|
||||||
|
import { campaignProgress, challengeName, challengeOpen, defUsable, isCampaign, KIND_UNLOCK, NEEDS } from '~/lib/logic/progress'
|
||||||
|
import { weekKey, weeklyId } from '~/lib/logic/puzzles'
|
||||||
|
import { BASIC_GROUPS } from '~/composables/useParts'
|
||||||
|
import type { ComponentDef, NodeKind } from '~/lib/logic/types'
|
||||||
|
|
||||||
|
const ed = useEditor()
|
||||||
|
const { componentGroups, search } = useParts()
|
||||||
|
|
||||||
|
interface Tile {
|
||||||
|
id: string
|
||||||
|
kind: NodeKind
|
||||||
|
chip?: string
|
||||||
|
name: string
|
||||||
|
hint: string
|
||||||
|
/** Small text under the name: its key, transistors, "editing". */
|
||||||
|
meta?: string
|
||||||
|
/** Why it cannot be placed right now. */
|
||||||
|
blocked?: string
|
||||||
|
/** A component that can be opened for editing. */
|
||||||
|
edit?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Task {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
hint: string
|
||||||
|
state: 'solved' | 'open' | 'locked' | 'weekly' | 'puzzle'
|
||||||
|
meta?: string
|
||||||
|
run: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
type CatId = 'search' | 'logic' | 'inputs' | 'outputs' | 'wiring' | 'components' | 'challenges'
|
||||||
|
|
||||||
|
// ── What is in each category ──────────────────────────────────────
|
||||||
|
function lockedHint(kind: NodeKind) {
|
||||||
|
const by = KIND_UNLOCK[kind]
|
||||||
|
return by ? `Solve the ${challengeName(by)} challenge to unlock this part` : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const basic = (group: string): Tile[] =>
|
||||||
|
(BASIC_GROUPS.find(g => g.name === group)?.parts ?? []).map(p => ({
|
||||||
|
id: p.kind,
|
||||||
|
kind: p.kind,
|
||||||
|
name: p.name,
|
||||||
|
hint: p.hint,
|
||||||
|
meta: p.kind === 'nand' ? '4 transistors' : p.key ? `key ${p.key}` : undefined,
|
||||||
|
blocked: ed.canPlaceKind(p.kind) ? undefined : lockedHint(p.kind),
|
||||||
|
}))
|
||||||
|
|
||||||
|
function compTile(d: ComponentDef): Tile {
|
||||||
|
const editing = d.id === ed.def.value.id
|
||||||
|
const t = ed.transistors(d.id)
|
||||||
|
let blocked: string | undefined
|
||||||
|
if (editing) blocked = 'You are editing this one'
|
||||||
|
else if (!defUsable(ed.project.value, d)) blocked = 'Solve this challenge to use it as a part'
|
||||||
|
else if (!ed.canPlace(d.id)) blocked = 'It contains the circuit you are editing'
|
||||||
|
return {
|
||||||
|
id: d.id,
|
||||||
|
kind: 'chip',
|
||||||
|
chip: d.id,
|
||||||
|
name: d.name,
|
||||||
|
hint: d.description || 'Click, then click on the canvas to place',
|
||||||
|
meta: editing ? 'editing' : t ? `${shortCount(t)} transistors` : undefined,
|
||||||
|
blocked,
|
||||||
|
edit: !editing,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Components drawn like gates go with NAND under Logic; the rest under Components. */
|
||||||
|
const GATE_GROUP = 'Gates'
|
||||||
|
const compTabs = computed(() => componentGroups.value.filter(g => g.name !== GATE_GROUP))
|
||||||
|
const compTab = ref('')
|
||||||
|
const compTiles = computed(() => {
|
||||||
|
const tabs = compTabs.value
|
||||||
|
const g = tabs.find(t => t.name === compTab.value) ?? tabs[0]
|
||||||
|
return g ? g.defs.map(compTile) : []
|
||||||
|
})
|
||||||
|
|
||||||
|
const tiles = computed<Record<Exclude<CatId, 'challenges' | 'search'>, Tile[]>>(() => ({
|
||||||
|
logic: [...basic('Logic'), ...(componentGroups.value.find(g => g.name === GATE_GROUP)?.defs.map(compTile) ?? [])],
|
||||||
|
inputs: basic('Inputs'),
|
||||||
|
outputs: basic('Outputs'),
|
||||||
|
wiring: [...basic('Wiring'), ...basic('Notes')],
|
||||||
|
components: compTiles.value,
|
||||||
|
}))
|
||||||
|
|
||||||
|
const CATS: { id: Exclude<CatId, 'search'>; name: string; icon: string; key?: string }[] = [
|
||||||
|
{ id: 'logic', name: 'Logic', icon: 'lucide:square-function' },
|
||||||
|
{ id: 'inputs', name: 'Inputs', icon: 'lucide:toggle-left' },
|
||||||
|
{ id: 'outputs', name: 'Outputs', icon: 'lucide:lightbulb' },
|
||||||
|
{ id: 'wiring', name: 'Wiring', icon: 'lucide:cable' },
|
||||||
|
{ id: 'components', name: 'Components', icon: 'lucide:boxes' },
|
||||||
|
{ id: 'challenges', name: 'Challenges', icon: 'lucide:target' },
|
||||||
|
]
|
||||||
|
|
||||||
|
// ── Challenges and puzzles ────────────────────────────────────────
|
||||||
|
const solved = computed(() => new Set(ed.project.value.solved))
|
||||||
|
const solvedCount = computed(() => CHALLENGES.filter(c => solved.value.has(c.id)).length)
|
||||||
|
const campaign = computed(() => isCampaign(ed.project.value))
|
||||||
|
const started = computed(() => new Map(ed.project.value.components.filter(d => d.challenge).map(d => [d.challenge!, d])))
|
||||||
|
|
||||||
|
function openWeekly() {
|
||||||
|
const spec = ed.project.value.puzzles?.find(p => p.id === weeklyId(weekKey()))
|
||||||
|
if (spec) ed.beginPuzzle(spec)
|
||||||
|
else void ed.openPuzzle('weekly')
|
||||||
|
}
|
||||||
|
|
||||||
|
const tasks = computed<Task[]>(() => {
|
||||||
|
const best = ed.project.value.best ?? {}
|
||||||
|
const out: Task[] = [
|
||||||
|
{
|
||||||
|
id: 'weekly',
|
||||||
|
name: 'Puzzle of the week',
|
||||||
|
hint: 'A new logic puzzle every Monday, the same for everyone. Fewest transistors wins.',
|
||||||
|
state: 'weekly',
|
||||||
|
meta: started.value.has(weeklyId(weekKey())) ? 'open it' : 'new',
|
||||||
|
run: openWeekly,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
const puzzles = (ed.project.value.puzzles ?? []).filter(p => !p.id.startsWith('week:'))
|
||||||
|
for (const p of puzzles)
|
||||||
|
out.push({ id: p.id, name: p.name, hint: p.goal, state: solved.value.has(p.id) ? 'solved' : 'puzzle', meta: best[p.id] !== undefined ? `best ${best[p.id]}` : 'puzzle', run: () => ed.beginPuzzle(p) })
|
||||||
|
for (const c of CHALLENGES) {
|
||||||
|
const open = challengeOpen(ed.project.value, c.id) || started.value.has(c.id)
|
||||||
|
const needs = `Solve ${(NEEDS[c.id] ?? []).filter(n => !solved.value.has(n)).map(challengeName).join(' and ')} first`
|
||||||
|
out.push({
|
||||||
|
id: c.id,
|
||||||
|
name: c.name,
|
||||||
|
hint: open ? `${c.goal}\n${c.inputs.join(', ')} → ${c.outputs.join(', ')}` : needs,
|
||||||
|
state: solved.value.has(c.id) ? 'solved' : open ? 'open' : 'locked',
|
||||||
|
meta: best[c.id] !== undefined ? `best ${best[c.id]}` : open ? (started.value.has(c.id) ? 'started' : undefined) : 'locked',
|
||||||
|
run: () => ed.beginChallenge(c),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
})
|
||||||
|
const TASK_ICON: Record<Task['state'], string> = {
|
||||||
|
solved: 'lucide:circle-check',
|
||||||
|
open: 'lucide:circle',
|
||||||
|
locked: 'lucide:lock',
|
||||||
|
weekly: 'lucide:calendar-days',
|
||||||
|
puzzle: 'lucide:puzzle',
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Opening and closing ───────────────────────────────────────────
|
||||||
|
const shown = ref<CatId | null>(null)
|
||||||
|
const pinned = ref(false)
|
||||||
|
let closeTimer: ReturnType<typeof setTimeout> | undefined
|
||||||
|
let openTimer: ReturnType<typeof setTimeout> | undefined
|
||||||
|
|
||||||
|
function hover(id: CatId) {
|
||||||
|
clearTimeout(closeTimer)
|
||||||
|
clearTimeout(openTimer)
|
||||||
|
if (pinned.value && shown.value !== id) return
|
||||||
|
// Already open: follow the pointer at once; otherwise wait a moment, so passing over does not flash.
|
||||||
|
if (shown.value) shown.value = id
|
||||||
|
else openTimer = setTimeout(() => (shown.value = id), 90)
|
||||||
|
}
|
||||||
|
|
||||||
|
function click(id: CatId) {
|
||||||
|
clearTimeout(openTimer)
|
||||||
|
if (shown.value === id && pinned.value) return close()
|
||||||
|
shown.value = id
|
||||||
|
pinned.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function leave() {
|
||||||
|
clearTimeout(openTimer)
|
||||||
|
if (pinned.value || ed.dragPart.value || searching.value) return
|
||||||
|
closeTimer = setTimeout(close, 280)
|
||||||
|
}
|
||||||
|
|
||||||
|
function stay() {
|
||||||
|
clearTimeout(closeTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
clearTimeout(closeTimer)
|
||||||
|
shown.value = null
|
||||||
|
pinned.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchEl = ref<HTMLInputElement>()
|
||||||
|
const query = ref('')
|
||||||
|
const focused = ref(false)
|
||||||
|
const searching = computed(() => focused.value || !!query.value.trim())
|
||||||
|
const at = ref(0)
|
||||||
|
const hits = computed<Tile[]>(() =>
|
||||||
|
search(query.value, 40).map(h => ({ id: h.chip ?? h.kind, kind: h.kind, chip: h.chip, name: h.name, hint: h.group, meta: h.key ? `key ${h.key}` : h.group })),
|
||||||
|
)
|
||||||
|
watch(query, () => {
|
||||||
|
at.value = 0
|
||||||
|
if (query.value.trim()) shown.value = 'search'
|
||||||
|
})
|
||||||
|
watch(focused, f => {
|
||||||
|
if (f) shown.value = 'search'
|
||||||
|
else if (shown.value === 'search' && !query.value.trim()) close()
|
||||||
|
})
|
||||||
|
// "/" on the canvas, or a request from elsewhere, puts the cursor here.
|
||||||
|
watch(
|
||||||
|
() => ed.partSearch.value,
|
||||||
|
() => {
|
||||||
|
ed.toggleSidebar('left', true)
|
||||||
|
nextTick(() => {
|
||||||
|
searchEl.value?.focus()
|
||||||
|
searchEl.value?.select()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
function onSearchKey(e: KeyboardEvent) {
|
||||||
|
e.stopPropagation()
|
||||||
|
const n = hits.value.length
|
||||||
|
if (['ArrowRight', 'ArrowDown', 'ArrowLeft', 'ArrowUp'].includes(e.key)) {
|
||||||
|
e.preventDefault()
|
||||||
|
if (n) at.value = (at.value + (e.key === 'ArrowRight' || e.key === 'ArrowDown' ? 1 : -1) + n) % n
|
||||||
|
nextTick(() => strip.value?.querySelector('.tile.active')?.scrollIntoView({ inline: 'nearest', block: 'nearest' }))
|
||||||
|
} else if (e.key === 'Enter') {
|
||||||
|
e.preventDefault()
|
||||||
|
const h = hits.value[at.value]
|
||||||
|
if (h) pick(h)
|
||||||
|
} else if (e.key === 'Escape') {
|
||||||
|
query.value = ''
|
||||||
|
searchEl.value?.blur()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const list = computed<Tile[]>(() => {
|
||||||
|
const s = shown.value
|
||||||
|
if (!s || s === 'challenges') return []
|
||||||
|
return s === 'search' ? hits.value : tiles.value[s]
|
||||||
|
})
|
||||||
|
|
||||||
|
// ── Using a tile ──────────────────────────────────────────────────
|
||||||
|
function pick(t: Tile) {
|
||||||
|
if (t.blocked) {
|
||||||
|
ed.play('error')
|
||||||
|
return ed.notify(t.blocked, 'error')
|
||||||
|
}
|
||||||
|
ed.placing.value = { kind: t.kind, chip: t.chip }
|
||||||
|
query.value = ''
|
||||||
|
searchEl.value?.blur()
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDragStart(e: DragEvent, t: Tile) {
|
||||||
|
if (t.blocked) return e.preventDefault()
|
||||||
|
e.dataTransfer?.setData('application/x-logigate', JSON.stringify({ kind: t.kind, chip: t.chip }))
|
||||||
|
if (e.dataTransfer) e.dataTransfer.effectAllowed = 'copy'
|
||||||
|
ed.dragPart.value = { kind: t.kind, chip: t.chip }
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDragEnd() {
|
||||||
|
ed.dragPart.value = null
|
||||||
|
if (!pinned.value) close()
|
||||||
|
}
|
||||||
|
|
||||||
|
function runTask(t: Task) {
|
||||||
|
if (t.state === 'locked') {
|
||||||
|
ed.play('error')
|
||||||
|
return ed.notify(t.hint, 'error')
|
||||||
|
}
|
||||||
|
t.run()
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Sideways scrolling ────────────────────────────────────────────
|
||||||
|
const strip = ref<HTMLElement>()
|
||||||
|
const edges = ref({ left: false, right: false })
|
||||||
|
function measure() {
|
||||||
|
const el = strip.value
|
||||||
|
if (!el) return
|
||||||
|
edges.value = { left: el.scrollLeft > 4, right: el.scrollLeft + el.clientWidth < el.scrollWidth - 4 }
|
||||||
|
}
|
||||||
|
function onWheel(e: WheelEvent) {
|
||||||
|
const el = strip.value
|
||||||
|
if (!el || Math.abs(e.deltaX) > Math.abs(e.deltaY)) return
|
||||||
|
e.preventDefault()
|
||||||
|
el.scrollLeft += e.deltaY
|
||||||
|
}
|
||||||
|
function page(dir: number) {
|
||||||
|
strip.value?.scrollBy({ left: dir * strip.value.clientWidth * 0.8, behavior: 'smooth' })
|
||||||
|
}
|
||||||
|
watch([shown, compTab, () => list.value.length], () => nextTick(measure))
|
||||||
|
|
||||||
|
const title = computed(() => {
|
||||||
|
const s = shown.value
|
||||||
|
if (s === 'search') return query.value.trim() ? `Parts matching "${query.value.trim()}"` : 'Recent and basic parts'
|
||||||
|
return CATS.find(c => c.id === s)?.name ?? ''
|
||||||
|
})
|
||||||
|
|
||||||
|
// Escape closes a strip that was clicked open.
|
||||||
|
function onKey(e: KeyboardEvent) {
|
||||||
|
if (e.key === 'Escape' && shown.value && !searching.value) close()
|
||||||
|
}
|
||||||
|
onMounted(() => window.addEventListener('keydown', onKey))
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener('keydown', onKey)
|
||||||
|
clearTimeout(closeTimer)
|
||||||
|
clearTimeout(openTimer)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="dock" @pointerleave="leave" @pointerenter="stay">
|
||||||
|
<Transition name="flyout">
|
||||||
|
<section v-if="shown" class="dock-flyout" :class="{ pinned }" :aria-label="title">
|
||||||
|
<header class="flyout-head">
|
||||||
|
<span class="flyout-title">{{ title }}</span>
|
||||||
|
<template v-if="shown === 'components' && compTabs.length > 1">
|
||||||
|
<div class="flyout-tabs" role="tablist">
|
||||||
|
<button
|
||||||
|
v-for="(g, i) in compTabs"
|
||||||
|
:key="g.name"
|
||||||
|
role="tab"
|
||||||
|
:aria-selected="(compTab || compTabs[0]!.name) === g.name"
|
||||||
|
:class="{ active: (compTab || compTabs[0]!.name) === g.name || (!compTab && i === 0) }"
|
||||||
|
@click="compTab = g.name"
|
||||||
|
>
|
||||||
|
{{ g.name }} <span class="count">{{ g.defs.length }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-if="shown === 'challenges'">
|
||||||
|
<span v-if="campaign" class="flyout-progress" :title="`${solvedCount} of ${CHALLENGES.length} solved`">
|
||||||
|
<span class="bar"><span :style="{ width: `${campaignProgress(ed.project.value) * 100}%` }" /></span>
|
||||||
|
{{ solvedCount }}/{{ CHALLENGES.length }}
|
||||||
|
</span>
|
||||||
|
<span v-else class="flyout-note">{{ solvedCount }}/{{ CHALLENGES.length }} solved</span>
|
||||||
|
</template>
|
||||||
|
<span v-else-if="shown === 'search'" class="flyout-note">← → choose · Enter place</span>
|
||||||
|
<span v-else class="flyout-note">Click, then click the canvas · or drag</span>
|
||||||
|
<button v-if="pinned" class="icon-btn ml-auto" title="Close (Esc)" @click="close"><Icon name="lucide:x" class="size-3.5" /></button>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="strip-wrap">
|
||||||
|
<button v-if="edges.left" class="strip-arrow left" title="Scroll left" @click="page(-1)"><Icon name="lucide:chevron-left" class="size-4" /></button>
|
||||||
|
<div ref="strip" class="strip" @wheel="onWheel" @scroll="measure">
|
||||||
|
<template v-if="shown === 'challenges'">
|
||||||
|
<button
|
||||||
|
v-for="t in tasks"
|
||||||
|
:key="t.id"
|
||||||
|
class="tile task"
|
||||||
|
:class="[t.state, { current: ed.def.value.challenge === t.id || (t.id === 'weekly' && ed.def.value.challenge === weeklyId(weekKey())) }]"
|
||||||
|
:title="t.hint"
|
||||||
|
@click="runTask(t)"
|
||||||
|
>
|
||||||
|
<span class="tile-art"><Icon :name="TASK_ICON[t.state]" class="size-6" /></span>
|
||||||
|
<span class="tile-name">{{ t.name }}</span>
|
||||||
|
<span v-if="t.meta" class="tile-meta">{{ t.meta }}</span>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div v-for="(t, i) in list" :key="t.id" class="tile-slot">
|
||||||
|
<button
|
||||||
|
class="tile"
|
||||||
|
:class="{ active: shown === 'search' && i === at, blocked: !!t.blocked, placing: ed.placing.value?.kind === t.kind && ed.placing.value?.chip === t.chip }"
|
||||||
|
:title="t.blocked || t.hint"
|
||||||
|
:draggable="!t.blocked"
|
||||||
|
@click="pick(t)"
|
||||||
|
@dragstart="onDragStart($event, t)"
|
||||||
|
@dragend="onDragEnd"
|
||||||
|
@pointerenter="shown === 'search' && (at = i)"
|
||||||
|
>
|
||||||
|
<span class="tile-art"><EditorPartThumb :kind="t.kind" :chip="t.chip" /></span>
|
||||||
|
<span class="tile-name">{{ t.name }}</span>
|
||||||
|
<span v-if="t.meta" class="tile-meta">{{ t.meta }}</span>
|
||||||
|
<Icon v-if="t.blocked && !t.meta?.startsWith('editing')" name="lucide:lock" class="tile-lock size-3.5" />
|
||||||
|
</button>
|
||||||
|
<button v-if="t.edit && t.chip" class="tile-edit" title="Open and edit" @click="ed.open(t.chip!); close()">
|
||||||
|
<Icon name="lucide:pencil" class="size-3" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<template v-if="shown === 'components'">
|
||||||
|
<button class="tile add" title="An empty component to build; its inputs and outputs become its pins" @click="ed.createComponent(); close()">
|
||||||
|
<span class="tile-art"><Icon name="lucide:plus" class="size-6" /></span>
|
||||||
|
<span class="tile-name">New component</span>
|
||||||
|
</button>
|
||||||
|
<button class="tile add" title="NOT, AND, … up to a 4-bit counter, all built from NAND" @click="ed.loadExamples(); close()">
|
||||||
|
<span class="tile-art"><Icon name="lucide:library" class="size-6" /></span>
|
||||||
|
<span class="tile-name">Example parts</span>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
<p v-if="!list.length && shown === 'search'" class="strip-empty">Nothing called "{{ query.trim() }}" fits here.</p>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
<button v-if="edges.right" class="strip-arrow right" title="Scroll right" @click="page(1)"><Icon name="lucide:chevron-right" class="size-4" /></button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</Transition>
|
||||||
|
|
||||||
|
<nav class="dock-bar" aria-label="Parts">
|
||||||
|
<label class="dock-search" :class="{ open: searching }">
|
||||||
|
<Icon name="lucide:search" class="size-4 shrink-0" />
|
||||||
|
<input
|
||||||
|
ref="searchEl"
|
||||||
|
v-model="query"
|
||||||
|
placeholder="Find a part"
|
||||||
|
@focus="focused = true"
|
||||||
|
@blur="focused = false"
|
||||||
|
@keydown="onSearchKey"
|
||||||
|
/>
|
||||||
|
<kbd v-if="!searching">/</kbd>
|
||||||
|
</label>
|
||||||
|
<span class="dock-sep" />
|
||||||
|
<button
|
||||||
|
v-for="c in CATS"
|
||||||
|
:key="c.id"
|
||||||
|
class="dock-cat"
|
||||||
|
:class="{ active: shown === c.id, task: c.id === 'challenges' && !!ed.task.value }"
|
||||||
|
:aria-expanded="shown === c.id"
|
||||||
|
@pointerenter="hover(c.id)"
|
||||||
|
@click="click(c.id)"
|
||||||
|
>
|
||||||
|
<Icon :name="c.icon" class="size-5" />
|
||||||
|
<span>{{ c.name }}</span>
|
||||||
|
<span v-if="c.id === 'challenges'" class="dock-count">{{ solvedCount }}/{{ CHALLENGES.length }}</span>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// The right panel: tabs for the selection, the circuit, its pins, and testing.
|
// The panel on the right, floating over the canvas: tabs for the selection,
|
||||||
|
// the circuit, its pins, and testing. It opens on its own while something is
|
||||||
|
// selected (like a building's info panel in a city builder); the pin keeps it
|
||||||
|
// open, and opening a challenge pins it on its Test tab.
|
||||||
import { ioList } from '~/lib/logic/bulk'
|
import { ioList } from '~/lib/logic/bulk'
|
||||||
|
|
||||||
const ed = useEditor()
|
const ed = useEditor()
|
||||||
|
|
@ -14,6 +17,12 @@ const pinCount = computed(() => {
|
||||||
return io.inputs.length + io.outputs.length
|
return io.inputs.length + io.outputs.length
|
||||||
})
|
})
|
||||||
const hasTask = computed(() => !!ed.task.value)
|
const hasTask = computed(() => !!ed.task.value)
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
ed.toggleSidebar('right', false)
|
||||||
|
ed.selection.value = []
|
||||||
|
ed.wireSel.value = []
|
||||||
|
}
|
||||||
/** Errors and warnings in the open circuit, on the Circuit tab. */
|
/** Errors and warnings in the open circuit, on the Circuit tab. */
|
||||||
const problems = computed(() => ed.issues.value.filter(i => i.level !== 'info').length)
|
const problems = computed(() => ed.issues.value.filter(i => i.level !== 'info').length)
|
||||||
|
|
||||||
|
|
@ -29,7 +38,7 @@ const tabs = computed(() => [
|
||||||
let before: Tab = 'circuit'
|
let before: Tab = 'circuit'
|
||||||
watch(selected, (now, was) => {
|
watch(selected, (now, was) => {
|
||||||
const tab = ed.rightTab.value
|
const tab = ed.rightTab.value
|
||||||
if (now && !was && tab === 'circuit') {
|
if (now && !was && (tab === 'circuit' || !ed.sidebars.right)) {
|
||||||
before = tab
|
before = tab
|
||||||
ed.rightTab.value = 'selection'
|
ed.rightTab.value = 'selection'
|
||||||
} else if (!now && tab === 'selection') ed.rightTab.value = before
|
} else if (!now && tab === 'selection') ed.rightTab.value = before
|
||||||
|
|
@ -44,8 +53,10 @@ watch(
|
||||||
watch(
|
watch(
|
||||||
() => ed.def.value.id,
|
() => ed.def.value.id,
|
||||||
() => {
|
() => {
|
||||||
if (ed.task.value) ed.rightTab.value = 'test'
|
if (ed.task.value) {
|
||||||
else if (ed.rightTab.value === 'test') ed.rightTab.value = 'circuit'
|
ed.rightTab.value = 'test'
|
||||||
|
ed.toggleSidebar('right', true)
|
||||||
|
} else if (ed.rightTab.value === 'test') ed.rightTab.value = 'circuit'
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
)
|
)
|
||||||
|
|
@ -54,9 +65,6 @@ watch(
|
||||||
<template>
|
<template>
|
||||||
<aside class="inspector">
|
<aside class="inspector">
|
||||||
<nav class="itabs" role="tablist">
|
<nav class="itabs" role="tablist">
|
||||||
<button class="collapse-btn" title="Hide this panel (])" @click="ed.toggleSidebar('right', false)">
|
|
||||||
<Icon name="lucide:panel-right-close" class="size-4" />
|
|
||||||
</button>
|
|
||||||
<button
|
<button
|
||||||
v-for="t in tabs"
|
v-for="t in tabs"
|
||||||
:key="t.id"
|
:key="t.id"
|
||||||
|
|
@ -70,6 +78,17 @@ watch(
|
||||||
<span class="label">{{ t.label }}</span>
|
<span class="label">{{ t.label }}</span>
|
||||||
<span v-if="t.badge" class="badge" :class="{ warn: 'warn' in t && t.warn }">{{ t.badge }}</span>
|
<span v-if="t.badge" class="badge" :class="{ warn: 'warn' in t && t.warn }">{{ t.badge }}</span>
|
||||||
</button>
|
</button>
|
||||||
|
<div class="itabs-tools">
|
||||||
|
<button
|
||||||
|
class="collapse-btn"
|
||||||
|
:class="{ active: ed.sidebars.right }"
|
||||||
|
:title="ed.sidebars.right ? 'Kept open; click to let it close with the selection (])' : 'Keep this panel open (])'"
|
||||||
|
@click="ed.toggleSidebar('right')"
|
||||||
|
>
|
||||||
|
<Icon :name="ed.sidebars.right ? 'lucide:pin' : 'lucide:pin-off'" class="size-3.5" />
|
||||||
|
</button>
|
||||||
|
<button class="collapse-btn" title="Close" @click="close"><Icon name="lucide:x" class="size-4" /></button>
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="scroll">
|
<div class="scroll">
|
||||||
<template v-if="ed.rightTab.value === 'selection'">
|
<template v-if="ed.rightTab.value === 'selection'">
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@ const parts = (id: string) =>
|
||||||
.join(', ')
|
.join(', ')
|
||||||
|
|
||||||
function fresh() {
|
function fresh() {
|
||||||
ed.newProject(false, true)
|
ed.startCampaign()
|
||||||
ed.paletteTab.value = 'challenges'
|
|
||||||
ed.enterGame()
|
ed.enterGame()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,8 @@ const faceHex = (inner: string) => sevenSegment([0, 1, 2, 3].reduce((n, i) => n
|
||||||
const FACE_SCALE = 0.6
|
const FACE_SCALE = 0.6
|
||||||
const hexValue = computed(() => [0, 1, 2, 3].reduce((n, i) => n + (v(`b${i}`) << i), 0))
|
const hexValue = computed(() => [0, 1, 2, 3].reduce((n, i) => n + (v(`b${i}`) << i), 0))
|
||||||
const segments = computed(() => sevenSegment(hexValue.value))
|
const segments = computed(() => sevenSegment(hexValue.value))
|
||||||
const lit = computed(() => v(props.node.kind === 'input' || props.node.kind === 'button' || props.node.kind === 'clock' ? 'q' : 'a') === 1)
|
// Lamps and outputs show what they pass on (q): with a bubble, that is the inverted wire.
|
||||||
|
const lit = computed(() => v(props.node.kind === 'pixel' ? 'a' : 'q') === 1)
|
||||||
const title = computed(() => {
|
const title = computed(() => {
|
||||||
if (props.node.kind === 'chip') return chipDef.value ? `${chipDef.value.name}${chipDef.value.description ? `: ${chipDef.value.description}` : ''}\nDouble-click to open` : 'Missing component'
|
if (props.node.kind === 'chip') return chipDef.value ? `${chipDef.value.name}${chipDef.value.description ? `: ${chipDef.value.description}` : ''}\nDouble-click to open` : 'Missing component'
|
||||||
return undefined
|
return undefined
|
||||||
|
|
|
||||||
|
|
@ -1,317 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import { shortCount } from '~/lib/logic/analyze'
|
|
||||||
import { CHALLENGES } from '~/lib/logic/challenges'
|
|
||||||
import { campaignProgress, challengeName, challengeOpen, defUsable, isCampaign, KIND_UNLOCK, NEEDS } from '~/lib/logic/progress'
|
|
||||||
import { weekKey, weeklyId } from '~/lib/logic/puzzles'
|
|
||||||
import { BASIC_GROUPS } from '~/composables/useParts'
|
|
||||||
import type { ComponentDef, NodeKind } from '~/lib/logic/types'
|
|
||||||
|
|
||||||
const ed = useEditor()
|
|
||||||
const tab = ed.paletteTab
|
|
||||||
const query = ref('')
|
|
||||||
|
|
||||||
const { componentGroups, search, recentParts } = useParts()
|
|
||||||
|
|
||||||
// ── Search: type to narrow everything down; arrows pick, Enter places ──
|
|
||||||
const searchInput = ref<HTMLInputElement>()
|
|
||||||
const hits = computed(() => (query.value.trim() ? search(query.value, 30) : []))
|
|
||||||
const at = ref(0)
|
|
||||||
watch(query, () => (at.value = 0))
|
|
||||||
watch(
|
|
||||||
() => ed.partSearch.value,
|
|
||||||
() => {
|
|
||||||
tab.value = 'parts'
|
|
||||||
nextTick(() => {
|
|
||||||
searchInput.value?.focus()
|
|
||||||
searchInput.value?.select()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
function onSearchKey(e: KeyboardEvent) {
|
|
||||||
const n = hits.value.length
|
|
||||||
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
||||||
e.preventDefault()
|
|
||||||
if (n) at.value = (at.value + (e.key === 'ArrowDown' ? 1 : -1) + n) % n
|
|
||||||
} else if (e.key === 'Enter') {
|
|
||||||
e.preventDefault()
|
|
||||||
const h = hits.value[at.value]
|
|
||||||
if (h) {
|
|
||||||
pick(h.kind, h.chip)
|
|
||||||
query.value = ''
|
|
||||||
searchInput.value?.blur()
|
|
||||||
}
|
|
||||||
} else if (e.key === 'Escape') {
|
|
||||||
query.value = ''
|
|
||||||
searchInput.value?.blur()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Groups that can be folded away; remembered in this browser ──
|
|
||||||
const FOLD_KEY = 'logigate:palette-folded'
|
|
||||||
const folded = ref<Set<string>>(
|
|
||||||
(() => {
|
|
||||||
try {
|
|
||||||
return new Set<string>(JSON.parse(localStorage.getItem(FOLD_KEY) ?? '[]'))
|
|
||||||
} catch {
|
|
||||||
return new Set<string>()
|
|
||||||
}
|
|
||||||
})(),
|
|
||||||
)
|
|
||||||
function fold(name: string) {
|
|
||||||
const next = new Set(folded.value)
|
|
||||||
if (!next.delete(name)) next.add(name)
|
|
||||||
folded.value = next
|
|
||||||
try {
|
|
||||||
localStorage.setItem(FOLD_KEY, JSON.stringify([...next]))
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
|
|
||||||
function pick(kind: NodeKind, chip?: string) {
|
|
||||||
if (chip && !ed.canPlace(chip)) return
|
|
||||||
if (!ed.canPlaceKind(kind)) {
|
|
||||||
ed.play('error')
|
|
||||||
return ed.notify(lockedHint(kind), 'error')
|
|
||||||
}
|
|
||||||
ed.placing.value = { kind, chip }
|
|
||||||
}
|
|
||||||
|
|
||||||
function onDragStart(e: DragEvent, kind: NodeKind, chip?: string) {
|
|
||||||
if (chip && !ed.canPlace(chip)) {
|
|
||||||
e.preventDefault()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
e.dataTransfer?.setData('application/x-logigate', JSON.stringify({ kind, chip }))
|
|
||||||
if (e.dataTransfer) e.dataTransfer.effectAllowed = 'copy'
|
|
||||||
ed.dragPart.value = { kind, chip }
|
|
||||||
}
|
|
||||||
|
|
||||||
const solved = computed(() => new Set(ed.project.value.solved))
|
|
||||||
const best = computed(() => ed.project.value.best ?? {})
|
|
||||||
const solvedCount = computed(() => CHALLENGES.filter(c => solved.value.has(c.id)).length)
|
|
||||||
const campaign = computed(() => isCampaign(ed.project.value))
|
|
||||||
const progress = computed(() => campaignProgress(ed.project.value))
|
|
||||||
const open = (id: string) => challengeOpen(ed.project.value, id)
|
|
||||||
const needsText = (id: string) => `Solve ${(NEEDS[id] ?? []).filter(n => !solved.value.has(n)).map(challengeName).join(' and ')} first`
|
|
||||||
const puzzles = computed(() => (ed.project.value.puzzles ?? []).filter(p => !p.id.startsWith('week:') || p.id === weeklyId(weekKey())))
|
|
||||||
const weeklyStarted = computed(() => ed.project.value.components.some(d => d.challenge === weeklyId(weekKey())))
|
|
||||||
|
|
||||||
function lockedHint(kind: NodeKind) {
|
|
||||||
const by = KIND_UNLOCK[kind]
|
|
||||||
return by ? `Solve the ${challengeName(by)} challenge to unlock this part` : ''
|
|
||||||
}
|
|
||||||
|
|
||||||
function openWeekly() {
|
|
||||||
const spec = ed.project.value.puzzles?.find(p => p.id === weeklyId(weekKey()))
|
|
||||||
if (spec) ed.beginPuzzle(spec)
|
|
||||||
else void ed.openPuzzle('weekly')
|
|
||||||
}
|
|
||||||
|
|
||||||
function compTitle(d: ComponentDef) {
|
|
||||||
if (d.id === ed.def.value.id) return 'You are editing this one'
|
|
||||||
if (!defUsable(ed.project.value, d)) return 'Solve this challenge to use it as a part'
|
|
||||||
if (!ed.canPlace(d.id)) return 'Contains the circuit you are editing'
|
|
||||||
return d.description || 'Click, then click on the canvas to place'
|
|
||||||
}
|
|
||||||
const started = computed(() => new Map(ed.project.value.components.filter(d => d.challenge).map(d => [d.challenge!, d])))
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<aside class="palette">
|
|
||||||
<div class="tabs">
|
|
||||||
<button :class="{ active: tab === 'parts' }" @click="tab = 'parts'">Parts</button>
|
|
||||||
<button :class="{ active: tab === 'challenges' }" @click="tab = 'challenges'">
|
|
||||||
Challenges
|
|
||||||
<span class="count">{{ solvedCount }}/{{ CHALLENGES.length }}</span>
|
|
||||||
</button>
|
|
||||||
<button class="collapse-btn" title="Hide this panel ([)" @click="ed.toggleSidebar('left', false)">
|
|
||||||
<Icon name="lucide:panel-left-close" class="size-4" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="tab === 'parts'" class="scroll">
|
|
||||||
<div class="search part-search">
|
|
||||||
<Icon name="lucide:search" class="size-3.5 text-(--muted)" />
|
|
||||||
<input ref="searchInput" v-model="query" placeholder="Find a part" @keydown="onSearchKey" />
|
|
||||||
<kbd v-if="!query" title="Press / on the canvas to search, Shift+A to add at the mouse">/</kbd>
|
|
||||||
<button v-else class="icon-btn" title="Clear (Esc)" @click="query = ''"><Icon name="lucide:x" class="size-3.5" /></button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Searching: one list of everything that matches -->
|
|
||||||
<template v-if="query.trim()">
|
|
||||||
<p v-if="!hits.length" class="hint px-3 pt-3">Nothing called "{{ query.trim() }}" fits here.</p>
|
|
||||||
<ul class="items mt-2">
|
|
||||||
<li v-for="(h, i) in hits" :key="h.chip ?? h.kind">
|
|
||||||
<button
|
|
||||||
class="item"
|
|
||||||
:class="{ active: i === at }"
|
|
||||||
:draggable="true"
|
|
||||||
@click="pick(h.kind, h.chip)"
|
|
||||||
@dragstart="onDragStart($event, h.kind, h.chip)"
|
|
||||||
@dragend="ed.dragPart.value = null"
|
|
||||||
@pointerenter="at = i"
|
|
||||||
>
|
|
||||||
<span v-if="h.kind === 'nand'" class="nand-badge">&</span>
|
|
||||||
<Icon v-else :name="h.icon" class="size-4 shrink-0 text-(--muted)" />
|
|
||||||
<span class="grow truncate">{{ h.name }}</span>
|
|
||||||
<span class="group-tag">{{ h.group }}</span>
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p class="hint px-3 pt-2">↑ ↓ to choose, Enter to place, Esc to clear.</p>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template v-else>
|
|
||||||
<template v-if="recentParts.length">
|
|
||||||
<h3>Recent</h3>
|
|
||||||
<div class="recent-parts">
|
|
||||||
<button
|
|
||||||
v-for="r in recentParts"
|
|
||||||
:key="r.chip ?? r.kind"
|
|
||||||
class="recent-chip"
|
|
||||||
:title="`Place ${r.name}`"
|
|
||||||
draggable="true"
|
|
||||||
@click="pick(r.kind, r.chip)"
|
|
||||||
@dragstart="onDragStart($event, r.kind, r.chip)"
|
|
||||||
@dragend="ed.dragPart.value = null"
|
|
||||||
>
|
|
||||||
<Icon :name="r.icon" class="size-3.5 shrink-0" />
|
|
||||||
<span class="truncate">{{ r.name }}</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template v-for="g in BASIC_GROUPS" :key="g.name">
|
|
||||||
<button class="group-head" @click="fold(g.name)">
|
|
||||||
<Icon :name="folded.has(g.name) ? 'lucide:chevron-right' : 'lucide:chevron-down'" class="size-3.5" />
|
|
||||||
<span>{{ g.name }}</span>
|
|
||||||
</button>
|
|
||||||
<ul v-if="!folded.has(g.name)" class="items">
|
|
||||||
<li v-for="item in g.parts" :key="item.kind">
|
|
||||||
<button
|
|
||||||
class="item"
|
|
||||||
:class="{ active: ed.placing.value?.kind === item.kind && !ed.placing.value?.chip, blocked: !ed.canPlaceKind(item.kind) }"
|
|
||||||
:title="ed.canPlaceKind(item.kind) ? item.hint : lockedHint(item.kind)"
|
|
||||||
:draggable="ed.canPlaceKind(item.kind)"
|
|
||||||
@click="pick(item.kind)"
|
|
||||||
@dragstart="onDragStart($event, item.kind)"
|
|
||||||
@dragend="ed.dragPart.value = null"
|
|
||||||
>
|
|
||||||
<span v-if="item.kind === 'nand'" class="nand-badge">&</span>
|
|
||||||
<Icon v-else :name="item.icon" class="size-4 shrink-0 text-(--muted)" />
|
|
||||||
<span class="grow truncate">{{ item.name }}</span>
|
|
||||||
<span v-if="item.kind === 'nand'" class="tcount" title="4 transistors: a CMOS NAND gate">4T</span>
|
|
||||||
<Icon v-if="!ed.canPlaceKind(item.kind)" name="lucide:lock" class="size-3.5 shrink-0 text-(--muted)" />
|
|
||||||
<kbd v-else-if="item.key">{{ item.key }}</kbd>
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template v-for="g in componentGroups" :key="g.name">
|
|
||||||
<button class="group-head" @click="fold(`c:${g.name}`)">
|
|
||||||
<Icon :name="folded.has(`c:${g.name}`) ? 'lucide:chevron-right' : 'lucide:chevron-down'" class="size-3.5" />
|
|
||||||
<span>{{ g.name }}</span>
|
|
||||||
<span class="group-count">{{ g.defs.length }}</span>
|
|
||||||
</button>
|
|
||||||
<ul v-if="!folded.has(`c:${g.name}`)" class="items">
|
|
||||||
<li v-for="d in g.defs" :key="d.id" class="comp-row">
|
|
||||||
<button
|
|
||||||
class="item"
|
|
||||||
:class="{ active: ed.placing.value?.chip === d.id, current: d.id === ed.def.value.id, blocked: !ed.canPlace(d.id) }"
|
|
||||||
:title="compTitle(d)"
|
|
||||||
:draggable="ed.canPlace(d.id)"
|
|
||||||
@click="pick('chip', d.id)"
|
|
||||||
@dragstart="onDragStart($event, 'chip', d.id)"
|
|
||||||
@dragend="ed.dragPart.value = null"
|
|
||||||
>
|
|
||||||
<Icon :name="d.challenge && solved.has(d.challenge) ? 'lucide:badge-check' : 'lucide:box'" class="size-4 shrink-0" :class="d.challenge && solved.has(d.challenge) ? 'text-(--on)' : 'text-(--muted)'" />
|
|
||||||
<span class="grow truncate">{{ d.name }}</span>
|
|
||||||
<span v-if="d.id === ed.def.value.id" class="editing">editing</span>
|
|
||||||
<span v-else-if="ed.transistors(d.id)" class="tcount" :title="`${ed.transistors(d.id).toLocaleString()} transistors`">{{ shortCount(ed.transistors(d.id)) }}T</span>
|
|
||||||
</button>
|
|
||||||
<button v-if="d.id !== ed.def.value.id" class="open" title="Open and edit" @click="ed.open(d.id)">
|
|
||||||
<Icon name="lucide:pencil" class="size-3.5" />
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<div class="grid gap-2 px-3 pt-3 pb-4">
|
|
||||||
<button class="btn w-full" @click="ed.createComponent()">
|
|
||||||
<Icon name="lucide:plus" class="size-4" /> New component
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ghost w-full" title="NOT, AND, … up to a 4-bit counter, all built from NAND" @click="ed.loadExamples()">
|
|
||||||
<Icon name="lucide:library" class="size-4" /> Add example parts
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-else class="scroll">
|
|
||||||
<div v-if="campaign" class="campaign">
|
|
||||||
<div class="flex items-center justify-between">
|
|
||||||
<span class="font-semibold">Campaign</span>
|
|
||||||
<span class="tabular-nums text-(--muted)">{{ solvedCount }} / {{ CHALLENGES.length }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="bar"><span :style="{ width: `${progress * 100}%` }" /></div>
|
|
||||||
<p>Every part you solve becomes yours to use. New parts and challenges open as you go.</p>
|
|
||||||
</div>
|
|
||||||
<p v-else class="intro">
|
|
||||||
Build each part from NAND and the parts you already made. Start a challenge, wire it up, then press
|
|
||||||
<strong>Check</strong> on the right.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="weekly">
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<Icon name="lucide:calendar-days" class="size-4 shrink-0 text-(--accent)" />
|
|
||||||
<span class="grow font-medium">Puzzle of the week</span>
|
|
||||||
<button class="btn-sm" @click="openWeekly">{{ weeklyStarted ? 'Open' : 'Play' }}</button>
|
|
||||||
</div>
|
|
||||||
<p>A new logic puzzle every Monday, the same for everyone. Fewest transistors wins.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<template v-if="puzzles.length">
|
|
||||||
<h3>Puzzles</h3>
|
|
||||||
<ul class="challenges">
|
|
||||||
<li v-for="p in puzzles" :key="p.id" :class="{ solved: solved.has(p.id) }">
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<Icon :name="solved.has(p.id) ? 'lucide:circle-check' : 'lucide:puzzle'" class="size-4 shrink-0" :class="solved.has(p.id) ? 'text-(--on)' : 'text-(--muted)'" />
|
|
||||||
<span class="grow font-medium">{{ p.name }}</span>
|
|
||||||
<button class="btn-sm" @click="ed.beginPuzzle(p)">Open</button>
|
|
||||||
</div>
|
|
||||||
<p class="pins">
|
|
||||||
{{ p.inputs.join(', ') }} → {{ p.outputs.join(', ') }}
|
|
||||||
<span v-if="best[p.id] !== undefined" class="best"> · best {{ best[p.id]!.toLocaleString() }} transistors</span>
|
|
||||||
</p>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<h3>Challenges</h3>
|
|
||||||
<ul class="challenges">
|
|
||||||
<li v-for="c in CHALLENGES" :key="c.id" :class="{ solved: solved.has(c.id), locked: !open(c.id) }">
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<Icon
|
|
||||||
:name="solved.has(c.id) ? 'lucide:circle-check' : open(c.id) ? 'lucide:circle' : 'lucide:lock'"
|
|
||||||
class="size-4 shrink-0"
|
|
||||||
:class="solved.has(c.id) ? 'text-(--on)' : 'text-(--muted)'"
|
|
||||||
/>
|
|
||||||
<span class="grow font-medium">{{ c.name }}</span>
|
|
||||||
<button class="btn-sm" :disabled="!open(c.id) && !started.has(c.id)" :title="open(c.id) ? '' : needsText(c.id)" @click="ed.beginChallenge(c)">
|
|
||||||
{{ started.has(c.id) ? 'Open' : 'Start' }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<p v-if="!open(c.id)" class="needs">{{ needsText(c.id) }}</p>
|
|
||||||
<p>{{ c.goal }}</p>
|
|
||||||
<p class="pins">
|
|
||||||
{{ c.inputs.join(', ') }} → {{ c.outputs.join(', ') }}
|
|
||||||
<span v-if="best[c.id] !== undefined" class="best" title="Fewest transistors in a passing solution so far">
|
|
||||||
· best {{ best[c.id]!.toLocaleString() }} transistors
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</aside>
|
|
||||||
</template>
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
// A small picture of a part, drawn the way the canvas draws it, for the
|
||||||
|
// parts dock: you see what you are about to place.
|
||||||
|
import { GRID as G } from '~/lib/logic/geometry'
|
||||||
|
import { newPanelRows } from '~/lib/logic/panels'
|
||||||
|
import type { CircuitNode, NodeKind } from '~/lib/logic/types'
|
||||||
|
|
||||||
|
const props = defineProps<{ kind: NodeKind; chip?: string }>()
|
||||||
|
const ed = useEditor()
|
||||||
|
|
||||||
|
const node = computed<CircuitNode>(() => {
|
||||||
|
const n: CircuitNode = { id: 'thumb', kind: props.kind, x: 0, y: 0 }
|
||||||
|
if (props.chip) n.chip = props.chip
|
||||||
|
if (props.kind === 'panel' || props.kind === 'outpanel') n.rows = newPanelRows(3)
|
||||||
|
if (props.kind === 'bundle' || props.kind === 'split') n.bits = 4
|
||||||
|
if (props.kind === 'note') n.label = 'Note'
|
||||||
|
if (props.kind === 'tag' || props.kind === 'ref') n.label = 'CLK'
|
||||||
|
return n
|
||||||
|
})
|
||||||
|
const shape = computed(() => ed.shape(node.value))
|
||||||
|
|
||||||
|
/** The part and its pins, with a little room around. */
|
||||||
|
const box = computed(() => {
|
||||||
|
const s = shape.value
|
||||||
|
const xs = [s.body.x, s.body.x + s.body.w, ...s.inputs.map(p => p.dx), ...s.outputs.map(p => p.dx)]
|
||||||
|
const ys = [s.body.y, s.body.y + s.body.h, ...s.inputs.map(p => p.dy), ...s.outputs.map(p => p.dy)]
|
||||||
|
const pad = 0.6
|
||||||
|
const x0 = Math.min(...xs) - pad
|
||||||
|
const y0 = Math.min(...ys) - pad
|
||||||
|
return `${x0 * G} ${y0 * G} ${(Math.max(...xs) + pad - x0) * G} ${(Math.max(...ys) + pad - y0) * G}`
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<svg class="part-thumb" :viewBox="box" preserveAspectRatio="xMidYMid meet" aria-hidden="true">
|
||||||
|
<EditorNodeView :node="node" :shape="shape" :selected="false" ghost />
|
||||||
|
</svg>
|
||||||
|
</template>
|
||||||
|
|
@ -16,7 +16,7 @@ const value = computed(() => {
|
||||||
const id = n.value.id
|
const id = n.value.id
|
||||||
if (props.e.row) return String(ed.val(id, props.e.row.id))
|
if (props.e.row) return String(ed.val(id, props.e.row.id))
|
||||||
if (n.value.kind === 'hex') return [0, 1, 2, 3].reduce((v, i) => v + (ed.val(id, `b${i}`) << i), 0).toString(16).toUpperCase()
|
if (n.value.kind === 'hex') return [0, 1, 2, 3].reduce((v, i) => v + (ed.val(id, `b${i}`) << i), 0).toString(16).toUpperCase()
|
||||||
return String(ed.val(id, ['output', 'lamp'].includes(n.value.kind) ? 'a' : 'q'))
|
return String(ed.val(id, 'q'))
|
||||||
})
|
})
|
||||||
|
|
||||||
function flip() {
|
function flip() {
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ function onFile(e: Event) {
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div class="mt-4 flex flex-wrap gap-2">
|
<div class="mt-4 flex flex-wrap gap-2">
|
||||||
<button v-if="!freeOnly" class="btn btn-primary" title="Start with NAND only and earn every other part by solving challenges" @click="ed.newProject(false, true); close()">
|
<button v-if="!freeOnly" class="btn btn-primary" title="Start with NAND only and earn every other part by solving challenges" @click="ed.startCampaign(); close()">
|
||||||
<Icon name="lucide:trophy" class="size-4" /> New campaign
|
<Icon name="lucide:trophy" class="size-4" /> New campaign
|
||||||
</button>
|
</button>
|
||||||
<button class="btn" @click="ed.newProject(false); close()"><Icon name="lucide:file" class="size-4" /> New (NAND only)</button>
|
<button class="btn" @click="ed.newProject(false); close()"><Icon name="lucide:file" class="size-4" /> New (NAND only)</button>
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
// A hidden side panel shrinks to this strip; its buttons bring it back.
|
|
||||||
const props = defineProps<{ side: 'left' | 'right' }>()
|
|
||||||
const ed = useEditor()
|
|
||||||
|
|
||||||
const TABS = [
|
|
||||||
{ id: 'selection', label: 'Selection', icon: 'lucide:mouse-pointer-2' },
|
|
||||||
{ id: 'circuit', label: 'Circuit', icon: 'lucide:cpu' },
|
|
||||||
{ id: 'pins', label: 'Pins', icon: 'lucide:list' },
|
|
||||||
{ id: 'test', label: 'Test', icon: 'lucide:table' },
|
|
||||||
] as const
|
|
||||||
|
|
||||||
function openTab(id: (typeof TABS)[number]['id']) {
|
|
||||||
ed.rightTab.value = id
|
|
||||||
ed.toggleSidebar('right', true)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<aside class="rail" :class="props.side">
|
|
||||||
<button
|
|
||||||
class="rail-btn"
|
|
||||||
:title="props.side === 'left' ? 'Show parts and challenges ([)' : 'Show the side panel (])'"
|
|
||||||
@click="ed.toggleSidebar(props.side, true)"
|
|
||||||
>
|
|
||||||
<Icon :name="props.side === 'left' ? 'lucide:panel-left-open' : 'lucide:panel-right-open'" class="size-4" />
|
|
||||||
</button>
|
|
||||||
<template v-if="props.side === 'right'">
|
|
||||||
<button v-for="t in TABS" :key="t.id" class="rail-btn" :title="t.label" @click="openTab(t.id)">
|
|
||||||
<Icon :name="t.icon" class="size-4" />
|
|
||||||
</button>
|
|
||||||
</template>
|
|
||||||
</aside>
|
|
||||||
</template>
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
// The top of the editor: three small floating groups over the canvas.
|
||||||
|
// Left, where you are (menu, project, circuit); middle, the clock; right,
|
||||||
|
// the few things used all the time, and everything else in the ⋯ menu.
|
||||||
|
import type { MenuEntry } from '~/composables/useMenu'
|
||||||
|
|
||||||
const ed = useEditor()
|
const ed = useEditor()
|
||||||
|
|
||||||
const SPEEDS = [
|
const SPEEDS = [
|
||||||
|
|
@ -31,90 +36,95 @@ const linkIcon = computed(() => {
|
||||||
return 'lucide:share-2'
|
return 'lucide:share-2'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** The panel on the right: open on its own while something is selected; this keeps it open. */
|
||||||
|
const panelOpen = computed(() => ed.sidebars.right)
|
||||||
|
|
||||||
|
const more = ref<{ x: number; y: number } | null>(null)
|
||||||
|
function openMore(e: MouseEvent) {
|
||||||
|
const r = (e.currentTarget as HTMLElement).getBoundingClientRect()
|
||||||
|
more.value = more.value ? null : { x: r.right - 240, y: r.bottom + 6 }
|
||||||
|
}
|
||||||
|
const moreEntries = computed<MenuEntry[]>(() => [
|
||||||
|
{ label: 'Your projects', icon: 'lucide:folder', run: () => (ed.dialog.value = 'projects') },
|
||||||
|
{ label: 'Main menu', icon: 'lucide:house', run: () => ed.showMenu() },
|
||||||
|
'sep',
|
||||||
|
{ label: 'Settings', icon: 'lucide:settings', note: 'symbols, wires, sound', run: () => (ed.dialog.value = 'settings') },
|
||||||
|
{ label: ed.sound.value.on ? 'Sound on' : 'Sound off', icon: ed.sound.value.on ? 'lucide:volume-2' : 'lucide:volume-x', checked: ed.sound.value.on, run: () => ed.setSound({ on: !ed.sound.value.on }) },
|
||||||
|
{ label: ed.sidebars.left ? 'Hide the parts dock' : 'Show the parts dock', icon: 'lucide:panel-bottom', keys: '[', run: () => ed.toggleSidebar('left') },
|
||||||
|
{ label: 'Print or save as PDF', icon: 'lucide:printer', keys: 'Ctrl+P', run: () => ed.exportSheet('print') },
|
||||||
|
'sep',
|
||||||
|
{ label: 'How to play', icon: 'lucide:circle-help', keys: '?', run: () => (ed.showHelp.value = true) },
|
||||||
|
{ label: ed.account.value ? `${ed.account.value.email}` : 'Sign in', icon: ed.account.value ? 'lucide:user-check' : 'lucide:user', note: ed.account.value ? cloudText.value : 'keep projects everywhere', run: () => (ed.dialog.value = 'account') },
|
||||||
|
])
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<header class="toolbar">
|
<header class="hud">
|
||||||
<div class="flex min-w-0 items-center gap-2">
|
<div class="hud-group">
|
||||||
<button class="brand" title="Main menu (your work is saved)" @click="ed.showMenu()">
|
<button class="hud-btn brand" title="Main menu (your work is saved)" @click="ed.showMenu()">
|
||||||
<svg viewBox="0 0 32 32" class="size-6" aria-hidden="true">
|
<svg viewBox="0 0 32 32" class="size-5" aria-hidden="true">
|
||||||
<path d="M6 7h10a9 9 0 0 1 0 18H6Z" fill="none" stroke="currentColor" stroke-width="2.5" />
|
<path d="M6 7h10a9 9 0 0 1 0 18H6Z" fill="none" stroke="currentColor" stroke-width="2.8" />
|
||||||
<circle cx="27" cy="16" r="2.6" fill="none" stroke="currentColor" stroke-width="2.2" />
|
<circle cx="27" cy="16" r="2.6" fill="none" stroke="currentColor" stroke-width="2.4" />
|
||||||
</svg>
|
</svg>
|
||||||
<span class="hidden xl:inline">Menu</span>
|
|
||||||
</button>
|
</button>
|
||||||
<button class="tb-btn project-btn" title="Your projects" @click="ed.dialog.value = 'projects'">
|
<span class="hud-sep" />
|
||||||
<Icon name="lucide:folder" class="size-4 shrink-0" />
|
<button class="hud-btn hud-project" title="Your projects" @click="ed.dialog.value = 'projects'">
|
||||||
<span class="truncate">{{ ed.project.value.name }}</span>
|
<span class="truncate">{{ ed.project.value.name }}</span>
|
||||||
<Icon name="lucide:chevron-down" class="size-3.5 shrink-0 text-(--muted)" />
|
|
||||||
</button>
|
</button>
|
||||||
<span class="text-(--border)">/</span>
|
<Icon name="lucide:chevron-right" class="size-3.5 shrink-0 text-(--muted)" />
|
||||||
<button v-if="backName" class="tb-btn" :title="`Back to ${backName}`" @click="ed.back()">
|
<button v-if="backName" class="hud-btn" :title="`Back to ${backName}`" @click="ed.back()">
|
||||||
<Icon name="lucide:arrow-left" class="size-4" />
|
<Icon name="lucide:arrow-left" class="size-4" />
|
||||||
</button>
|
</button>
|
||||||
<label class="circuit-select" title="Circuit you are editing">
|
<label class="hud-circuit" title="Circuit you are editing">
|
||||||
<select :value="ed.def.value.id" @change="ed.open(($event.target as HTMLSelectElement).value)">
|
<select :value="ed.def.value.id" @change="ed.open(($event.target as HTMLSelectElement).value)">
|
||||||
<option v-for="d in ed.project.value.components" :key="d.id" :value="d.id">{{ d.name }}</option>
|
<option v-for="d in ed.project.value.components" :key="d.id" :value="d.id">{{ d.name }}</option>
|
||||||
</select>
|
</select>
|
||||||
|
<Icon name="lucide:chevron-down" class="size-3.5 text-(--muted)" />
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center gap-1.5">
|
<div class="hud-group hud-sim">
|
||||||
<button
|
<span class="status" :class="ed.status.value" :title="ed.status.value === 'oscillating' ? 'A loop keeps flipping and never settles (e.g. a NOT feeding itself)' : 'Simulation state'">
|
||||||
class="tb-btn"
|
<span class="dot" /><span class="hidden lg:inline">{{ statusText }}</span>
|
||||||
:class="{ active: ed.running.value }"
|
</span>
|
||||||
:title="ed.running.value ? 'Pause the clock' : 'Run the clock'"
|
<template v-if="hasClock">
|
||||||
:disabled="!hasClock"
|
<span class="hud-sep" />
|
||||||
@click="ed.running.value = !ed.running.value"
|
<button class="hud-btn" :class="{ active: ed.running.value }" :title="ed.running.value ? 'Pause the clock' : 'Run the clock'" @click="ed.running.value = !ed.running.value">
|
||||||
>
|
|
||||||
<Icon :name="ed.running.value ? 'lucide:pause' : 'lucide:play'" class="size-4" />
|
<Icon :name="ed.running.value ? 'lucide:pause' : 'lucide:play'" class="size-4" />
|
||||||
</button>
|
</button>
|
||||||
<button class="tb-btn" title="One clock cycle" :disabled="!hasClock" @click="ed.running.value = false; ed.step()">
|
<button class="hud-btn" title="One clock cycle" @click="ed.running.value = false; ed.step()">
|
||||||
<Icon name="lucide:step-forward" class="size-4" />
|
<Icon name="lucide:step-forward" class="size-4" />
|
||||||
</button>
|
</button>
|
||||||
<select v-model.number="ed.hz.value" class="tb-select" title="Clock speed" :disabled="!hasClock">
|
<select v-model.number="ed.hz.value" class="hud-select" title="Clock speed">
|
||||||
<option v-for="s in SPEEDS" :key="s.value" :value="s.value">{{ s.label }}</option>
|
<option v-for="s in SPEEDS" :key="s.value" :value="s.value">{{ s.label }}</option>
|
||||||
</select>
|
</select>
|
||||||
<span v-if="hasClock" class="cycles tabular-nums" title="Clock cycles since this circuit was opened">{{ ed.cycles.value.toLocaleString() }} ticks</span>
|
<span class="cycles tabular-nums" title="Clock cycles since this circuit was opened">{{ ed.cycles.value.toLocaleString() }}</span>
|
||||||
<span class="status" :class="ed.status.value" :title="ed.status.value === 'oscillating' ? 'A loop keeps flipping and never settles (e.g. a NOT feeding itself)' : 'Simulation state'">
|
</template>
|
||||||
<span class="dot" />{{ statusText }}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center gap-1.5">
|
<div class="hud-group">
|
||||||
<button class="tb-btn" title="Find anything in the project (Ctrl+F)" @click="ed.dialog.value = 'search'"><Icon name="lucide:search" class="size-4" /></button>
|
<button class="hud-btn" title="Find anything in the project (Ctrl+F)" @click="ed.dialog.value = 'search'"><Icon name="lucide:search" class="size-4" /></button>
|
||||||
<button class="tb-btn" title="Undo (Ctrl+Z)" :disabled="!ed.canUndo.value" @click="ed.undo()"><Icon name="lucide:undo-2" class="size-4" /></button>
|
<button class="hud-btn" title="Undo (Ctrl+Z)" :disabled="!ed.canUndo.value" @click="ed.undo()"><Icon name="lucide:undo-2" class="size-4" /></button>
|
||||||
<button class="tb-btn" title="Redo (Ctrl+Shift+Z)" :disabled="!ed.canRedo.value" @click="ed.redo()"><Icon name="lucide:redo-2" class="size-4" /></button>
|
<button class="hud-btn" title="Redo (Ctrl+Shift+Z)" :disabled="!ed.canRedo.value" @click="ed.redo()"><Icon name="lucide:redo-2" class="size-4" /></button>
|
||||||
<button
|
<span class="hud-sep" />
|
||||||
class="tb-btn"
|
<button class="hud-btn share-btn" :class="ed.linkState.value" title="Save online, share a link, export or import a file" @click="ed.dialog.value = 'share'">
|
||||||
:title="ed.sound.value.on ? 'Sound on (volume and clock ticks in Settings)' : 'Sound off'"
|
|
||||||
@click="ed.setSound({ on: !ed.sound.value.on })"
|
|
||||||
>
|
|
||||||
<Icon :name="ed.sound.value.on ? 'lucide:volume-2' : 'lucide:volume-x'" class="size-4" />
|
|
||||||
</button>
|
|
||||||
<button class="tb-btn" title="Settings: gate symbols, wire crossings, current flow, tidy wiring, sound" @click="ed.dialog.value = 'settings'">
|
|
||||||
<Icon name="lucide:settings" class="size-4" />
|
|
||||||
</button>
|
|
||||||
<button class="tb-btn share-btn" :class="ed.linkState.value" title="Save online, share a link, export or import a file" @click="ed.dialog.value = 'share'">
|
|
||||||
<Icon :name="linkIcon" class="size-4" />
|
<Icon :name="linkIcon" class="size-4" />
|
||||||
<span class="hidden md:inline">Share</span>
|
<span class="hidden md:inline">Share</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="tb-btn" title="Help (?)" @click="ed.showHelp.value = true"><Icon name="lucide:circle-help" class="size-4" /></button>
|
|
||||||
<button
|
<button
|
||||||
class="tb-btn account-btn"
|
class="hud-btn"
|
||||||
:class="ed.cloudState.value"
|
:class="{ active: panelOpen }"
|
||||||
:title="ed.account.value ? `${ed.account.value.email}: ${cloudText}` : 'Sign in to keep your projects on every computer'"
|
:title="panelOpen ? 'Hide the side panel (])' : 'Circuit, pins and tests (])'"
|
||||||
@click="ed.dialog.value = 'account'"
|
@click="ed.toggleSidebar('right')"
|
||||||
>
|
>
|
||||||
<template v-if="ed.account.value">
|
<Icon name="lucide:panel-right" class="size-4" />
|
||||||
<span class="avatar">{{ ed.account.value.email[0]!.toUpperCase() }}</span>
|
</button>
|
||||||
<span class="sync-dot" />
|
<button class="hud-btn account-btn" :class="[ed.cloudState.value, { active: !!more }]" title="More: projects, settings, sound, help, account" @click="openMore">
|
||||||
</template>
|
<template v-if="ed.account.value"><span class="avatar">{{ ed.account.value.email[0]!.toUpperCase() }}</span><span class="sync-dot" /></template>
|
||||||
<template v-else>
|
<Icon v-else name="lucide:ellipsis" class="size-4" />
|
||||||
<Icon name="lucide:user" class="size-4" />
|
|
||||||
<span class="hidden md:inline">Sign in</span>
|
|
||||||
</template>
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<EditorContextMenu v-if="more" :x="more.x" :y="more.y" :entries="moreEntries" @close="more = null" />
|
||||||
</header>
|
</header>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -172,15 +172,19 @@ function create() {
|
||||||
}
|
}
|
||||||
/** Tab shown in the right panel. */
|
/** Tab shown in the right panel. */
|
||||||
const rightTab = ref<'selection' | 'circuit' | 'pins' | 'test'>('circuit')
|
const rightTab = ref<'selection' | 'circuit' | 'pins' | 'test'>('circuit')
|
||||||
/** Which side panels are open; remembered in this browser. */
|
/**
|
||||||
const sidebars = reactive<{ left: boolean; right: boolean }>({ left: true, right: true })
|
* Left: the parts dock at the bottom is shown. Right: the side panel is
|
||||||
|
* kept open (it also opens on its own while something is selected).
|
||||||
|
* Remembered in this browser; a fresh layout starts clean.
|
||||||
|
*/
|
||||||
|
const sidebars = reactive<{ left: boolean; right: boolean }>({ left: true, right: false })
|
||||||
try {
|
try {
|
||||||
Object.assign(sidebars, JSON.parse(localStorage.getItem('logigate:sidebars') ?? '{}'))
|
Object.assign(sidebars, JSON.parse(localStorage.getItem('logigate:layout') ?? '{}'))
|
||||||
} catch {}
|
} catch {}
|
||||||
function toggleSidebar(side: 'left' | 'right', open = !sidebars[side]) {
|
function toggleSidebar(side: 'left' | 'right', open = !sidebars[side]) {
|
||||||
sidebars[side] = open
|
sidebars[side] = open
|
||||||
try {
|
try {
|
||||||
localStorage.setItem('logigate:sidebars', JSON.stringify(sidebars))
|
localStorage.setItem('logigate:layout', JSON.stringify(sidebars))
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
/** Asks the canvas to centre on a part. */
|
/** Asks the canvas to centre on a part. */
|
||||||
|
|
@ -805,8 +809,6 @@ function create() {
|
||||||
/** The title menu shows when the app opens at /; links open straight into the editor. */
|
/** The title menu shows when the app opens at /; links open straight into the editor. */
|
||||||
const screen = ref<'menu' | 'editor'>(location.pathname === '/' ? 'menu' : 'editor')
|
const screen = ref<'menu' | 'editor'>(location.pathname === '/' ? 'menu' : 'editor')
|
||||||
const menuPage = ref<MenuPage>('main')
|
const menuPage = ref<MenuPage>('main')
|
||||||
/** Tab of the parts panel on the left. */
|
|
||||||
const paletteTab = ref<'parts' | 'challenges'>('parts')
|
|
||||||
|
|
||||||
function enterGame() {
|
function enterGame() {
|
||||||
screen.value = 'editor'
|
screen.value = 'editor'
|
||||||
|
|
@ -838,15 +840,21 @@ function create() {
|
||||||
return m.id === meta.value.id ? project.value : loadProject(m.id)
|
return m.id === meta.value.id ? project.value : loadProject(m.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Into the campaign: the newest one, or a new one. */
|
/** Into the campaign: the newest one where it was left, or a new one at its first challenge. */
|
||||||
function playCampaign() {
|
function playCampaign() {
|
||||||
const m = newestOf('campaign')
|
const m = newestOf('campaign')
|
||||||
if (m) switchProject(m.id)
|
if (m) switchProject(m.id)
|
||||||
else newProject(false, true)
|
else startCampaign()
|
||||||
paletteTab.value = 'challenges'
|
|
||||||
enterGame()
|
enterGame()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A new campaign, open at its first challenge. */
|
||||||
|
function startCampaign() {
|
||||||
|
newProject(false, true)
|
||||||
|
const first = CHALLENGES.find(c => challengeOpen(project.value, c.id))
|
||||||
|
if (first) beginChallenge(first)
|
||||||
|
}
|
||||||
|
|
||||||
/** Into the challenges project (made on first use: NAND only, every challenge open). */
|
/** Into the challenges project (made on first use: NAND only, every challenge open). */
|
||||||
function intoChallenges() {
|
function intoChallenges() {
|
||||||
const m = newestOf('challenges')
|
const m = newestOf('challenges')
|
||||||
|
|
@ -857,7 +865,6 @@ function create() {
|
||||||
p.mode = 'challenges'
|
p.mode = 'challenges'
|
||||||
activate(addProject(p), p)
|
activate(addProject(p), p)
|
||||||
}
|
}
|
||||||
paletteTab.value = 'challenges'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function playChallenge(c: Challenge) {
|
function playChallenge(c: Challenge) {
|
||||||
|
|
@ -2135,7 +2142,7 @@ function create() {
|
||||||
setScreen,
|
setScreen,
|
||||||
screen,
|
screen,
|
||||||
menuPage,
|
menuPage,
|
||||||
paletteTab,
|
startCampaign,
|
||||||
enterGame,
|
enterGame,
|
||||||
showMenu,
|
showMenu,
|
||||||
projectMode,
|
projectMode,
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,6 @@ export function useMenu() {
|
||||||
function rename(id: string) {
|
function rename(id: string) {
|
||||||
ed.selection.value = [id]
|
ed.selection.value = [id]
|
||||||
ed.wireSel.value = []
|
ed.wireSel.value = []
|
||||||
ed.toggleSidebar('right', true)
|
|
||||||
ed.labelFocus.value++
|
ed.labelFocus.value++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ export function truthTable(getDef: DefLookup, defId: string): TruthTable | { err
|
||||||
const ins = pins.inputs.map((_, k) => (i >> (n - 1 - k)) & 1)
|
const ins = pins.inputs.map((_, k) => (i >> (n - 1 - k)) & 1)
|
||||||
pins.inputs.forEach((p, k) => sim.setSource(p.key, ins[k] === 1))
|
pins.inputs.forEach((p, k) => sim.setSource(p.key, ins[k] === 1))
|
||||||
const settled = sim.run(SETTLE_BUDGET)
|
const settled = sim.run(SETTLE_BUDGET)
|
||||||
rows.push({ ins, outs: pins.outputs.map(p => sim.pin(p.key, 'a')), settled })
|
rows.push({ ins, outs: pins.outputs.map(p => sim.output(p.key)), settled })
|
||||||
}
|
}
|
||||||
return { inputs: pins.inputs.map(p => p.label), outputs: pins.outputs.map(p => p.label), rows }
|
return { inputs: pins.inputs.map(p => p.label), outputs: pins.outputs.map(p => p.label), rows }
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +176,7 @@ export function runSteps(getDef: DefLookup, defId: string, steps: TestStep[]): T
|
||||||
for (const [l, v] of Object.entries(step.set)) sim.setSource(find(pins.inputs, l)!.key, v === 1)
|
for (const [l, v] of Object.entries(step.set)) sim.setSource(find(pins.inputs, l)!.key, v === 1)
|
||||||
if (!sim.run(SETTLE_BUDGET)) return { pass: false, message: 'The circuit oscillates and never settles', failedStep: i }
|
if (!sim.run(SETTLE_BUDGET)) return { pass: false, message: 'The circuit oscillates and never settles', failedStep: i }
|
||||||
for (const [l, want] of Object.entries(step.expect)) {
|
for (const [l, want] of Object.entries(step.expect)) {
|
||||||
const got = sim.pin(find(pins.outputs, l)!.key, 'a')
|
const got = sim.output(find(pins.outputs, l)!.key)
|
||||||
if (got !== want) {
|
if (got !== want) {
|
||||||
const inputs = Object.entries(step.set).map(([k, v]) => `${k}=${v}`).join(' ')
|
const inputs = Object.entries(step.set).map(([k, v]) => `${k}=${v}`).join(' ')
|
||||||
return { pass: false, message: `With ${inputs}: ${l} is ${got}, expected ${want}`, failedStep: i }
|
return { pass: false, message: `With ${inputs}: ${l} is ${got}, expected ${want}`, failedStep: i }
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ export interface Netlist {
|
||||||
tracePinNet?: Map<string, number>
|
tracePinNet?: Map<string, number>
|
||||||
/** Inputs of lamps and displays inside the root's chips, keyed "chipNode/nodeId:pin", for drawing them on the chip. */
|
/** Inputs of lamps and displays inside the root's chips, keyed "chipNode/nodeId:pin", for drawing them on the chip. */
|
||||||
facePinNet: Map<string, number>
|
facePinNet: Map<string, number>
|
||||||
|
/** What each of the root circuit's output pins puts out (keyed like ChipPins outputs), after any bubble on it. */
|
||||||
|
outputs: Map<string, number>
|
||||||
/** User-driven sources in the root circuit (switches, buttons): nodeId → net. */
|
/** User-driven sources in the root circuit (switches, buttons): nodeId → net. */
|
||||||
sources: Map<string, number>
|
sources: Map<string, number>
|
||||||
clocks: Int32Array
|
clocks: Int32Array
|
||||||
|
|
@ -310,8 +312,8 @@ export function compile(getDef: DefLookup, rootId: string, opts: { trace?: boole
|
||||||
}
|
}
|
||||||
|
|
||||||
const root = getDef(rootId)
|
const root = getDef(rootId)
|
||||||
if (root) expand(root, null, '', [])
|
const rootOut = root ? expand(root, null, '', []) : new Map<string, number>()
|
||||||
else errors.push('Circuit not found')
|
if (!root) errors.push('Circuit not found')
|
||||||
|
|
||||||
// Renumber union-find roots to 0..netCount-1, constants first.
|
// Renumber union-find roots to 0..netCount-1, constants first.
|
||||||
const idx = new Int32Array(parent.length).fill(-1)
|
const idx = new Int32Array(parent.length).fill(-1)
|
||||||
|
|
@ -373,6 +375,7 @@ export function compile(getDef: DefLookup, rootId: string, opts: { trace?: boole
|
||||||
pinNet,
|
pinNet,
|
||||||
tracePinNet,
|
tracePinNet,
|
||||||
facePinNet,
|
facePinNet,
|
||||||
|
outputs: mapNets(rootOut),
|
||||||
sources: srcs,
|
sources: srcs,
|
||||||
clocks: clockNets,
|
clocks: clockNets,
|
||||||
clockHz: Float64Array.from(clockList.map(c => c.hz)),
|
clockHz: Float64Array.from(clockList.map(c => c.hz)),
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ export function describeCircuit(get: DefLookup, defId: string): { inputs: string
|
||||||
if (!sim.run(STEP_BUDGET)) throw new Error('The circuit keeps oscillating, so it has no clear answer')
|
if (!sim.run(STEP_BUDGET)) throw new Error('The circuit keeps oscillating, so it has no clear answer')
|
||||||
steps.push({
|
steps.push({
|
||||||
set: Object.fromEntries(pins.inputs.map((p, k) => [p.label, ins[k]!])),
|
set: Object.fromEntries(pins.inputs.map((p, k) => [p.label, ins[k]!])),
|
||||||
expect: Object.fromEntries(pins.outputs.map(p => [p.label, sim.pin(p.key, 'a')])),
|
expect: Object.fromEntries(pins.outputs.map(p => [p.label, sim.output(p.key)])),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return { inputs: pins.inputs.map(p => p.label), outputs: pins.outputs.map(p => p.label), steps, sequential }
|
return { inputs: pins.inputs.map(p => p.label), outputs: pins.outputs.map(p => p.label), steps, sequential }
|
||||||
|
|
@ -162,7 +162,7 @@ export function scoreSolution(components: ComponentDef[], defId: string, spec: P
|
||||||
for (const [l, v] of Object.entries(step.set)) sim.setSource(find(pins.inputs, l)!.key, v === 1)
|
for (const [l, v] of Object.entries(step.set)) sim.setSource(find(pins.inputs, l)!.key, v === 1)
|
||||||
if (!settle()) return out(false, left <= 0 ? 'The circuit takes too long to settle' : 'The circuit oscillates and never settles', delay)
|
if (!settle()) return out(false, left <= 0 ? 'The circuit takes too long to settle' : 'The circuit oscillates and never settles', delay)
|
||||||
for (const [l, want] of Object.entries(step.expect)) {
|
for (const [l, want] of Object.entries(step.expect)) {
|
||||||
const got = sim.pin(find(pins.outputs, l)!.key, 'a')
|
const got = sim.output(find(pins.outputs, l)!.key)
|
||||||
if (got !== want) {
|
if (got !== want) {
|
||||||
const ins = Object.entries(step.set).map(([k, v]) => `${k}=${v}`).join(' ')
|
const ins = Object.entries(step.set).map(([k, v]) => `${k}=${v}`).join(' ')
|
||||||
return out(false, `${spec.steps.length > 1 << spec.inputs.length ? `Step ${i + 1}: with` : 'With'} ${ins}: ${l} is ${got}, expected ${want}`, delay)
|
return out(false, `${spec.steps.length > 1 << spec.inputs.length ? `Step ${i + 1}: with` : 'With'} ${ins}: ${l} is ${got}, expected ${want}`, delay)
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,12 @@ export class Simulator {
|
||||||
return net === undefined ? 0 : this.values[net]!
|
return net === undefined ? 0 : this.values[net]!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** What an output pin of the root circuit puts out (a ChipPins output key), after any bubble on it. */
|
||||||
|
output(key: string): number {
|
||||||
|
const net = this.nl.outputs.get(key)
|
||||||
|
return net === undefined ? 0 : this.values[net]!
|
||||||
|
}
|
||||||
|
|
||||||
/** Value at a lamp or display input inside one of the root circuit's chips. */
|
/** Value at a lamp or display input inside one of the root circuit's chips. */
|
||||||
face(chipNode: string, node: string, pin: string): number {
|
face(chipNode: string, node: string, pin: string): number {
|
||||||
const net = this.nl.facePinNet.get(`${chipNode}/${node}:${pin}`)
|
const net = this.nl.facePinNet.get(`${chipNode}/${node}:${pin}`)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ function table(get: DefLookup, base: string): number[] | null {
|
||||||
sim.setSource(pins.inputs[0]!.key, (i & 2) !== 0)
|
sim.setSource(pins.inputs[0]!.key, (i & 2) !== 0)
|
||||||
sim.setSource(pins.inputs[1]!.key, (i & 1) !== 0)
|
sim.setSource(pins.inputs[1]!.key, (i & 1) !== 0)
|
||||||
if (!sim.run(200_000)) return null
|
if (!sim.run(200_000)) return null
|
||||||
out.push(sim.pin(pins.outputs[0]!.key, 'a'))
|
out.push(sim.output(pins.outputs[0]!.key))
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { describe, expect, it } from 'vitest'
|
import { describe, expect, it } from 'vitest'
|
||||||
import { nandCounts, stats } from '../app/lib/logic/analyze'
|
import { nandCounts, runSteps, stats, truthTable } from '../app/lib/logic/analyze'
|
||||||
import { transistorBreakdown } from '../app/lib/logic/bulk'
|
import { transistorBreakdown } from '../app/lib/logic/bulk'
|
||||||
import { compile } from '../app/lib/logic/compile'
|
import { compile } from '../app/lib/logic/compile'
|
||||||
import { chipPins } from '../app/lib/logic/geometry'
|
import { chipPins } from '../app/lib/logic/geometry'
|
||||||
|
|
@ -130,3 +130,53 @@ describe('inverted inputs', () => {
|
||||||
expect(stats(compile(lookup(p), 'outer')).nands).toBe(counts.get('outer'))
|
expect(stats(compile(lookup(p), 'outer')).nands).toBe(counts.get('outer'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('outputs as the checks read them', () => {
|
||||||
|
it('a bubble on an output pin counts in the truth table and the challenge check', () => {
|
||||||
|
// NOT: one NAND fed twice gives !A; a bubble on Q inverts it back to A.
|
||||||
|
const { p, def } = circuit(
|
||||||
|
[
|
||||||
|
{ id: 'a', kind: 'input', x: 0, y: 0, label: 'A' },
|
||||||
|
{ id: 'g', kind: 'nand', x: 6, y: 0 },
|
||||||
|
{ id: 'q', kind: 'output', x: 14, y: 0, label: 'Q', invert: ['a'] },
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ id: 'w1', from: { node: 'a', pin: 'q' }, to: { node: 'g', pin: 'a' } },
|
||||||
|
{ id: 'w2', from: { node: 'a', pin: 'q' }, to: { node: 'g', pin: 'b' } },
|
||||||
|
{ id: 'w3', from: { node: 'g', pin: 'q' }, to: { node: 'q', pin: 'a' } },
|
||||||
|
],
|
||||||
|
)
|
||||||
|
const t = truthTable(lookup(p), def.id)
|
||||||
|
expect('rows' in t && t.rows.map(r => r.outs[0])).toEqual([0, 1])
|
||||||
|
const steps = [
|
||||||
|
{ set: { A: 0 }, expect: { Q: 0 } },
|
||||||
|
{ set: { A: 1 }, expect: { Q: 1 } },
|
||||||
|
]
|
||||||
|
expect(runSteps(lookup(p), def.id, steps).pass).toBe(true)
|
||||||
|
// The output pin shows what leaves the circuit; its input pin shows the wire.
|
||||||
|
const s = run(p, def, { a: true })
|
||||||
|
expect([s.pin('q', 'a'), s.pin('q', 'q'), s.output('q')]).toEqual([0, 1, 1])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('rows of an output panel are outputs in the truth table', () => {
|
||||||
|
const { p, def } = circuit(
|
||||||
|
[
|
||||||
|
{ id: 'a', kind: 'input', x: 0, y: 0, label: 'A' },
|
||||||
|
{ id: 'g', kind: 'nand', x: 6, y: 0 },
|
||||||
|
{ id: 'op', kind: 'outpanel', x: 14, y: 0, rows: [{ id: 'r0', type: 'switch', label: 'Y' }, { id: 'r1', type: 'switch', label: 'Z' }] },
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ id: 'w1', from: { node: 'a', pin: 'q' }, to: { node: 'g', pin: 'a' } },
|
||||||
|
{ id: 'w2', from: { node: 'a', pin: 'q' }, to: { node: 'g', pin: 'b' } },
|
||||||
|
{ id: 'w3', from: { node: 'g', pin: 'q' }, to: { node: 'op', pin: 'r0' } },
|
||||||
|
{ id: 'w4', from: { node: 'a', pin: 'q' }, to: { node: 'op', pin: 'r1' } },
|
||||||
|
],
|
||||||
|
)
|
||||||
|
const t = truthTable(lookup(p), def.id)
|
||||||
|
expect('rows' in t && t.outputs).toEqual(['Y', 'Z'])
|
||||||
|
expect('rows' in t && t.rows.map(r => r.outs)).toEqual([
|
||||||
|
[1, 0],
|
||||||
|
[0, 1],
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue