Modern Apps git

← Modern-Apps.git

logicgate: plain-sentence level and chip text, moved into strings.xml

Commit
26294f941610ca0ccf44ecf7278405eb6af71299
Author
Vayun Mathur <[email protected]>
When
2026-11-04 20:25 UTC (1 month ago)
Parents
5265483
Rewrite every level brief, hint and chip blurb as full sentences a
teenager can follow, with jargon explained. Lists are kept only where a
chip has many unrelated outputs (decoder, CPU) or several modes (ALU,
program counter). Fixes ADD4/ADD8 blurbs naming the sum pin o instead
of s.

Level titles, briefs, hints, chip names and chip blurbs now live in
strings.xml as @StringRes ids. Gate names and other chip names that
languages localize are translatable; MUX/DMUX/DEC2/DFF abbreviations
are not. Gate-named level titles alias the chip name string so they
cannot drift. Chip boxes are sized from the localized name.

Diff

games/logicgate/AGENTS.md
diff --git a/games/logicgate/AGENTS.md b/games/logicgate/AGENTS.mdindex 353e09b162..b799fb1dba 100644--- a/games/logicgate/AGENTS.md+++ b/games/logicgate/AGENTS.md@@ -24,13 +24,14 @@ _Install: ./install games/logicgate (dev by default)._ **Gotchas:** - Pars are asserted equal to the reference solution costs in `src/test/.../domain/LevelSolutionsTest.kt`. Change a chip's `nandCost` and its reference together. - `ui/canvas/` is world-unit geometry (≈dp at 1×). `CameraState.scale` already includes density, so canvas text uses `sizeWorld.toSp()`.-- Nothing edits on finger-down. Chips are created by pulling them up out of the tray (`ChipTray`: an upward drag claims the gesture, a sideways one scrolls) or from `ui/ChipInfoSheet.kt`, opened by tapping a tray card (chip blurbs live in `domain/model/ChipInfo.kt`). Gates are deleted by dropping them back on the bottom area (`ui/canvas/TrashZone.kt`) or from the selection bar.+- Nothing edits on finger-down. Chips are created by pulling them up out of the tray (`ChipTray`: an upward drag claims the gesture, a sideways one scrolls) or from `ui/ChipInfoSheet.kt`, opened by tapping a tray card (chip names and blurbs are `strings.xml` resources mapped in `domain/model/ChipInfo.kt`; UI resolves names via `ui/ChipLabels.kt`). Gates are deleted by dropping them back on the bottom area (`ui/canvas/TrashZone.kt`) or from the selection bar.+- Level titles, briefs and hints are `@StringRes` ids (`lg_level_<id>_{title,brief,hint}`); gate-named level titles alias the chip name string. - Test rows carry plain-language titles (`domain/levels/RowTitles.kt`, e.g. `1 OR 1 = 1`), which are shown instead of row numbers.  ## Key files ### domain/ — pure, unit-tested - domain/model/Circuit.kt — nodes, pins, wires, immutable edits, `sanitized`-- domain/model/ChipSpec.kt, domain/model/Chips.kt, domain/model/ChipInfo.kt (tray tap blurbs), domain/model/Isa.kt+- domain/model/ChipSpec.kt, domain/model/Chips.kt, domain/model/ChipInfo.kt (chip name + blurb string ids), domain/model/Isa.kt - domain/sim/Simulator.kt, domain/sim/Scheduler.kt — tick semantics, SCC ordering - domain/sim/Verifier.kt, domain/sim/TestSpec.kt, domain/sim/Scoring.kt - domain/levels/LevelRegistry.kt + {Basics,Routing,Arithmetic,Memory,Cpu}Levels.kt
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/ArithmeticLevels.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/ArithmeticLevels.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/ArithmeticLevels.ktindex c34b2236d5..1d83829fd9 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/ArithmeticLevels.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/ArithmeticLevels.kt@@ -1,77 +1,78 @@ package com.vayunmathur.games.logicgate.domain.levels +import com.vayunmathur.games.logicgate.R import com.vayunmathur.games.logicgate.domain.model.Chips  internal val arithmeticLevels: List<LevelDef> = listOf(     chipLevel(         Chapter.ARITHMETIC, "half_adder", Chips.HALF,         LevelText(-            "Half adder",-            "Add two bits. s is the sum bit and c the carry.",-            "s is XOR and c is AND — and the NAND(a, b) inside an XOR is already NOT c.",+            R.string.lg_level_half_adder_title,+            R.string.lg_level_half_adder_brief,+            R.string.lg_level_half_adder_hint,         ),         title = RowTitles.half,     ),     chipLevel(         Chapter.ARITHMETIC, "full_adder", Chips.FULL,         LevelText(-            "Full adder",-            "Add three bits: a, b and a carry in.",-            "Two half adders and an OR work. Nine NANDs is the record.",+            R.string.lg_level_full_adder_title,+            R.string.lg_level_full_adder_brief,+            R.string.lg_level_full_adder_hint,         ),         title = RowTitles.full,     ),     chipLevel(         Chapter.ARITHMETIC, "add4", Chips.ADD4,         LevelText(-            "4-bit adder",-            "Add two 4-bit numbers and a carry in.",-            "Chain four full adders, each carry out feeding the next carry in.",+            R.string.lg_level_add4_title,+            R.string.lg_level_add4_brief,+            R.string.lg_level_add4_hint,         ),         title = RowTitles.add,     ),     chipLevel(         Chapter.ARITHMETIC, "add8", Chips.ADD8,         LevelText(-            "8-bit adder",-            "Add two bytes and a carry in.",-            "Two ADD4s, one per nibble.",+            R.string.lg_level_add8_title,+            R.string.lg_level_add8_brief,+            R.string.lg_level_add8_hint,         ),         title = RowTitles.add,     ),     chipLevel(         Chapter.ARITHMETIC, "inc4", Chips.INC4,         LevelText(-            "Incrementer",-            "Output a + 1, wrapping 15 round to 0.",-            "Bit 0 always flips. Every other bit is a half adder fed by the carry from below.",+            R.string.lg_level_inc4_title,+            R.string.lg_level_inc4_brief,+            R.string.lg_level_inc4_hint,         ),         title = RowTitles.inc,     ),     chipLevel(         Chapter.ARITHMETIC, "sub8", Chips.SUB8,         LevelText(-            "Subtractor",-            "Output a − b, wrapping below zero.",-            "In two's complement −b is NOT b + 1. Feed the + 1 in as the carry.",+            R.string.lg_level_sub8_title,+            R.string.lg_level_sub8_brief,+            R.string.lg_level_sub8_hint,         ),         title = RowTitles.sub,     ),     chipLevel(         Chapter.ARITHMETIC, "zero8", Chips.ZERO8,         LevelText(-            "Zero test",-            "Output 1 when every bit of a is 0.",-            "OR all eight bits together, then invert.",+            R.string.lg_level_zero8_title,+            R.string.lg_level_zero8_brief,+            R.string.lg_level_zero8_hint,         ),         title = RowTitles.zero,     ),     chipLevel(         Chapter.ARITHMETIC, "alu8", Chips.ALU8,         LevelText(-            "ALU",-            "op1 op0 picks the operation: 00 add, 01 subtract, 10 AND, 11 pass b. z is 1 when o is 0.",-            "Subtracting is adding NOT b with carry 1: XOR b with op0 to invert it on demand.",+            R.string.lg_level_alu8_title,+            R.string.lg_level_alu8_brief,+            R.string.lg_level_alu8_hint,         ),         title = RowTitles.alu,     ),
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/BasicsLevels.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/BasicsLevels.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/BasicsLevels.ktindex 7691361386..39fa405162 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/BasicsLevels.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/BasicsLevels.kt@@ -1,59 +1,60 @@ package com.vayunmathur.games.logicgate.domain.levels +import com.vayunmathur.games.logicgate.R import com.vayunmathur.games.logicgate.domain.model.Chips  internal val basicsLevels: List<LevelDef> = listOf(     chipLevel(         Chapter.BASICS, "not", Chips.NOT,         LevelText(-            "NOT",-            "Everything here is built from NAND. Make o the opposite of a.",-            "A NAND with both inputs tied to the same wire inverts it.",+            R.string.lg_level_not_title,+            R.string.lg_level_not_brief,+            R.string.lg_level_not_hint,         ),         title = RowTitles.not,     ),     chipLevel(         Chapter.BASICS, "and", Chips.AND,         LevelText(-            "AND",-            "Output 1 only when a and b are both 1.",-            "NAND is NOT-AND. Undo the NOT.",+            R.string.lg_level_and_title,+            R.string.lg_level_and_brief,+            R.string.lg_level_and_hint,         ),         title = RowTitles.infix("AND"),     ),     chipLevel(         Chapter.BASICS, "or", Chips.OR,         LevelText(-            "OR",-            "Output 1 when either input is 1.",-            "De Morgan: a OR b is NAND(NOT a, NOT b).",+            R.string.lg_level_or_title,+            R.string.lg_level_or_brief,+            R.string.lg_level_or_hint,         ),         title = RowTitles.infix("OR"),     ),     chipLevel(         Chapter.BASICS, "nor", Chips.NOR,         LevelText(-            "NOR",-            "Output 1 only when both inputs are 0.",-            "Invert an OR.",+            R.string.lg_level_nor_title,+            R.string.lg_level_nor_brief,+            R.string.lg_level_nor_hint,         ),         title = RowTitles.infix("NOR"),     ),     chipLevel(         Chapter.BASICS, "xor", Chips.XOR,         LevelText(-            "XOR",-            "Output 1 when the inputs differ.",-            "Four NANDs: NAND(a, b) goes into two more NANDs, one with a and one with b; NAND their outputs.",+            R.string.lg_level_xor_title,+            R.string.lg_level_xor_brief,+            R.string.lg_level_xor_hint,         ),         title = RowTitles.infix("XOR"),     ),     chipLevel(         Chapter.BASICS, "xnor", Chips.XNOR,         LevelText(-            "XNOR",-            "Output 1 when the inputs match.",-            "Invert an XOR.",+            R.string.lg_level_xnor_title,+            R.string.lg_level_xnor_brief,+            R.string.lg_level_xnor_hint,         ),         title = RowTitles.infix("XNOR"),     ),
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/ChipLevel.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/ChipLevel.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/ChipLevel.ktindex 3bf3e518d6..4d9a0e9eb7 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/ChipLevel.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/ChipLevel.kt@@ -1,5 +1,6 @@ package com.vayunmathur.games.logicgate.domain.levels +import androidx.annotation.StringRes import com.vayunmathur.games.logicgate.domain.sim.TestSpec  /** A level whose pins, tests and par all come from the chip it rewards, so they cannot drift apart. */@@ -28,4 +29,4 @@ internal fun chipLevel( }  /** The words of a level. */-internal data class LevelText(val title: String, val brief: String, val hint: String)+internal data class LevelText(@StringRes val title: Int, @StringRes val brief: Int, @StringRes val hint: Int)
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/CpuLevels.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/CpuLevels.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/CpuLevels.ktindex b2576a3591..c9e524d2fe 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/CpuLevels.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/CpuLevels.kt@@ -1,5 +1,6 @@ package com.vayunmathur.games.logicgate.domain.levels +import com.vayunmathur.games.logicgate.R import com.vayunmathur.games.logicgate.domain.model.Chips import com.vayunmathur.games.logicgate.domain.model.Isa import com.vayunmathur.games.logicgate.domain.model.Isa.encode@@ -51,38 +52,27 @@ internal val cpuLevels: List<LevelDef> = listOf(     chipLevel(         Chapter.CPU, "decoder", Chips.DECODER,         LevelText(-            "Instruction decoder",-            "op is a 4-bit opcode (top bit unused): 0 LDA · 1 STA · 2 ADD · 3 SUB · 4 LDI · 5 JMP · 6 JZ · 7 HLT.\n" +-                "What each output does:\n" +-                "• aluOp1 aluOp0 — ALU operation: 00 add · 01 subtract · 11 pass b. ADD adds, SUB subtracts, " +-                "LDA and LDI pass b. Only checked when accLoad is 1.\n" +-                "• accLoad — 1 for LDA, ADD, SUB, LDI: the ALU result is stored into acc.\n" +-                "• memWrite — 1 for STA: acc is written to memory.\n" +-                "• useImm — 1 for LDI: the ALU takes the operand itself, not memory.\n" +-                "• jump — 1 for JMP; for JZ only when z is 1.\n" +-                "• halt — 1 for HLT.",-            "Split op, decode its low three bits into eight lines, then OR together the lines each control needs.",+            R.string.lg_level_decoder_title,+            R.string.lg_level_decoder_brief,+            R.string.lg_level_decoder_hint,         ),         tests = decoderTests,     ),     chipLevel(         Chapter.CPU, "cpu", Chips.CPU,         LevelText(-            "CPU",-            "Each tick, instr is the byte at pc and data is the byte at addr. Run the instruction: update acc " +-                "and pc, and to store put acc on dout and raise we. Tested by running real programs.",-            "operand → addr and PC4 v · ALU(acc, data or operand) → REG8 acc · ZERO8(acc) → decoder z · " +-                "NOT halt → PC4 en.",+            R.string.lg_level_cpu_title,+            R.string.lg_level_cpu_brief,+            R.string.lg_level_cpu_hint,         ),         tests = TestSpec.Programs(cpuPrograms, harness = true),     ),     LevelDef(         id = "computer",         chapter = Chapter.CPU,-        title = "Computer",-        brief = "Wire your CPU to a RAM16. Three programs get loaded into the RAM: add two numbers, count down, " +-            "and multiply 3 × 4.",-        hint = "pc → iaddr, addr → daddr, dout → din, we → we; instr and dout go back into the CPU.",+        title = R.string.lg_level_computer_title,+        brief = R.string.lg_level_computer_brief,+        hint = R.string.lg_level_computer_hint,         inputs = emptyList(),         outputs = listOf(Pin("acc", 8), Pin("halt")),         tests = TestSpec.Programs(cpuPrograms, harness = false),
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/LevelDef.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/LevelDef.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/LevelDef.ktindex 09eba5dc25..a16ebf73cf 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/LevelDef.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/LevelDef.kt@@ -1,5 +1,6 @@ package com.vayunmathur.games.logicgate.domain.levels +import androidx.annotation.StringRes import com.vayunmathur.games.logicgate.domain.model.LevelIo import com.vayunmathur.games.logicgate.domain.model.Pin import com.vayunmathur.games.logicgate.domain.sim.TestSpec@@ -14,9 +15,9 @@ enum class Chapter { BASICS, ROUTING, ARITHMETIC, MEMORY, CPU } data class LevelDef(     val id: String,     val chapter: Chapter,-    val title: String,-    val brief: String,-    val hint: String,+    @StringRes val title: Int,+    @StringRes val brief: Int,+    @StringRes val hint: Int,     val inputs: List<Pin>,     val outputs: List<Pin>,     val tests: TestSpec,
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/MemoryLevels.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/MemoryLevels.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/MemoryLevels.ktindex 6c9c871e86..7980e294dc 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/MemoryLevels.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/MemoryLevels.kt@@ -1,5 +1,6 @@ package com.vayunmathur.games.logicgate.domain.levels +import com.vayunmathur.games.logicgate.R import com.vayunmathur.games.logicgate.domain.model.Chips import com.vayunmathur.games.logicgate.domain.model.Pin import com.vayunmathur.games.logicgate.domain.sim.Case@@ -12,9 +13,9 @@ internal val memoryLevels: List<LevelDef> = listOf(     LevelDef(         id = "sr_latch",         chapter = Chapter.MEMORY,-        title = "SR latch",-        brief = "Memory from feedback. s sets q to 1, r resets it to 0, and with both low q holds. nq is always NOT q.",-        hint = "Two NORs, each one's output wired into the other's input.",+        title = R.string.lg_level_sr_latch_title,+        brief = R.string.lg_level_sr_latch_brief,+        hint = R.string.lg_level_sr_latch_hint,         inputs = listOf(Pin("s"), Pin("r")),         outputs = listOf(Pin("q"), Pin("nq")),         tests = ticks(@@ -33,9 +34,9 @@ internal val memoryLevels: List<LevelDef> = listOf(     LevelDef(         id = "d_latch",         chapter = Chapter.MEMORY,-        title = "D latch",-        brief = "While en is 1, q follows d. When en drops to 0, q holds its last value.",-        hint = "Build an SR latch and drive its set and reset from d and en.",+        title = R.string.lg_level_d_latch_title,+        brief = R.string.lg_level_d_latch_brief,+        hint = R.string.lg_level_d_latch_hint,         inputs = listOf(Pin("d"), Pin("en")),         outputs = listOf(Pin("q")),         tests = ticks(@@ -56,9 +57,9 @@ internal val memoryLevels: List<LevelDef> = listOf(     chipLevel(         Chapter.MEMORY, "bit", Chips.BIT,         LevelText(-            "1-bit register",-            "A DFF stores its input on every tick. Build one that only stores when load is 1; q shows the stored bit.",-            "Feed the DFF from a MUX choosing between d and the DFF's own output.",+            R.string.lg_level_bit_title,+            R.string.lg_level_bit_brief,+            R.string.lg_level_bit_hint,         ),         tests = TestGen.seqFromChip(             Chips.BIT,@@ -72,9 +73,9 @@ internal val memoryLevels: List<LevelDef> = listOf(     chipLevel(         Chapter.MEMORY, "reg8", Chips.REG8,         LevelText(-            "8-bit register",-            "The same, a byte wide.",-            "A MUX8b in front of a DFF8.",+            R.string.lg_level_reg8_title,+            R.string.lg_level_reg8_brief,+            R.string.lg_level_reg8_hint,         ),         tests = TestGen.seqFromChip(             Chips.REG8,@@ -88,10 +89,9 @@ internal val memoryLevels: List<LevelDef> = listOf(     chipLevel(         Chapter.MEMORY, "pc4", Chips.PC4,         LevelText(-            "Program counter",-            "Each tick: if load is 1, jump to v; otherwise if en is 1, count up by one (15 wraps to 0); " +-                "otherwise hold.",-            "An INC4 and two MUX4bs in front of a DFF4.",+            R.string.lg_level_pc4_title,+            R.string.lg_level_pc4_brief,+            R.string.lg_level_pc4_hint,         ),         tests = TestGen.seqFromChip(             Chips.PC4,@@ -106,9 +106,9 @@ internal val memoryLevels: List<LevelDef> = listOf(     chipLevel(         Chapter.MEMORY, "ram4", Chips.RAM4,         LevelText(-            "RAM",-            "Four bytes. dout always shows the byte at address a1 a0; when we is 1, that byte becomes din on the tick.",-            "A DEC2 picks which REG8 loads; MUX8bs pick which one is read.",+            R.string.lg_level_ram4_title,+            R.string.lg_level_ram4_brief,+            R.string.lg_level_ram4_hint,         ),         unlocks = listOf(Chips.RAM4, Chips.RAM16),         tests = TestGen.seqFromChip(
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/RoutingLevels.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/RoutingLevels.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/RoutingLevels.ktindex 10878d9057..50690bb6ad 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/RoutingLevels.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/levels/RoutingLevels.kt@@ -1,5 +1,6 @@ package com.vayunmathur.games.logicgate.domain.levels +import com.vayunmathur.games.logicgate.R import com.vayunmathur.games.logicgate.domain.model.Chips import com.vayunmathur.games.logicgate.domain.model.Pin @@ -13,36 +14,36 @@ internal val routingLevels: List<LevelDef> = listOf(     chipLevel(         Chapter.ROUTING, "mux", Chips.MUX,         LevelText(-            "MUX",-            "A selector: o is a when s is 0, and b when s is 1.",-            "AND a with NOT s and b with s, then OR the two. In NANDs it is just four gates.",+            R.string.lg_level_mux_title,+            R.string.lg_level_mux_brief,+            R.string.lg_level_mux_hint,         ),         title = RowTitles.mux,     ),     chipLevel(         Chapter.ROUTING, "dmux", Chips.DMUX,         LevelText(-            "DMUX",-            "Send in to a when s is 0, or to b when s is 1. The other output stays 0.",-            "a = in AND NOT s, b = in AND s.",+            R.string.lg_level_dmux_title,+            R.string.lg_level_dmux_brief,+            R.string.lg_level_dmux_hint,         ),         title = RowTitles.dmux,     ),     chipLevel(         Chapter.ROUTING, "dec2", Chips.DEC2,         LevelText(-            "Decoder",-            "Light exactly one of y0–y3: the one numbered by s1 s0 (s1 is the high bit).",-            "Each output is an AND of s1 or NOT s1 with s0 or NOT s0.",+            R.string.lg_level_dec2_title,+            R.string.lg_level_dec2_brief,+            R.string.lg_level_dec2_hint,         ),         title = RowTitles.dec2,     ),     LevelDef(         id = "nibble_swap",         chapter = Chapter.ROUTING,-        title = "Nibble swap",-        brief = "Thick wires are buses carrying 4 or 8 bits at once. Swap the low and high halves of x.",-        hint = "NIB SPLIT gives the two halves; cross them into a NIB JOIN.",+        title = R.string.lg_level_nibble_swap_title,+        brief = R.string.lg_level_nibble_swap_brief,+        hint = R.string.lg_level_nibble_swap_hint,         inputs = listOf(Pin("x", 8)),         outputs = listOf(Pin("y", 8)),         tests = TestGen.comb(listOf(Pin("x", 8)), seed = 10, RowTitles.nibbleSwap) {@@ -54,9 +55,9 @@ internal val routingLevels: List<LevelDef> = listOf(     chipLevel(         Chapter.ROUTING, "bus_mux", Chips.MUX8B,         LevelText(-            "Bus MUX",-            "Choose between two whole bytes. The one tedious bus level: solve it and every bus-wide gate is yours.",-            "Split both buses, use eight MUXes, and join the results.",+            R.string.lg_level_bus_mux_title,+            R.string.lg_level_bus_mux_brief,+            R.string.lg_level_bus_mux_hint,         ),         title = RowTitles.busMux,         unlocks = bitwisePack,
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/ChipInfo.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/ChipInfo.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/ChipInfo.ktindex 34be2c8e3d..f69283daa2 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/ChipInfo.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/ChipInfo.kt@@ -1,76 +1,70 @@ package com.vayunmathur.games.logicgate.domain.model +import androidx.annotation.StringRes+import com.vayunmathur.games.logicgate.R+ /**- * One- or two-sentence explanations of each chip, shown when a chip card in the tray is tapped.- * Plain English like the level briefs; every chip in [Chips.all] has an entry (guarded by a test).+ * Each chip's localized name (tray, canvas, sheets) and its plain-English explanation, shown when a+ * chip card in the tray is tapped. Every chip in [Chips.all] has an entry (guarded by a test).  */ object ChipInfo { -    private val blurbs = mapOf(-        Chips.NAND to "The gate everything starts from: o is 0 only when a and b are both 1. " +-            "Every other chip in the game is built from NANDs alone.",-        Chips.HIGH to "No inputs; o is always 1.",-        Chips.LOW to "No inputs; o is always 0.",-        Chips.NOT to "o is the opposite of a: 1 becomes 0, 0 becomes 1.",-        Chips.AND to "o is 1 only when a and b are both 1.",-        Chips.OR to "o is 1 when a, b or both are 1.",-        Chips.NOR to "OR then NOT: o is 1 only when a and b are both 0. " +-            "Two NORs wired into each other make an SR latch.",-        Chips.XOR to "o is 1 when a and b differ.",-        Chips.XNOR to "o is 1 when a and b are equal.",+    private class ChipText(@StringRes val label: Int, @StringRes val blurb: Int)++    private val texts = mapOf(+        Chips.NAND to ChipText(R.string.lg_chip_nand_label, R.string.lg_chip_nand_info),+        Chips.HIGH to ChipText(R.string.lg_chip_high_label, R.string.lg_chip_high_info),+        Chips.LOW to ChipText(R.string.lg_chip_low_label, R.string.lg_chip_low_info),+        Chips.NOT to ChipText(R.string.lg_chip_not_label, R.string.lg_chip_not_info),+        Chips.AND to ChipText(R.string.lg_chip_and_label, R.string.lg_chip_and_info),+        Chips.OR to ChipText(R.string.lg_chip_or_label, R.string.lg_chip_or_info),+        Chips.NOR to ChipText(R.string.lg_chip_nor_label, R.string.lg_chip_nor_info),+        Chips.XOR to ChipText(R.string.lg_chip_xor_label, R.string.lg_chip_xor_info),+        Chips.XNOR to ChipText(R.string.lg_chip_xnor_label, R.string.lg_chip_xnor_info), -        Chips.MUX to "Picks one of two inputs: o copies a while s is 0, b while s is 1.",-        Chips.DMUX to "The reverse of a MUX: in goes to a while s is 0, to b while s is 1. " +-            "The other output stays 0.",-        Chips.DEC2 to "One-hot decoder: the 2-bit number s1 s0 selects exactly one of y0–y3 to be 1; " +-            "the rest stay 0.",-        Chips.SPLIT8 to "Splits an 8-bit bus into its eight bits, b0 (lowest) to b7 (highest).",-        Chips.JOIN8 to "Packs eight bits, b0 (lowest) to b7 (highest), into one 8-bit bus.",-        Chips.SPLIT4 to "Splits a 4-bit bus into its four bits, b0 (lowest) to b3 (highest).",-        Chips.JOIN4 to "Packs four bits, b0 (lowest) to b3 (highest), into one 4-bit bus.",-        Chips.NIB_SPLIT to "Splits a byte into its two halves: lo is the low 4 bits, hi the high 4.",-        Chips.NIB_JOIN to "Packs a low and a high 4-bit half into one byte.",-        Chips.NOT8 to "Flips all eight bits of a at once.",-        Chips.AND8 to "Bitwise AND on bytes: each output bit is 1 only where a and b both have a 1.",-        Chips.OR8 to "Bitwise OR on bytes: each output bit is 1 where a or b has a 1.",-        Chips.XOR8 to "Bitwise XOR on bytes: each output bit is 1 where a and b differ.",-        Chips.MUX8B to "A byte-wide MUX: o copies a while s is 0, b while s is 1.",-        Chips.MUX4B to "A 4-bit-wide MUX: o copies a while s is 0, b while s is 1.",+        Chips.MUX to ChipText(R.string.lg_chip_mux_label, R.string.lg_chip_mux_info),+        Chips.DMUX to ChipText(R.string.lg_chip_dmux_label, R.string.lg_chip_dmux_info),+        Chips.DEC2 to ChipText(R.string.lg_chip_dec2_label, R.string.lg_chip_dec2_info),+        Chips.SPLIT8 to ChipText(R.string.lg_chip_split8_label, R.string.lg_chip_split8_info),+        Chips.JOIN8 to ChipText(R.string.lg_chip_join8_label, R.string.lg_chip_join8_info),+        Chips.SPLIT4 to ChipText(R.string.lg_chip_split4_label, R.string.lg_chip_split4_info),+        Chips.JOIN4 to ChipText(R.string.lg_chip_join4_label, R.string.lg_chip_join4_info),+        Chips.NIB_SPLIT to ChipText(R.string.lg_chip_nib_split_label, R.string.lg_chip_nib_split_info),+        Chips.NIB_JOIN to ChipText(R.string.lg_chip_nib_join_label, R.string.lg_chip_nib_join_info),+        Chips.NOT8 to ChipText(R.string.lg_chip_not8_label, R.string.lg_chip_not8_info),+        Chips.AND8 to ChipText(R.string.lg_chip_and8_label, R.string.lg_chip_and8_info),+        Chips.OR8 to ChipText(R.string.lg_chip_or8_label, R.string.lg_chip_or8_info),+        Chips.XOR8 to ChipText(R.string.lg_chip_xor8_label, R.string.lg_chip_xor8_info),+        Chips.MUX8B to ChipText(R.string.lg_chip_mux8b_label, R.string.lg_chip_mux8b_info),+        Chips.MUX4B to ChipText(R.string.lg_chip_mux4b_label, R.string.lg_chip_mux4b_info), -        Chips.HALF to "Half adder: s is the sum of a and b, c is the carry into the next column.",-        Chips.FULL to "Full adder: adds a + b + cin; s is the sum bit, cout the carry into the next column.",-        Chips.ADD4 to "Adds two 4-bit numbers and cin; o is the 4-bit sum, cout the carry out. " +-            "Overflow wraps around.",-        Chips.ADD8 to "Adds two bytes and cin; o is the sum, cout the carry out. Overflow wraps around.",-        Chips.INC4 to "Counts up: o is a + 1. 15 wraps back to 0.",-        Chips.SUB8 to "d is a − b, wrapping modulo 256.",-        Chips.ZERO8 to "z is 1 only when every bit of a is 0 — the flag a CPU needs for jumps.",-        Chips.ALU8 to "Arithmetic and logic in one chip: op1 op0 choose 00 = a + b, 01 = a − b, " +-            "10 = a AND b, 11 = b. z is 1 when the result is 0.",+        Chips.HALF to ChipText(R.string.lg_chip_half_label, R.string.lg_chip_half_info),+        Chips.FULL to ChipText(R.string.lg_chip_full_label, R.string.lg_chip_full_info),+        Chips.ADD4 to ChipText(R.string.lg_chip_add4_label, R.string.lg_chip_add4_info),+        Chips.ADD8 to ChipText(R.string.lg_chip_add8_label, R.string.lg_chip_add8_info),+        Chips.INC4 to ChipText(R.string.lg_chip_inc4_label, R.string.lg_chip_inc4_info),+        Chips.SUB8 to ChipText(R.string.lg_chip_sub8_label, R.string.lg_chip_sub8_info),+        Chips.ZERO8 to ChipText(R.string.lg_chip_zero8_label, R.string.lg_chip_zero8_info),+        Chips.ALU8 to ChipText(R.string.lg_chip_alu8_label, R.string.lg_chip_alu8_info), -        Chips.DFF to "The memory primitive. q always shows the stored bit, and every tick of the " +-            "clock stores whatever d is — so q is d delayed by one tick. It never reads d while " +-            "settling, which is what breaks feedback loops.",-        Chips.DFF4 to "Four DFFs in one chip: stores a 4-bit number every tick.",-        Chips.DFF8 to "Eight DFFs in one chip: stores a byte every tick.",-        Chips.BIT to "A 1-bit register: on the tick it stores d when load is 1, " +-            "and holds its bit when load is 0.",-        Chips.REG8 to "A byte register: on the tick it stores d when load is 1, " +-            "and holds its byte when load is 0.",-        Chips.PC4 to "Program counter: on each tick it jumps to v when load is 1, " +-            "else counts up when en is 1 (15 wraps to 0), else holds.",-        Chips.RAM4 to "Four bytes of memory. dout always shows the byte at address a1 a0; " +-            "on the tick, din replaces that byte when we is 1.",-        Chips.RAM16 to "Sixteen bytes with two read ports: instr shows the byte at iaddr, dout the " +-            "byte at daddr. On the tick, din is written to daddr when we is 1.",+        Chips.DFF to ChipText(R.string.lg_chip_dff_label, R.string.lg_chip_dff_info),+        Chips.DFF4 to ChipText(R.string.lg_chip_dff4_label, R.string.lg_chip_dff4_info),+        Chips.DFF8 to ChipText(R.string.lg_chip_dff8_label, R.string.lg_chip_dff8_info),+        Chips.BIT to ChipText(R.string.lg_chip_bit_label, R.string.lg_chip_bit_info),+        Chips.REG8 to ChipText(R.string.lg_chip_reg8_label, R.string.lg_chip_reg8_info),+        Chips.PC4 to ChipText(R.string.lg_chip_pc4_label, R.string.lg_chip_pc4_info),+        Chips.RAM4 to ChipText(R.string.lg_chip_ram4_label, R.string.lg_chip_ram4_info),+        Chips.RAM16 to ChipText(R.string.lg_chip_ram16_label, R.string.lg_chip_ram16_info), -        Chips.DECODER to "Instruction decoder: from the 4-bit opcode and the z flag it produces the " +-            "CPU's control signals — aluOp1 aluOp0, accLoad, memWrite, useImm, jump and halt.",-        Chips.CPU to "A complete processor. Each tick it executes the instruction on instr, driving " +-            "pc, addr, dout and we to talk to RAM and reading data back; acc is the accumulator and " +-            "halt goes 1 when the program ends.",+        Chips.DECODER to ChipText(R.string.lg_chip_decoder_label, R.string.lg_chip_decoder_info),+        Chips.CPU to ChipText(R.string.lg_chip_cpu_label, R.string.lg_chip_cpu_info),     ) -    /** The explanation of [chipId], or null for a chip with no entry. */-    fun of(chipId: String): String? = blurbs[chipId]+    /** The name of [chipId] as a string resource, or null for a chip with no entry. */+    @StringRes+    fun label(chipId: String): Int? = texts[chipId]?.label++    /** The explanation of [chipId] as a string resource, or null for a chip with no entry. */+    @StringRes+    fun blurb(chipId: String): Int? = texts[chipId]?.blurb }
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/ChipSpec.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/ChipSpec.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/ChipSpec.ktindex d91c9a0f2f..2d70405467 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/ChipSpec.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/ChipSpec.kt@@ -25,7 +25,6 @@ sealed interface Behavior { /** A placeable chip: its pins, what it costs in NAND gates, and its trusted native behaviour. */ data class ChipSpec(     val id: String,-    val label: String,     val inputs: List<Pin>,     val outputs: List<Pin>,     val nandCost: Int,
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/Chips.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/Chips.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/Chips.ktindex 957002db2d..1afe008114 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/Chips.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/domain/model/Chips.kt@@ -59,18 +59,17 @@ object Chips {         inputs: List<Pin>,         outputs: List<Pin>,         cost: Int,-        label: String = id,         f: (IntArray) -> IntArray,-    ) = ChipSpec(id, label, inputs, outputs, cost, Behavior.Comb(f))+    ) = ChipSpec(id, inputs, outputs, cost, Behavior.Comb(f))      private fun gate2(id: String, cost: Int, f: (Int, Int) -> Int) =         comb(id, listOf(p("a"), p("b")), listOf(p("o")), cost) { intArrayOf(f(it[0], it[1]) and 1) } -    private fun split(id: String, n: Int, label: String) =-        comb(id, listOf(p("x", n)), bits("b", n), 0, label) { v -> IntArray(n) { (v[0] shr it) and 1 } }+    private fun split(id: String, n: Int) =+        comb(id, listOf(p("x", n)), bits("b", n), 0) { v -> IntArray(n) { (v[0] shr it) and 1 } } -    private fun join(id: String, n: Int, label: String) =-        comb(id, bits("b", n), listOf(p("x", n)), 0, label) { v ->+    private fun join(id: String, n: Int) =+        comb(id, bits("b", n), listOf(p("x", n)), 0) { v ->             intArrayOf(v.foldIndexed(0) { i, acc, b -> acc or ((b and 1) shl i) })         } @@ -100,14 +99,14 @@ object Chips {             val sel = v[0] * 2 + v[1]             IntArray(4) { if (it == sel) 1 else 0 }         },-        split(SPLIT8, 8, "SPLIT 8"),-        join(JOIN8, 8, "JOIN 8"),-        split(SPLIT4, 4, "SPLIT 4"),-        join(JOIN4, 4, "JOIN 4"),-        comb(NIB_SPLIT, listOf(p("x", 8)), listOf(p("lo", 4), p("hi", 4)), 0, "NIB SPLIT") {+        split(SPLIT8, 8),+        join(JOIN8, 8),+        split(SPLIT4, 4),+        join(JOIN4, 4),+        comb(NIB_SPLIT, listOf(p("x", 8)), listOf(p("lo", 4), p("hi", 4)), 0) {             intArrayOf(it[0] and 0xF, it[0] shr 4)         },-        comb(NIB_JOIN, listOf(p("lo", 4), p("hi", 4)), listOf(p("x", 8)), 0, "NIB JOIN") {+        comb(NIB_JOIN, listOf(p("lo", 4), p("hi", 4)), listOf(p("x", 8)), 0) {             intArrayOf(it[0] or (it[1] shl 4))         },         comb(NOT8, listOf(p("a", 8)), listOf(p("o", 8)), 8) { intArrayOf(it[0].inv() and 0xFF) },@@ -150,7 +149,7 @@ object Chips {     private fun register(id: String, width: Int, cost: Int, withLoad: Boolean): ChipSpec {         val ins = if (withLoad) listOf(p("d", width), p("load")) else listOf(p("d", width))         return ChipSpec(-            id, id, ins, listOf(p("q", width)), cost,+            id, ins, listOf(p("q", width)), cost,             Behavior.Seq(                 init = IntArray(1),                 outputs = { s, _ -> intArrayOf(s[0]) },@@ -166,7 +165,7 @@ object Chips {         register(BIT, 1, 12, withLoad = true),         register(REG8, 8, 96, withLoad = true),         ChipSpec(-            PC4, PC4, listOf(p("en"), p("load"), p("v", 4)), listOf(p("pc", 4)), 80,+            PC4, listOf(p("en"), p("load"), p("v", 4)), listOf(p("pc", 4)), 80,             Behavior.Seq(                 init = IntArray(1),                 outputs = { s, _ -> intArrayOf(s[0]) },@@ -174,7 +173,7 @@ object Chips {             ),         ),         ChipSpec(-            RAM4, RAM4, listOf(p("a1"), p("a0"), p("din", 8), p("we")), listOf(p("dout", 8)), 498,+            RAM4, listOf(p("a1"), p("a0"), p("din", 8), p("we")), listOf(p("dout", 8)), 498,             Behavior.Seq(                 init = IntArray(4),                 outputs = { s, i -> intArrayOf(s[i[0] * 2 + i[1]]) },@@ -183,7 +182,7 @@ object Chips {             ),         ),         ChipSpec(-            RAM16, RAM16, listOf(p("iaddr", 4), p("daddr", 4), p("din", 8), p("we")),+            RAM16, listOf(p("iaddr", 4), p("daddr", 4), p("din", 8), p("we")),             listOf(p("instr", 8), p("dout", 8)), 2560,             Behavior.Seq(                 init = IntArray(16),@@ -197,7 +196,7 @@ object Chips {     private val cpu = listOf(         comb(DECODER, listOf(p("op", 4), p("z")), Isa.decoderOutputs, 44) { Isa.decode(it[0], it[1]) },         ChipSpec(-            CPU, CPU, listOf(p("instr", 8), p("data", 8)), Isa.cpuOutputs, 481,+            CPU, listOf(p("instr", 8), p("data", 8)), Isa.cpuOutputs, 481,             Behavior.Seq(                 init = IntArray(2),                 outputs = { s, i -> Isa.cpuOut(s[0], s[1], i[0]) },
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/platform/LogicUiContract.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/platform/LogicUiContract.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/platform/LogicUiContract.ktindex b651eb6955..bb903f6c42 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/platform/LogicUiContract.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/platform/LogicUiContract.kt@@ -1,5 +1,6 @@ package com.vayunmathur.games.logicgate.platform +import androidx.annotation.StringRes import com.vayunmathur.games.logicgate.domain.levels.Chapter import com.vayunmathur.games.logicgate.domain.levels.LevelDef import com.vayunmathur.games.logicgate.domain.model.ChipSpec@@ -20,7 +21,7 @@ import com.vayunmathur.games.logicgate.domain.sim.VerifyResult data class LevelCard(     val id: String,     val number: Int,-    val title: String,+    @StringRes val title: Int,     val chapter: Chapter,     val unlocked: Boolean,     val stars: Int,
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/BriefSheet.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/BriefSheet.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/BriefSheet.ktindex 2e578a23f4..db8338be31 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/BriefSheet.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/BriefSheet.kt@@ -16,7 +16,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import com.vayunmathur.games.logicgate.R import com.vayunmathur.games.logicgate.domain.levels.LevelDef-import com.vayunmathur.games.logicgate.domain.model.Chips import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.IconLightbulb import com.vayunmathur.library.ui.MaterialTheme@@ -39,12 +38,12 @@ fun BriefSheet(level: LevelDef, number: Int, onDismiss: () -> Unit) {                 .padding(bottom = Spacing.xl),             verticalArrangement = Arrangement.spacedBy(Spacing.md),         ) {-            Text(stringResource(R.string.lg_level_title, number, level.title), style = MaterialTheme.typography.headlineSmall)-            Text(level.brief, style = MaterialTheme.typography.bodyLarge)+            Text(stringResource(R.string.lg_level_title, number, stringResource(level.title)), style = MaterialTheme.typography.headlineSmall)+            Text(stringResource(level.brief), style = MaterialTheme.typography.bodyLarge)             PinLine(stringResource(R.string.lg_brief_inputs), level.inputs)             PinLine(stringResource(R.string.lg_brief_outputs), level.outputs)             if (level.unlocks.isNotEmpty()) {-                val chips = level.unlocks.joinToString { Chips[it]?.label ?: it }+                val chips = level.unlocks.map { chipLabel(it) }.joinToString()                 Text(stringResource(R.string.lg_brief_unlocks, chips), color = MaterialTheme.colorScheme.primary)             }             Text(@@ -56,7 +55,7 @@ fun BriefSheet(level: LevelDef, number: Int, onDismiss: () -> Unit) {                 Surface(color = MaterialTheme.colorScheme.secondaryContainer, shape = MaterialTheme.shapes.medium) {                     Row(Modifier.padding(Spacing.md), horizontalArrangement = Arrangement.spacedBy(Spacing.sm)) {                         IconLightbulb(tint = MaterialTheme.colorScheme.tertiary)-                        Text(level.hint)+                        Text(stringResource(level.hint))                     }                 }             } else {
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipInfoSheet.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipInfoSheet.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipInfoSheet.ktindex 473b417591..9834c7a84c 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipInfoSheet.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipInfoSheet.kt@@ -33,13 +33,13 @@ fun ChipInfoSheet(chip: ChipSpec, onAdd: () -> Unit, onDismiss: () -> Unit) {                 .padding(bottom = Spacing.xl),             verticalArrangement = Arrangement.spacedBy(Spacing.md),         ) {-            Text(chip.label, style = MaterialTheme.typography.headlineSmall)+            Text(chipLabel(chip.id), style = MaterialTheme.typography.headlineSmall)             Text(                 stringResource(R.string.lg_cost, chip.nandCost),                 style = MaterialTheme.typography.labelLarge,                 color = MaterialTheme.colorScheme.onSurfaceVariant,             )-            ChipInfo.of(chip.id)?.let { Text(it, style = MaterialTheme.typography.bodyLarge) }+            ChipInfo.blurb(chip.id)?.let { Text(stringResource(it), style = MaterialTheme.typography.bodyLarge) }             PinLine(stringResource(R.string.lg_brief_inputs), chip.inputs)             PinLine(stringResource(R.string.lg_brief_outputs), chip.outputs)             Button(onClick = onAdd, modifier = Modifier.fillMaxWidth()) { Text(stringResource(R.string.lg_add_to_board)) }
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipLabels.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipLabels.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipLabels.ktnew file mode 100644index 0000000000..1eb3dcdf21--- /dev/null+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipLabels.kt@@ -0,0 +1,21 @@+package com.vayunmathur.games.logicgate.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.remember+import androidx.compose.ui.platform.LocalResources+import androidx.compose.ui.res.stringResource+import com.vayunmathur.games.logicgate.domain.model.ChipInfo+import com.vayunmathur.games.logicgate.domain.model.Chips++/** The localized name of [chipId], falling back to the id. */+@Composable+fun chipLabel(chipId: String): String = ChipInfo.label(chipId)?.let { stringResource(it) } ?: chipId++/** Every chip's localized name by id, for measuring and drawing outside composition. */+@Composable+fun rememberChipLabels(): Map<String, String> {+    val resources = LocalResources.current+    return remember(resources) {+        Chips.all.associate { chip -> chip.id to (ChipInfo.label(chip.id)?.let(resources::getString) ?: chip.id) }+    }+}
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipTray.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipTray.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipTray.ktindex 5d2e21fd96..d372bddc75 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipTray.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipTray.kt@@ -74,7 +74,7 @@ private fun ChipCard(     onDrop: (TrayDrag) -> Unit, ) {     var coords by remember { mutableStateOf<LayoutCoordinates?>(null) }-    val description = stringResource(R.string.lg_cd_chip, chip.label, chip.nandCost)+    val description = stringResource(R.string.lg_cd_chip, chipLabel(chip.id), chip.nandCost)     val widest = (chip.inputs + chip.outputs).maxOfOrNull { it.width } ?: 1     Surface(         onClick = { onTap(chip.id) },@@ -110,7 +110,7 @@ private fun ChipCard(             verticalArrangement = Arrangement.Center,             horizontalAlignment = Alignment.CenterHorizontally,         ) {-            Text(chip.label, fontWeight = FontWeight.Bold, style = MaterialTheme.typography.labelLarge)+            Text(chipLabel(chip.id), fontWeight = FontWeight.Bold, style = MaterialTheme.typography.labelLarge)             Row(horizontalArrangement = Arrangement.spacedBy(Spacing.xs)) {                 Text(chip.nandCost.toString(), style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant)                 if (widest > 1) {
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/CircuitCanvas.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/CircuitCanvas.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/CircuitCanvas.ktindex fc6339d9b7..79f76b73c9 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/CircuitCanvas.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/CircuitCanvas.kt@@ -77,8 +77,9 @@ fun CircuitCanvas(     val shake = remember { Animatable(0f) }     var shakePin by remember { mutableStateOf<PinRef?>(null) }     var editingInput by remember { mutableStateOf<Int?>(null) }+    val labels = rememberChipLabels()     val shown = controller.preview(state.circuit)-    val layout = remember(shown, lookup) { CircuitLayout(shown, lookup) }+    val layout = remember(shown, lookup, labels) { CircuitLayout(shown, lookup, labels) }      SideEffect {         controller.bind(state, actions, layout, lookup)@@ -87,7 +88,7 @@ fun CircuitCanvas(         controller.onEditBus = { editingInput = it }         controller.onReject = { pin, check ->             haptics.reject()-            messenger.show(rejectMessage(resources, check))+            messenger.show(rejectMessage(resources, labels, check))             shakePin = pin             scope.launch {                 for (x in SHAKE) shake.animateTo(x, Motion.over(SHAKE_STEP_MS))@@ -160,23 +161,20 @@ fun CircuitCanvas(     } } -private fun rejectMessage(res: Resources, check: ConnectCheck): String = when (check) {+private fun rejectMessage(res: Resources, labels: Map<String, String>, check: ConnectCheck): String = when (check) {     is ConnectCheck.WidthMismatch ->-        res.getString(R.string.lg_wire_width, check.fromWidth, check.toWidth, adapterFor(check.fromWidth, check.toWidth))+        res.getString(R.string.lg_wire_width, check.fromWidth, check.toWidth, labels.getValue(adapterFor(check.fromWidth, check.toWidth)))     else -> res.getString(R.string.lg_wire_same_side) } -/** The chip that converts between two bus widths. */-private fun adapterFor(from: Int, to: Int): String {-    val id = when {-        from == 8 && to == 1 -> Chips.SPLIT8-        from == 1 && to == 8 -> Chips.JOIN8-        from == 4 && to == 1 -> Chips.SPLIT4-        from == 1 && to == 4 -> Chips.JOIN4-        from == 8 -> Chips.NIB_SPLIT-        else -> Chips.NIB_JOIN-    }-    return Chips[id]?.label ?: id+/** The id of the chip that converts between two bus widths. */+private fun adapterFor(from: Int, to: Int): String = when {+    from == 8 && to == 1 -> Chips.SPLIT8+    from == 1 && to == 8 -> Chips.JOIN8+    from == 4 && to == 1 -> Chips.SPLIT4+    from == 1 && to == 4 -> Chips.JOIN4+    from == 8 -> Chips.NIB_SPLIT+    else -> Chips.NIB_JOIN }  private val SHAKE = listOf(7f, -7f, 5f, -5f, 2f, 0f)
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/GameScreen.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/GameScreen.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/GameScreen.ktindex e3399e7611..ee740afe7e 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/GameScreen.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/GameScreen.kt@@ -63,6 +63,7 @@ fun GameScreen(     val density = LocalDensity.current.density     val cameraState = remember { CameraState(density) }     val lookup = remember(state.level) { Chips.lookup(state.level.io) }+    val labels = rememberChipLabels()     val number = LevelRegistry.indexOf(state.level.id) + 1     var trayDrag by remember { mutableStateOf<TrayDrag?>(null) }     val trash = remember { TrashZone() }@@ -71,16 +72,16 @@ fun GameScreen(     var canvasBounds by remember { mutableStateOf(Rect.Zero) }      fun placeNear(chipId: String, world: Offset) =-        actions.placeChip(chipId, CircuitLayout(state.circuit, lookup).freeSpot(chipId, world, lookup))+        actions.placeChip(chipId, CircuitLayout(state.circuit, lookup, labels).freeSpot(chipId, world, lookup))      AppScaffold(-        title = stringResource(R.string.lg_level_title, number, state.level.title),+        title = stringResource(R.string.lg_level_title, number, stringResource(state.level.title)),         modifier = modifier,         onNavigateBack = onBack,         actions = {             IconButton(onClick = actions::undo, enabled = state.canUndo) { IconUndo() }             IconButton(onClick = actions::redo, enabled = state.canRedo) { IconRedo() }-            IconButton(onClick = { cameraState.fit(CircuitLayout(state.circuit, lookup).bounds) }) { IconFullscreen() }+            IconButton(onClick = { cameraState.fit(CircuitLayout(state.circuit, lookup, labels).bounds) }) { IconFullscreen() }             IconButton(onClick = { actions.showBrief(true) }) { IconInfo() }         },         scrollBehavior = appBarScrollBehavior(),@@ -124,7 +125,7 @@ fun GameScreen(                     TrashOverlay(trash, Modifier.matchParentSize())                 }             }-            trayDrag?.let { DragGhost(Chips[it.chipId]?.label ?: it.chipId, it.root - rootOrigin) }+            trayDrag?.let { DragGhost(chipLabel(it.chipId), it.root - rootOrigin) }             if (state.won) {                 LevelCompleteOverlay(                     state = state,
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/LevelCompleteOverlay.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/LevelCompleteOverlay.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/LevelCompleteOverlay.ktindex 0f1ff83576..3309029e16 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/LevelCompleteOverlay.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/LevelCompleteOverlay.kt@@ -5,7 +5,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.vayunmathur.games.logicgate.R-import com.vayunmathur.games.logicgate.domain.model.Chips import com.vayunmathur.games.logicgate.platform.GameUiState import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text@@ -32,7 +31,7 @@ fun LevelCompleteOverlay(         StarRating(state.stars, size = 36.dp)         Text(stringResource(R.string.lg_cost_vs_par, state.cost, state.level.par), style = MaterialTheme.typography.titleMedium)         if (state.level.unlocks.isNotEmpty()) {-            val chips = state.level.unlocks.joinToString { Chips[it]?.label ?: it }+            val chips = state.level.unlocks.map { chipLabel(it) }.joinToString()             Text(stringResource(R.string.lg_new_chips, chips), color = MaterialTheme.colorScheme.primary)         }     }
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ProgressionScreen.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ProgressionScreen.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ProgressionScreen.ktindex c5fc16d767..d4abf0cb25 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ProgressionScreen.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ProgressionScreen.kt@@ -103,12 +103,13 @@ private fun ChapterHeader(chapter: Chapter) { @Composable private fun LevelRow(card: LevelCard, onOpenLevel: (String) -> Unit) {     val locked = stringResource(R.string.lg_cd_locked)+    val title = stringResource(card.title)     Card(         onClick = { onOpenLevel(card.id) },         enabled = card.unlocked,         modifier = Modifier             .fillMaxWidth()-            .semantics { if (!card.unlocked) contentDescription = "${card.title}, $locked" },+            .semantics { if (!card.unlocked) contentDescription = "$title, $locked" },     ) {         Row(             Modifier.padding(Spacing.md),@@ -125,7 +126,7 @@ private fun LevelRow(card: LevelCard, onOpenLevel: (String) -> Unit) {                 }             }             Column(Modifier.weight(1f)) {-                Text(card.title, style = MaterialTheme.typography.titleMedium)+                Text(title, style = MaterialTheme.typography.titleMedium)                 Text(                     card.bestCost?.let { stringResource(R.string.lg_best_cost, it, card.par) }                         ?: stringResource(R.string.lg_par, card.par),
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/SelectionBar.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/SelectionBar.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/SelectionBar.ktindex 4d4af383fc..8f878679d2 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/SelectionBar.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/SelectionBar.kt@@ -14,7 +14,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.vayunmathur.games.logicgate.R-import com.vayunmathur.games.logicgate.domain.model.Chips import com.vayunmathur.games.logicgate.domain.model.Gate import com.vayunmathur.games.logicgate.platform.GameUiState import com.vayunmathur.games.logicgate.platform.LogicActions@@ -34,7 +33,7 @@ import com.vayunmathur.library.ui.TextButton fun SelectionBar(state: GameUiState, actions: LogicActions, modifier: Modifier = Modifier) {     val wireLabel = stringResource(R.string.lg_selected_wire)     val label = when (val sel = state.selection) {-        is Selection.OfNode -> (state.circuit.node(sel.id) as? Gate)?.let { Chips[it.chipId]?.label ?: it.chipId }+        is Selection.OfNode -> (state.circuit.node(sel.id) as? Gate)?.let { chipLabel(it.chipId) }         is Selection.OfWire -> wireLabel         null -> null     }
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/canvas/GateGeometry.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/canvas/GateGeometry.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/canvas/GateGeometry.ktindex 95b4019311..f194580430 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/canvas/GateGeometry.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/canvas/GateGeometry.kt@@ -3,7 +3,6 @@ package com.vayunmathur.games.logicgate.ui.canvas import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Rect import androidx.compose.ui.geometry.Size-import com.vayunmathur.games.logicgate.domain.model.Chips import com.vayunmathur.games.logicgate.domain.model.Circuit import com.vayunmathur.games.logicgate.domain.model.Gate import com.vayunmathur.games.logicgate.domain.model.LevelInput@@ -34,11 +33,10 @@ object GateGeometry {     private const val LABEL_PAD = 34f     private const val MIN_CURVE = 40f -    fun size(node: Node, pins: NodePins): Size = when (node) {+    fun size(node: Node, pins: NodePins, label: (String) -> String): Size = when (node) {         is Gate -> {             val rows = max(max(pins.inputs.size, pins.outputs.size), 1)-            val label = Chips[node.chipId]?.label ?: node.chipId-            Size(max(GATE_WIDTH, label.length * CHAR_WIDTH + LABEL_PAD), max(MIN_HEIGHT, rows * PIN_SPACING + GRID))+            Size(max(GATE_WIDTH, label(node.chipId).length * CHAR_WIDTH + LABEL_PAD), max(MIN_HEIGHT, rows * PIN_SPACING + GRID))         }         is LevelInput -> ioSize(pins.outputs.firstOrNull())         is LevelOutput -> ioSize(pins.inputs.firstOrNull())@@ -79,11 +77,13 @@ object GateGeometry {     } } -/** A circuit measured out for drawing and hit-testing. */-class CircuitLayout(val circuit: Circuit, lookup: PinLookup) {+/** A circuit measured out for drawing and hit-testing. [labels] maps chip ids to their displayed names. */+class CircuitLayout(val circuit: Circuit, lookup: PinLookup, private val labels: Map<String, String>) {+    fun label(chipId: String): String = labels[chipId] ?: chipId+     val pins: Map<NodeId, NodePins> = circuit.nodes.associate { it.id to (lookup.pins(it) ?: NodePins(emptyList(), emptyList())) }     val rects: Map<NodeId, Rect> = circuit.nodes.associate { n ->-        n.id to Rect(Offset(n.pos.x, n.pos.y), GateGeometry.size(n, pins.getValue(n.id)))+        n.id to Rect(Offset(n.pos.x, n.pos.y), GateGeometry.size(n, pins.getValue(n.id), ::label))     }     val anchors: Map<PinRef, Offset> = buildMap {         for (n in circuit.nodes) {@@ -107,7 +107,7 @@ class CircuitLayout(val circuit: Circuit, lookup: PinLookup) {      */     fun freeSpot(chipId: String, center: Offset, lookup: PinLookup): Point {         val probe = Gate(NodeId(-1), chipId, Point(0f, 0f))-        val size = GateGeometry.size(probe, lookup.pins(probe) ?: NodePins(emptyList(), emptyList()))+        val size = GateGeometry.size(probe, lookup.pins(probe) ?: NodePins(emptyList(), emptyList()), ::label)         val base = center - Offset(size.width / 2, size.height / 2)         val step = GateGeometry.PIN_SPACING * 2         val candidates = (-SEARCH..SEARCH).flatMap { i -> (-SEARCH..SEARCH).map { j -> Offset(i * step, j * step) } }
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/canvas/GatePainter.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/canvas/GatePainter.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/canvas/GatePainter.ktindex 4bd1176cf9..a89f4a909c 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/canvas/GatePainter.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/canvas/GatePainter.kt@@ -13,7 +13,6 @@ import androidx.compose.ui.text.TextMeasurer import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.drawText import androidx.compose.ui.text.font.FontWeight-import com.vayunmathur.games.logicgate.domain.model.Chips import com.vayunmathur.games.logicgate.domain.model.Gate import com.vayunmathur.games.logicgate.domain.model.LevelInput import com.vayunmathur.games.logicgate.domain.model.LevelOutput@@ -132,7 +131,7 @@ private fun DrawScope.drawGate(ctx: PaintContext, gate: Gate, rect: Rect, stroke         drawCircle(fill, GateShapes.BUBBLE_R, b)         drawCircle(stroke, GateShapes.BUBBLE_R, b, style = Stroke(2f))     }-    val label = Chips[gate.chipId]?.label ?: gate.chipId+    val label = ctx.layout.label(gate.chipId)     if (look.shape == GateShape.BOX) {         drawCentered(ctx, label, rect.center, LABEL_SIZE, ctx.colors.label)         drawPinNames(ctx, gate)
games/logicgate/src/main/res/values/strings.xml
diff --git a/games/logicgate/src/main/res/values/strings.xml b/games/logicgate/src/main/res/values/strings.xmlindex d24be67a99..70f8c5ba18 100644--- a/games/logicgate/src/main/res/values/strings.xml+++ b/games/logicgate/src/main/res/values/strings.xml@@ -118,4 +118,344 @@     <string name="lg_next_level">Next level</string>     <!-- Level complete overlay: dismiss and stay in the editor. Verb phrase -->     <string name="lg_keep_editing">Keep editing</string>++    <!-- Level titles, briefs and hints. Briefs and hints are written for a teenage reader: full, plain sentences. Keep pin names (like a, b, s, q, op) as they are, and write chip names exactly as you translated them in the lg_chip_*_label strings. -->+    <!-- Level map and brief sheet: title of the level that builds this chip. Same text as the chip name -->+    <string name="lg_level_not_title" translatable="false">@string/lg_chip_not_label</string>+    <!-- Brief sheet: goal of the "NOT" level. Sentences -->+    <string name="lg_level_not_brief">In this game, you build everything out of NAND gates. A NAND outputs 0 only when both of its inputs are 1. For this level, make the output o the opposite of the input a.</string>+    <!-- Brief sheet: hint for the "NOT" level, shown on request. Sentences -->+    <string name="lg_level_not_hint">Connect a to both inputs of a single NAND. Think about what it outputs when a is 0 and when a is 1.</string>+    <!-- Level map and brief sheet: title of the level that builds this chip. Same text as the chip name -->+    <string name="lg_level_and_title" translatable="false">@string/lg_chip_and_label</string>+    <!-- Brief sheet: goal of the "AND" level. Sentences -->+    <string name="lg_level_and_brief">Make o equal to 1 only when a and b are both 1. If either input is 0, o should be 0.</string>+    <!-- Brief sheet: hint for the "AND" level, shown on request. Sentences -->+    <string name="lg_level_and_hint">NAND means \"NOT AND\": it gives the opposite of AND. Flip a NAND\'s output back with a NOT.</string>+    <!-- Level map and brief sheet: title of the level that builds this chip. Same text as the chip name -->+    <string name="lg_level_or_title" translatable="false">@string/lg_chip_or_label</string>+    <!-- Brief sheet: goal of the "OR" level. Sentences -->+    <string name="lg_level_or_brief">Make o equal to 1 when a is 1, when b is 1, or when both are 1. It should be 0 only when both are 0.</string>+    <!-- Brief sheet: hint for the "OR" level, shown on request. Sentences -->+    <string name="lg_level_or_hint">Flip a and b with a NOT each, then feed both flipped values into a NAND. The NAND outputs 0 only when both flipped values are 1, which means a and b were both 0.</string>+    <!-- Level map and brief sheet: title of the level that builds this chip. Same text as the chip name -->+    <string name="lg_level_nor_title" translatable="false">@string/lg_chip_nor_label</string>+    <!-- Brief sheet: goal of the "NOR" level. Sentences -->+    <string name="lg_level_nor_brief">Make o equal to 1 only when a and b are both 0. If either input is 1, o should be 0.</string>+    <!-- Brief sheet: hint for the "NOR" level, shown on request. Sentences -->+    <string name="lg_level_nor_hint">This is the opposite of OR, so put a NOT after an OR.</string>+    <!-- Level map and brief sheet: title of the level that builds this chip. Same text as the chip name -->+    <string name="lg_level_xor_title" translatable="false">@string/lg_chip_xor_label</string>+    <!-- Brief sheet: goal of the "XOR" level. Sentences -->+    <string name="lg_level_xor_brief">Make o equal to 1 when a and b are different, and 0 when they are the same.</string>+    <!-- Brief sheet: hint for the "XOR" level, shown on request. Sentences -->+    <string name="lg_level_xor_hint">You can do this with four NANDs. Feed a and b into the first NAND. Feed the first NAND\'s output and a into a second NAND, and feed the first NAND\'s output and b into a third NAND. Finally, feed the outputs of the second and third NANDs into a fourth NAND.</string>+    <!-- Level map and brief sheet: title of the level that builds this chip. Same text as the chip name -->+    <string name="lg_level_xnor_title" translatable="false">@string/lg_chip_xnor_label</string>+    <!-- Brief sheet: goal of the "XNOR" level. Sentences -->+    <string name="lg_level_xnor_brief">Make o equal to 1 when a and b are the same, and 0 when they are different.</string>+    <!-- Brief sheet: hint for the "XNOR" level, shown on request. Sentences -->+    <string name="lg_level_xnor_hint">This is the opposite of XOR, so put a NOT after an XOR.</string>+    <!-- Level map and brief sheet: title of the level that builds this chip. Same text as the chip name -->+    <string name="lg_level_mux_title" translatable="false">@string/lg_chip_mux_label</string>+    <!-- Brief sheet: goal of the "MUX" level. Sentences -->+    <string name="lg_level_mux_brief">A MUX chooses between two inputs. When the select input s is 0, the output o should copy a. When s is 1, o should copy b.</string>+    <!-- Brief sheet: hint for the "MUX" level, shown on request. Sentences -->+    <string name="lg_level_mux_hint">AND a with NOT s, so it only gets through when s is 0. AND b with s, so it only gets through when s is 1. Then OR the two results together. Built straight from NANDs, it takes only four gates.</string>+    <!-- Level map and brief sheet: title of the level that builds this chip. Same text as the chip name -->+    <string name="lg_level_dmux_title" translatable="false">@string/lg_chip_dmux_label</string>+    <!-- Brief sheet: goal of the "DMUX" level. Sentences -->+    <string name="lg_level_dmux_brief">A DMUX sends one input to one of two outputs. When s is 0, the value of in should go to a. When s is 1, it should go to b. The output that is not chosen should stay 0.</string>+    <!-- Brief sheet: hint for the "DMUX" level, shown on request. Sentences -->+    <string name="lg_level_dmux_hint">Output a is in AND NOT s. Output b is in AND s.</string>+    <!-- Level map and brief sheet: title of the "Decoder" level. Short noun phrase -->+    <string name="lg_level_dec2_title">Decoder</string>+    <!-- Brief sheet: goal of the "Decoder" level. Sentences -->+    <string name="lg_level_dec2_brief">Read s1 and s0 as a two-bit number from 0 to 3, with s1 as the high bit. Turn on the output with that number (y0, y1, y2 or y3) and keep the other three at 0. For example, s1 = 1 and s0 = 0 is the number 2, so only y2 should be 1.</string>+    <!-- Brief sheet: hint for the "Decoder" level, shown on request. Sentences -->+    <string name="lg_level_dec2_hint">Each output needs its own AND gate. For y0, AND together NOT s1 and NOT s0. For y3, AND together s1 and s0. Work out y1 and y2 the same way.</string>+    <!-- Level map and brief sheet: title of the "Nibble swap" level. Short noun phrase -->+    <string name="lg_level_nibble_swap_title">Nibble swap</string>+    <!-- Brief sheet: goal of the "Nibble swap" level. Sentences -->+    <string name="lg_level_nibble_swap_brief">Thick wires are called buses, and they carry 4 or 8 bits at once. The input x is a byte (8 bits). Split it into its low 4 bits and its high 4 bits, then swap them, so the low half of x becomes the high half of y and the high half of x becomes the low half of y.</string>+    <!-- Brief sheet: hint for the "Nibble swap" level, shown on request. Sentences -->+    <string name="lg_level_nibble_swap_hint">A NIB SPLIT breaks x into its two halves. Connect them to a NIB JOIN the other way round.</string>+    <!-- Level map and brief sheet: title of the "Bus MUX" level. Short noun phrase -->+    <string name="lg_level_bus_mux_title">Bus MUX</string>+    <!-- Brief sheet: goal of the "Bus MUX" level. Sentences -->+    <string name="lg_level_bus_mux_brief">Build a MUX that chooses between two whole bytes. When s is 0, o should copy all 8 bits of a, and when s is 1, o should copy all 8 bits of b. This level takes some repetitive wiring, but once you solve it, you get bus versions of NOT, AND, OR, XOR and MUX for free.</string>+    <!-- Brief sheet: hint for the "Bus MUX" level, shown on request. Sentences -->+    <string name="lg_level_bus_mux_hint">Split a and b into separate bits. Use eight MUXes, one for each bit position, all sharing the same s. Then join their outputs back into one bus.</string>+    <!-- Level map and brief sheet: title of the "Half adder" level. Short noun phrase -->+    <string name="lg_level_half_adder_title">Half adder</string>+    <!-- Brief sheet: goal of the "Half adder" level. Sentences -->+    <string name="lg_level_half_adder_brief">Add two bits, a and b. The sum bit s should be 1 when exactly one input is 1. The carry c should be 1 when both inputs are 1, because 1 + 1 = 2, which is written 10 in binary.</string>+    <!-- Brief sheet: hint for the "Half adder" level, shown on request. Sentences -->+    <string name="lg_level_half_adder_hint">The sum s is a XOR b, and the carry c is a AND b. To save gates, notice that the first NAND inside your XOR already gives NOT c, so c needs only one more NOT.</string>+    <!-- Level map and brief sheet: title of the "Full adder" level. Short noun phrase -->+    <string name="lg_level_full_adder_title">Full adder</string>+    <!-- Brief sheet: goal of the "Full adder" level. Sentences -->+    <string name="lg_level_full_adder_brief">Add three bits: a, b and a carry in, cin, which comes from the column to the right. The output s is the sum bit, and cout is the carry that passes to the next column on the left.</string>+    <!-- Brief sheet: hint for the "Full adder" level, shown on request. Sentences -->+    <string name="lg_level_full_adder_hint">Use two half adders. The first adds a and b, and the second adds that sum to cin. cout should be 1 if either half adder made a carry, so OR their two carries together. The best known solution uses only nine NANDs.</string>+    <!-- Level map and brief sheet: title of the "4-bit adder" level. Short noun phrase -->+    <string name="lg_level_add4_title">4-bit adder</string>+    <!-- Brief sheet: goal of the "4-bit adder" level. Sentences -->+    <string name="lg_level_add4_brief">Add the two 4-bit numbers a and b, plus the carry in cin. The output s is the 4-bit sum. If the total is bigger than 15, it does not fit in 4 bits, so cout should be 1 and s should keep only the low 4 bits.</string>+    <!-- Brief sheet: hint for the "4-bit adder" level, shown on request. Sentences -->+    <string name="lg_level_add4_hint">Split a and b into bits and use one full adder per bit, starting from the lowest bit. Connect each adder\'s cout to the next adder\'s cin, then join the four sum bits back together into s.</string>+    <!-- Level map and brief sheet: title of the "8-bit adder" level. Short noun phrase -->+    <string name="lg_level_add8_title">8-bit adder</string>+    <!-- Brief sheet: goal of the "8-bit adder" level. Sentences -->+    <string name="lg_level_add8_brief">Add the two bytes a and b, plus the carry in cin. The output s is the 8-bit sum. If the total is bigger than 255, it does not fit in 8 bits, so cout should be 1 and s should keep only the low 8 bits.</string>+    <!-- Brief sheet: hint for the "8-bit adder" level, shown on request. Sentences -->+    <string name="lg_level_add8_hint">Use two ADD4s: one for the low 4 bits and one for the high 4 bits. Split the inputs with NIB SPLITs, connect the low adder\'s cout to the high adder\'s cin, and join the two sums with a NIB JOIN.</string>+    <!-- Level map and brief sheet: title of the "Incrementer" level. Short noun phrase -->+    <string name="lg_level_inc4_title">Incrementer</string>+    <!-- Brief sheet: goal of the "Incrementer" level. Sentences -->+    <string name="lg_level_inc4_brief">Make o equal to a + 1. Because o only has 4 bits, 15 + 1 should wrap back around to 0.</string>+    <!-- Brief sheet: hint for the "Incrementer" level, shown on request. Sentences -->+    <string name="lg_level_inc4_hint">The lowest bit always flips, so it only needs a NOT. Each higher bit goes into a half adder together with the carry from the bit below it.</string>+    <!-- Level map and brief sheet: title of the "Subtractor" level. Short noun phrase -->+    <string name="lg_level_sub8_title">Subtractor</string>+    <!-- Brief sheet: goal of the "Subtractor" level. Sentences -->+    <string name="lg_level_sub8_brief">Make d equal to a − b. If the answer would go below zero, it should wrap around from the top, so 0 − 1 gives 255.</string>+    <!-- Brief sheet: hint for the "Subtractor" level, shown on request. Sentences -->+    <string name="lg_level_sub8_hint">Computers subtract by adding. Flipping every bit of b and then adding 1 gives the same result as subtracting b (this trick is called two\'s complement). So add a to NOT b, and supply the extra 1 through the adder\'s carry in.</string>+    <!-- Level map and brief sheet: title of the "Zero test" level. Short noun phrase -->+    <string name="lg_level_zero8_title">Zero test</string>+    <!-- Brief sheet: goal of the "Zero test" level. Sentences -->+    <string name="lg_level_zero8_brief">Make z equal to 1 when every bit of a is 0, which means a is the number zero. If any bit of a is 1, z should be 0.</string>+    <!-- Brief sheet: hint for the "Zero test" level, shown on request. Sentences -->+    <string name="lg_level_zero8_hint">OR all eight bits together, then put a NOT after the result.</string>+    <!-- Level map and brief sheet: title of the "ALU" level. Short noun phrase -->+    <string name="lg_level_alu8_title">ALU</string>+    <!-- Brief sheet: goal of the "ALU" level. Sentences -->+    <string name="lg_level_alu8_brief">An ALU (arithmetic logic unit) is the part of a CPU that does the math. The inputs op1 and op0 choose what it does with a and b:\n• 00: add a and b.\n• 01: subtract b from a.\n• 10: AND each pair of bits in a and b.\n• 11: pass b through unchanged.\nThe output o is the result, and z should be 1 when o is 0.</string>+    <!-- Brief sheet: hint for the "ALU" level, shown on request. Sentences -->+    <string name="lg_level_alu8_hint">Subtracting b is the same as adding NOT b with the carry in set to 1. If you XOR each bit of b with op0, b gets flipped only when op0 is 1, and op0 can also be the carry in. Then use MUXes to choose between the adder\'s result, a AND b, and b.</string>+    <!-- Level map and brief sheet: title of the "SR latch" level. Short noun phrase -->+    <string name="lg_level_sr_latch_title">SR latch</string>+    <!-- Brief sheet: goal of the "SR latch" level. Sentences -->+    <string name="lg_level_sr_latch_brief">This circuit remembers one bit by feeding its outputs back into itself. Setting s to 1 sets q to 1, and setting r to 1 resets q to 0. When s and r are both 0, q keeps whatever value it had. The second output, nq, is always the opposite of q.</string>+    <!-- Brief sheet: hint for the "SR latch" level, shown on request. Sentences -->+    <string name="lg_level_sr_latch_hint">Use two NORs, and wire each one\'s output into one of the other\'s inputs. Connect r to the NOR that makes q, and s to the NOR that makes nq.</string>+    <!-- Level map and brief sheet: title of the "D latch" level. Short noun phrase -->+    <string name="lg_level_d_latch_title">D latch</string>+    <!-- Brief sheet: goal of the "D latch" level. Sentences -->+    <string name="lg_level_d_latch_brief">While en (enable) is 1, q should copy d. When en goes to 0, q should keep the last value it had, no matter what d does.</string>+    <!-- Brief sheet: hint for the "D latch" level, shown on request. Sentences -->+    <string name="lg_level_d_latch_hint">Start with an SR latch. Set it when en is 1 and d is 1, and reset it when en is 1 and d is 0.</string>+    <!-- Level map and brief sheet: title of the "1-bit register" level. Short noun phrase -->+    <string name="lg_level_bit_title">1-bit register</string>+    <!-- Brief sheet: goal of the "1-bit register" level. Sentences -->+    <string name="lg_level_bit_brief">A DFF stores its input on every tick, whether you want it to or not. Build a 1-bit register that stores d only on ticks when load is 1, and keeps its old bit when load is 0. The output q should always show the stored bit.</string>+    <!-- Brief sheet: hint for the "1-bit register" level, shown on request. Sentences -->+    <string name="lg_level_bit_hint">Put a MUX in front of the DFF. When load is 1, the MUX should pass d through. When load is 0, it should pass the DFF\'s own output back in, so the DFF stores the same bit again.</string>+    <!-- Level map and brief sheet: title of the "8-bit register" level. Short noun phrase -->+    <string name="lg_level_reg8_title">8-bit register</string>+    <!-- Brief sheet: goal of the "8-bit register" level. Sentences -->+    <string name="lg_level_reg8_brief">Build the same thing as the 1-bit register, but for a whole byte. On each tick, if load is 1, store the byte on d. If load is 0, keep the byte that is already stored. The output q should always show the stored byte.</string>+    <!-- Brief sheet: hint for the "8-bit register" level, shown on request. Sentences -->+    <string name="lg_level_reg8_hint">Put a MUX8b in front of a DFF8, the same way you used a MUX and a DFF for the 1-bit register.</string>+    <!-- Level map and brief sheet: title of the "Program counter" level. Short noun phrase -->+    <string name="lg_level_pc4_title">Program counter</string>+    <!-- Brief sheet: goal of the "Program counter" level. Sentences -->+    <string name="lg_level_pc4_brief">A program counter keeps track of which instruction a CPU runs next. On each tick, it should do one of three things:\n• If load is 1, jump to the number on v.\n• Otherwise, if en is 1, count up by one, wrapping from 15 back to 0.\n• Otherwise, keep the same number.\nThe output pc always shows the current count.</string>+    <!-- Brief sheet: hint for the "Program counter" level, shown on request. Sentences -->+    <string name="lg_level_pc4_hint">Store the count in a DFF4, and use an INC4 to work out the count plus one. Then use two MUX4bs to choose what the DFF4 stores next. The first uses en to choose between the current count and the count plus one. The second uses load to choose between that result and v.</string>+    <!-- Level map and brief sheet: title of the "RAM" level. Short noun phrase -->+    <string name="lg_level_ram4_title">RAM</string>+    <!-- Brief sheet: goal of the "RAM" level. Sentences -->+    <string name="lg_level_ram4_brief">Build four bytes of memory, numbered 0 to 3. The inputs a1 and a0 form the address of one byte, with a1 as the high bit, and dout should always show the byte at that address. On each tick, if we (write enable) is 1, the byte on din should be saved at that address.</string>+    <!-- Brief sheet: hint for the "RAM" level, shown on request. Sentences -->+    <string name="lg_level_ram4_hint">Use one REG8 for each byte. A DEC2 turns the address into four lines, one per register, so AND each line with we to decide which register loads. To read, use MUX8bs to pick the register that matches the address.</string>+    <!-- Level map and brief sheet: title of the "Instruction decoder" level. Short noun phrase -->+    <string name="lg_level_decoder_title">Instruction decoder</string>+    <!-- Brief sheet: goal of the "Instruction decoder" level. Sentences -->+    <string name="lg_level_decoder_brief">The instruction decoder looks at an instruction and decides which parts of the CPU should act. The CPU works on one number at a time, kept in a register called the accumulator.\nThe input op is the instruction number from 0 to 7 (op has 4 bits, but the top one is unused):\n• 0 LDA: load a byte from memory into the accumulator.\n• 1 STA: store the accumulator into memory.\n• 2 ADD: add a byte from memory to the accumulator.\n• 3 SUB: subtract a byte from memory from the accumulator.\n• 4 LDI: load the number written inside the instruction into the accumulator.\n• 5 JMP: jump to a different instruction.\n• 6 JZ: jump only if the accumulator is zero, which is when z is 1.\n• 7 HLT: stop the program.\nSet the outputs like this:\n• aluOp1 and aluOp0 choose the ALU operation: 00 (add) for ADD, 01 (subtract) for SUB, and 11 (pass b through) for LDA and LDI. They are only checked when accLoad is 1.\n• accLoad is 1 for LDA, ADD, SUB and LDI, so the ALU\'s result is stored in the accumulator.\n• memWrite is 1 for STA, so the accumulator is written to memory.\n• useImm is 1 for LDI, so the ALU uses the number inside the instruction instead of a byte from memory.\n• jump is 1 for JMP, and for JZ only when z is 1.\n• halt is 1 for HLT.</string>+    <!-- Brief sheet: hint for the "Instruction decoder" level, shown on request. Sentences -->+    <string name="lg_level_decoder_hint">Split op into bits and ignore the top one. Turn the other three bits into eight separate lines, one for each instruction, like a bigger version of a DEC2. Then each output is an OR of the lines for the instructions that need it.</string>+    <!-- Level map and brief sheet: title of the level that builds this chip. Same text as the chip name -->+    <string name="lg_level_cpu_title" translatable="false">@string/lg_chip_cpu_label</string>+    <!-- Brief sheet: goal of the "CPU" level. Sentences -->+    <string name="lg_level_cpu_brief">Build a CPU that runs one instruction on each tick. Each instruction is a byte: the high 4 bits are the instruction number (the decoder\'s op), and the low 4 bits are the operand. The operand is a memory address, or for LDI, the number to load. On each tick, instr is the instruction stored at address pc, and data is the byte stored at address addr. Your CPU should:\n• Put the operand on addr, so memory sends back the right byte on data.\n• Run the instruction, updating the accumulator, which is shown on acc.\n• Move pc on to the next instruction, or to the operand when it jumps.\n• For STA, put acc on dout and set we to 1, so the accumulator is written to memory.\n• For HLT, set halt to 1 and stop moving pc.\nYour CPU is tested by running three real programs.</string>+    <!-- Brief sheet: hint for the "CPU" level, shown on request. Sentences -->+    <string name="lg_level_cpu_hint">Split instr into its two halves. Send the instruction number to a decoder, and send the operand to addr and to the v input of a PC4. Keep the accumulator in a REG8 that loads when accLoad is 1. Feed an ALU with the accumulator as a, and as b, either data or the operand, chosen by useImm. Use a ZERO8 on the accumulator to make the decoder\'s z. Finally, connect jump to the PC4\'s load, and connect NOT halt to its en.</string>+    <!-- Level map and brief sheet: title of the "Computer" level. Short noun phrase -->+    <string name="lg_level_computer_title">Computer</string>+    <!-- Brief sheet: goal of the "Computer" level. Sentences -->+    <string name="lg_level_computer_brief">Connect your CPU to a RAM16 to make a working computer. Three programs will be loaded into the RAM and run: one adds two numbers, one counts down from 5 to 0, and one multiplies 3 × 4. The outputs acc and halt should show your CPU\'s accumulator and halt signal.</string>+    <!-- Brief sheet: hint for the "Computer" level, shown on request. Sentences -->+    <string name="lg_level_computer_hint">Connect the CPU\'s pc to the RAM\'s iaddr, addr to daddr, dout to din, and we to we. Then connect the RAM\'s instr output to the CPU\'s instr input, and the RAM\'s dout output to the CPU\'s data input.</string>++    <!-- Chip names and chip info sheet text (what each chip does, shown when a tray card is tapped). Keep pin names (like a, b, s, q, op) as they are, and write chip names exactly as you translated them in the lg_chip_*_label strings. -->+    <!-- Chip tray and canvas: name of the NAND chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep NAND -->+    <string name="lg_chip_nand_label">NAND</string>+    <!-- Chip info sheet: explanation of the NAND chip. Sentences -->+    <string name="lg_chip_nand_info">This is the gate everything else starts from. Its output o is 0 only when a and b are both 1; otherwise it is 1. Every other chip in the game can be built from NANDs alone.</string>+    <!-- Chip tray and canvas: name of the HIGH chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep HIGH -->+    <string name="lg_chip_high_label">HIGH</string>+    <!-- Chip info sheet: explanation of the HIGH chip. Sentences -->+    <string name="lg_chip_high_info">This chip has no inputs. Its output o is always 1.</string>+    <!-- Chip tray and canvas: name of the LOW chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep LOW -->+    <string name="lg_chip_low_label">LOW</string>+    <!-- Chip info sheet: explanation of the LOW chip. Sentences -->+    <string name="lg_chip_low_info">This chip has no inputs. Its output o is always 0.</string>+    <!-- Chip tray and canvas: name of the NOT chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep NOT -->+    <string name="lg_chip_not_label">NOT</string>+    <!-- Chip info sheet: explanation of the NOT chip. Sentences -->+    <string name="lg_chip_not_info">The output o is always the opposite of the input a: when a is 1, o is 0, and when a is 0, o is 1.</string>+    <!-- Chip tray and canvas: name of the AND chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep AND -->+    <string name="lg_chip_and_label">AND</string>+    <!-- Chip info sheet: explanation of the AND chip. Sentences -->+    <string name="lg_chip_and_info">The output o is 1 only when a and b are both 1. If either input is 0, o is 0.</string>+    <!-- Chip tray and canvas: name of the OR chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep OR -->+    <string name="lg_chip_or_label">OR</string>+    <!-- Chip info sheet: explanation of the OR chip. Sentences -->+    <string name="lg_chip_or_info">The output o is 1 when a is 1, when b is 1, or when both are 1. It is 0 only when both inputs are 0.</string>+    <!-- Chip tray and canvas: name of the NOR chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep NOR -->+    <string name="lg_chip_nor_label">NOR</string>+    <!-- Chip info sheet: explanation of the NOR chip. Sentences -->+    <string name="lg_chip_nor_info">This is an OR followed by a NOT, so the output o is 1 only when a and b are both 0. If you wire two NORs into each other, they can remember a bit. That circuit is called an SR latch.</string>+    <!-- Chip tray and canvas: name of the XOR chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep XOR -->+    <string name="lg_chip_xor_label">XOR</string>+    <!-- Chip info sheet: explanation of the XOR chip. Sentences -->+    <string name="lg_chip_xor_info">The output o is 1 when a and b are different, and 0 when they are the same. The name stands for \"exclusive OR\".</string>+    <!-- Chip tray and canvas: name of the XNOR chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep XNOR -->+    <string name="lg_chip_xnor_label">XNOR</string>+    <!-- Chip info sheet: explanation of the XNOR chip. Sentences -->+    <string name="lg_chip_xnor_info">The output o is 1 when a and b are the same, and 0 when they are different. It is the opposite of XOR.</string>+    <!-- Chip tray and canvas: name of the MUX chip. Standard abbreviation, kept as is in every language -->+    <string name="lg_chip_mux_label" translatable="false">MUX</string>+    <!-- Chip info sheet: explanation of the MUX chip. Sentences -->+    <string name="lg_chip_mux_info">A MUX (short for multiplexer) chooses between two inputs. When the select input s is 0, the output o copies a. When s is 1, o copies b.</string>+    <!-- Chip tray and canvas: name of the DMUX chip. Standard abbreviation, kept as is in every language -->+    <string name="lg_chip_dmux_label" translatable="false">DMUX</string>+    <!-- Chip info sheet: explanation of the DMUX chip. Sentences -->+    <string name="lg_chip_dmux_info">A DMUX does the reverse of a MUX: it sends one input to one of two outputs. When s is 0, the value of in goes to a, and when s is 1, it goes to b. The output that is not chosen stays 0.</string>+    <!-- Chip tray and canvas: name of the DEC2 chip. Standard abbreviation, kept as is in every language -->+    <string name="lg_chip_dec2_label" translatable="false">DEC2</string>+    <!-- Chip info sheet: explanation of the DEC2 chip. Sentences -->+    <string name="lg_chip_dec2_info">A decoder turns a number into a single lit-up output. Read s1 and s0 as a two-bit number from 0 to 3, with s1 as the high bit. The output with that number (y0, y1, y2 or y3) is 1, and the other three are 0.</string>+    <!-- Chip tray and canvas: name of the SPLIT 8 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep SPLIT 8 -->+    <string name="lg_chip_split8_label">SPLIT 8</string>+    <!-- Chip info sheet: explanation of the SPLIT8 chip. Sentences -->+    <string name="lg_chip_split8_info">A bus is a thick wire that carries several bits at once. This chip splits the 8-bit bus x into its eight separate bits, from b0 (the lowest bit) to b7 (the highest bit).</string>+    <!-- Chip tray and canvas: name of the JOIN 8 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep JOIN 8 -->+    <string name="lg_chip_join8_label">JOIN 8</string>+    <!-- Chip info sheet: explanation of the JOIN8 chip. Sentences -->+    <string name="lg_chip_join8_info">This chip combines eight separate bits into one 8-bit bus x. b0 becomes the lowest bit and b7 becomes the highest bit.</string>+    <!-- Chip tray and canvas: name of the SPLIT 4 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep SPLIT 4 -->+    <string name="lg_chip_split4_label">SPLIT 4</string>+    <!-- Chip info sheet: explanation of the SPLIT4 chip. Sentences -->+    <string name="lg_chip_split4_info">This chip splits the 4-bit bus x into its four separate bits, from b0 (the lowest bit) to b3 (the highest bit).</string>+    <!-- Chip tray and canvas: name of the JOIN 4 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep JOIN 4 -->+    <string name="lg_chip_join4_label">JOIN 4</string>+    <!-- Chip info sheet: explanation of the JOIN4 chip. Sentences -->+    <string name="lg_chip_join4_info">This chip combines four separate bits into one 4-bit bus x. b0 becomes the lowest bit and b3 becomes the highest bit.</string>+    <!-- Chip tray and canvas: name of the NIB SPLIT chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep NIB SPLIT -->+    <string name="lg_chip_nib_split_label">NIB SPLIT</string>+    <!-- Chip info sheet: explanation of the NIB_SPLIT chip. Sentences -->+    <string name="lg_chip_nib_split_info">This chip splits a byte (8 bits) into two halves of 4 bits each, called nibbles. lo gets the low 4 bits and hi gets the high 4 bits.</string>+    <!-- Chip tray and canvas: name of the NIB JOIN chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep NIB JOIN -->+    <string name="lg_chip_nib_join_label">NIB JOIN</string>+    <!-- Chip info sheet: explanation of the NIB_JOIN chip. Sentences -->+    <string name="lg_chip_nib_join_info">This chip does the reverse of NIB SPLIT. It combines a low nibble lo and a high nibble hi into one byte x.</string>+    <!-- Chip tray and canvas: name of the NOT8 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep NOT8 -->+    <string name="lg_chip_not8_label">NOT8</string>+    <!-- Chip info sheet: explanation of the NOT8 chip. Sentences -->+    <string name="lg_chip_not8_info">This chip flips all eight bits of a at once, so every 1 becomes 0 and every 0 becomes 1.</string>+    <!-- Chip tray and canvas: name of the AND8 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep AND8 -->+    <string name="lg_chip_and8_label">AND8</string>+    <!-- Chip info sheet: explanation of the AND8 chip. Sentences -->+    <string name="lg_chip_and8_info">This chip does an AND on each matching pair of bits in a and b. Each bit of o is 1 only where a and b both have a 1 in that position.</string>+    <!-- Chip tray and canvas: name of the OR8 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep OR8 -->+    <string name="lg_chip_or8_label">OR8</string>+    <!-- Chip info sheet: explanation of the OR8 chip. Sentences -->+    <string name="lg_chip_or8_info">This chip does an OR on each matching pair of bits in a and b. Each bit of o is 1 where a, b or both have a 1 in that position.</string>+    <!-- Chip tray and canvas: name of the XOR8 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep XOR8 -->+    <string name="lg_chip_xor8_label">XOR8</string>+    <!-- Chip info sheet: explanation of the XOR8 chip. Sentences -->+    <string name="lg_chip_xor8_info">This chip does an XOR on each matching pair of bits in a and b. Each bit of o is 1 where a and b have different bits in that position.</string>+    <!-- Chip tray and canvas: name of the MUX8b chip. Standard abbreviation, kept as is in every language -->+    <string name="lg_chip_mux8b_label" translatable="false">MUX8b</string>+    <!-- Chip info sheet: explanation of the MUX8B chip. Sentences -->+    <string name="lg_chip_mux8b_info">This is a MUX for whole bytes. When s is 0, o copies all 8 bits of a, and when s is 1, o copies all 8 bits of b.</string>+    <!-- Chip tray and canvas: name of the MUX4b chip. Standard abbreviation, kept as is in every language -->+    <string name="lg_chip_mux4b_label" translatable="false">MUX4b</string>+    <!-- Chip info sheet: explanation of the MUX4B chip. Sentences -->+    <string name="lg_chip_mux4b_info">This is a MUX for 4-bit buses. When s is 0, o copies all 4 bits of a, and when s is 1, o copies all 4 bits of b.</string>+    <!-- Chip tray and canvas: name of the HALF chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep HALF -->+    <string name="lg_chip_half_label">HALF</string>+    <!-- Chip info sheet: explanation of the HALF chip. Sentences -->+    <string name="lg_chip_half_info">A half adder adds two bits. The sum bit s is 1 when exactly one input is 1. The carry c is 1 when both inputs are 1, because 1 + 1 = 2, which is written 10 in binary.</string>+    <!-- Chip tray and canvas: name of the FULL chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep FULL -->+    <string name="lg_chip_full_label">FULL</string>+    <!-- Chip info sheet: explanation of the FULL chip. Sentences -->+    <string name="lg_chip_full_info">A full adder adds three bits: a, b and a carry in, cin, which comes from the column to its right. The output s is the sum bit, and cout is the carry that passes to the next column on the left.</string>+    <!-- Chip tray and canvas: name of the ADD4 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep ADD4 -->+    <string name="lg_chip_add4_label">ADD4</string>+    <!-- Chip info sheet: explanation of the ADD4 chip. Sentences -->+    <string name="lg_chip_add4_info">This chip adds two 4-bit numbers, a and b, plus a carry in, cin. The output s is the 4-bit sum. If the total is bigger than 15, it does not fit in 4 bits, so cout becomes 1 and s keeps only the low 4 bits.</string>+    <!-- Chip tray and canvas: name of the ADD8 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep ADD8 -->+    <string name="lg_chip_add8_label">ADD8</string>+    <!-- Chip info sheet: explanation of the ADD8 chip. Sentences -->+    <string name="lg_chip_add8_info">This chip adds two bytes, a and b, plus a carry in, cin. The output s is the 8-bit sum. If the total is bigger than 255, it does not fit in 8 bits, so cout becomes 1 and s keeps only the low 8 bits.</string>+    <!-- Chip tray and canvas: name of the INC4 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep INC4 -->+    <string name="lg_chip_inc4_label">INC4</string>+    <!-- Chip info sheet: explanation of the INC4 chip. Sentences -->+    <string name="lg_chip_inc4_info">This chip counts up by one: the output o is a + 1. Because there are only 4 bits, 15 + 1 wraps back around to 0.</string>+    <!-- Chip tray and canvas: name of the SUB8 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep SUB8 -->+    <string name="lg_chip_sub8_label">SUB8</string>+    <!-- Chip info sheet: explanation of the SUB8 chip. Sentences -->+    <string name="lg_chip_sub8_info">This chip subtracts: the output d is a − b. If the answer would go below zero, it wraps around from the top, so 0 − 1 gives 255.</string>+    <!-- Chip tray and canvas: name of the ZERO8 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep ZERO8 -->+    <string name="lg_chip_zero8_label">ZERO8</string>+    <!-- Chip info sheet: explanation of the ZERO8 chip. Sentences -->+    <string name="lg_chip_zero8_info">The output z is 1 only when every bit of a is 0, which means a is the number zero. A CPU uses this to decide whether to jump.</string>+    <!-- Chip tray and canvas: name of the ALU8 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep ALU8 -->+    <string name="lg_chip_alu8_label">ALU8</string>+    <!-- Chip info sheet: explanation of the ALU8 chip. Sentences -->+    <string name="lg_chip_alu8_info">ALU stands for arithmetic logic unit. It does one of four things to a and b, and op1 and op0 choose which: 00 adds them, 01 subtracts b from a, 10 ANDs each pair of bits, and 11 passes b straight through. The output o is the result, and z is 1 when o is 0.</string>+    <!-- Chip tray and canvas: name of the DFF chip. Standard abbreviation, kept as is in every language -->+    <string name="lg_chip_dff_label" translatable="false">DFF</string>+    <!-- Chip info sheet: explanation of the DFF chip. Sentences -->+    <string name="lg_chip_dff_info">The DFF (D flip-flop) is the basic memory chip. Its output q always shows the bit it has stored. On every tick of the clock, it stores whatever its input d is at that moment, so q always shows d from one tick earlier. Because q only changes on a tick, you can safely loop a DFF\'s output back into its own input.</string>+    <!-- Chip tray and canvas: name of the DFF4 chip. Standard abbreviation, kept as is in every language -->+    <string name="lg_chip_dff4_label" translatable="false">DFF4</string>+    <!-- Chip info sheet: explanation of the DFF4 chip. Sentences -->+    <string name="lg_chip_dff4_info">This is four DFFs in one chip. On every tick it stores the 4-bit number on d, and q shows the number stored on the tick before.</string>+    <!-- Chip tray and canvas: name of the DFF8 chip. Standard abbreviation, kept as is in every language -->+    <string name="lg_chip_dff8_label" translatable="false">DFF8</string>+    <!-- Chip info sheet: explanation of the DFF8 chip. Sentences -->+    <string name="lg_chip_dff8_info">This is eight DFFs in one chip. On every tick it stores the byte on d, and q shows the byte stored on the tick before.</string>+    <!-- Chip tray and canvas: name of the BIT chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep BIT -->+    <string name="lg_chip_bit_label">BIT</string>+    <!-- Chip info sheet: explanation of the BIT chip. Sentences -->+    <string name="lg_chip_bit_info">This is a 1-bit register: a DFF that you can tell when to remember. On each tick, if load is 1, it stores the bit on d. If load is 0, it keeps the bit it already has. q always shows the stored bit.</string>+    <!-- Chip tray and canvas: name of the REG8 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep REG8 -->+    <string name="lg_chip_reg8_label">REG8</string>+    <!-- Chip info sheet: explanation of the REG8 chip. Sentences -->+    <string name="lg_chip_reg8_info">This is an 8-bit register. On each tick, if load is 1, it stores the byte on d. If load is 0, it keeps the byte it already has. q always shows the stored byte.</string>+    <!-- Chip tray and canvas: name of the PC4 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep PC4 -->+    <string name="lg_chip_pc4_label">PC4</string>+    <!-- Chip info sheet: explanation of the PC4 chip. Sentences -->+    <string name="lg_chip_pc4_info">The program counter keeps track of which instruction a CPU runs next, and pc shows the current count. On each tick, if load is 1, it jumps to the number on v. Otherwise, if en is 1, it counts up by one, wrapping from 15 back to 0. Otherwise, it stays the same.</string>+    <!-- Chip tray and canvas: name of the RAM4 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep RAM4 -->+    <string name="lg_chip_ram4_label">RAM4</string>+    <!-- Chip info sheet: explanation of the RAM4 chip. Sentences -->+    <string name="lg_chip_ram4_info">This chip is four bytes of memory, numbered 0 to 3. The inputs a1 and a0 form the address of one byte, with a1 as the high bit, and dout always shows the byte stored there. On each tick, if we (write enable) is 1, the byte on din is saved at that address.</string>+    <!-- Chip tray and canvas: name of the RAM16 chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep RAM16 -->+    <string name="lg_chip_ram16_label">RAM16</string>+    <!-- Chip info sheet: explanation of the RAM16 chip. Sentences -->+    <string name="lg_chip_ram16_info">This chip is sixteen bytes of memory that can be read in two places at once. instr always shows the byte at address iaddr, and dout always shows the byte at address daddr. On each tick, if we (write enable) is 1, the byte on din is saved at address daddr. A CPU uses one address to fetch instructions and the other to read and write data.</string>+    <!-- Chip tray and canvas: name of the DECODER chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep DECODER -->+    <string name="lg_chip_decoder_label">DECODER</string>+    <!-- Chip info sheet: explanation of the DECODER chip. Sentences -->+    <string name="lg_chip_decoder_info">The instruction decoder reads the instruction number op and the zero flag z, and works out which parts of the CPU should act on this tick. Its outputs are:\n• aluOp1 and aluOp0: which operation the ALU does (00 adds, 01 subtracts, 11 passes b through).\n• accLoad: 1 when the ALU\'s result should be stored in the accumulator.\n• memWrite: 1 when the accumulator should be written to memory.\n• useImm: 1 when the ALU should use the number inside the instruction instead of a byte from memory.\n• jump: 1 when the program counter should jump to a new address.\n• halt: 1 when the program has finished.</string>+    <!-- Chip tray and canvas: name of the CPU chip, printed on a small box. Keep it very short; use the abbreviation people in your language use for this logic chip, or keep CPU -->+    <string name="lg_chip_cpu_label">CPU</string>+    <!-- Chip info sheet: explanation of the CPU chip. Sentences -->+    <string name="lg_chip_cpu_info">This is a complete processor. On each tick it runs the instruction on instr, using data, the byte that memory sends back. Its outputs are:\n• pc: the address of the instruction being run.\n• addr: the memory address this instruction reads from or writes to.\n• dout and we: when we is 1, the byte on dout should be written to memory.\n• acc: the accumulator, which holds the number the CPU is working on.\n• halt: 1 when the program has finished.</string> </resources>
games/logicgate/src/test/java/com/vayunmathur/games/logicgate/domain/ChipInfoTest.kt
diff --git a/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/domain/ChipInfoTest.kt b/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/domain/ChipInfoTest.ktindex 698bd5d3ff..db040e8aaa 100644--- a/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/domain/ChipInfoTest.kt+++ b/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/domain/ChipInfoTest.kt@@ -4,14 +4,14 @@ import com.vayunmathur.games.logicgate.domain.model.ChipInfo import com.vayunmathur.games.logicgate.domain.model.Chips import kotlin.test.Test import kotlin.test.assertNotNull-import kotlin.test.assertTrue  class ChipInfoTest {      @Test     fun everyChipHasABlurb() {         for (chip in Chips.all) {-            assertTrue(ChipInfo.of(chip.id).orEmpty().isNotBlank(), "missing blurb for ${chip.id}")+            assertNotNull(ChipInfo.label(chip.id), "missing label for ${chip.id}")+            assertNotNull(ChipInfo.blurb(chip.id), "missing blurb for ${chip.id}")         }     } @@ -27,7 +27,7 @@ class ChipInfoTest {             Chips.DECODER, Chips.CPU,         )) {             assertNotNull(Chips[id], id)-            assertNotNull(ChipInfo.of(id), id)+            assertNotNull(ChipInfo.blurb(id), id)         }     } }
games/logicgate/src/test/java/com/vayunmathur/games/logicgate/ui/canvas/CanvasControllerTest.kt
diff --git a/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/ui/canvas/CanvasControllerTest.kt b/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/ui/canvas/CanvasControllerTest.ktindex 2b9566d1a7..33f80cbfe0 100644--- a/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/ui/canvas/CanvasControllerTest.kt+++ b/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/ui/canvas/CanvasControllerTest.kt@@ -37,7 +37,7 @@ class CanvasControllerTest {         val controller = CanvasController(CameraState(1f), 1f, trash)         val actions = Recorder()         val state = GameUiState(level, circuit, emptyList(), listOf(0, 0))-        controller.bind(state, actions, CircuitLayout(circuit, lookup), lookup)+        controller.bind(state, actions, CircuitLayout(circuit, lookup, emptyMap()), lookup)         return Triple(controller, actions, circuit)     } 
games/logicgate/src/test/java/com/vayunmathur/games/logicgate/ui/canvas/HitTestTest.kt
diff --git a/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/ui/canvas/HitTestTest.kt b/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/ui/canvas/HitTestTest.ktindex 34af9149de..1771a733e7 100644--- a/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/ui/canvas/HitTestTest.kt+++ b/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/ui/canvas/HitTestTest.kt@@ -21,7 +21,7 @@ class HitTestTest {         val (c0, nand) = Circuit.forLevel(level.io).addGate(Chips.NAND, Point(200f, 0f))         val output = c0.nodes.first { it is com.vayunmathur.games.logicgate.domain.model.LevelOutput }.id         val c = requireNotNull(c0.connect(PinRef(nand, PinSide.OUT, 0), PinRef(output, PinSide.IN, 0), lookup))-        return CircuitLayout(c, lookup) to PinRef(nand, PinSide.OUT, 0)+        return CircuitLayout(c, lookup, emptyMap()) to PinRef(nand, PinSide.OUT, 0)     }      private fun hit(layout: CircuitLayout, at: Offset) = HitTest.hit(layout, at, 24f, 14f, 12f)