merge: More patterns
This commit is contained in:
@@ -118,6 +118,12 @@ action_t config_parse_action(const char *s) {
|
||||
if (strcmp(pat, "blinker") == 0) return ACTION_SELECT_BLINKER;
|
||||
if (strcmp(pat, "block") == 0) return ACTION_SELECT_BLOCK;
|
||||
if (strcmp(pat, "toad") == 0) return ACTION_SELECT_TOAD;
|
||||
if (strcmp(pat, "beacon") == 0) return ACTION_SELECT_BEACON;
|
||||
if (strcmp(pat, "boat") == 0) return ACTION_SELECT_BOAT;
|
||||
if (strcmp(pat, "tub") == 0) return ACTION_SELECT_TUB;
|
||||
if (strcmp(pat, "beehive") == 0) return ACTION_SELECT_BEEHIVE;
|
||||
if (strcmp(pat, "rpentomino") == 0) return ACTION_SELECT_RPENTOMINO;
|
||||
if (strcmp(pat, "acorn") == 0) return ACTION_SELECT_ACORN;
|
||||
}
|
||||
return ACTION_NONE;
|
||||
}
|
||||
@@ -129,6 +135,12 @@ config_t config_defaults(void) {
|
||||
{"2", ACTION_SELECT_BLINKER},
|
||||
{"3", ACTION_SELECT_BLOCK},
|
||||
{"4", ACTION_SELECT_TOAD},
|
||||
{"5", ACTION_SELECT_BEACON},
|
||||
{"6", ACTION_SELECT_BOAT},
|
||||
{"7", ACTION_SELECT_TUB},
|
||||
{"8", ACTION_SELECT_BEEHIVE},
|
||||
{"9", ACTION_SELECT_RPENTOMINO},
|
||||
{"0", ACTION_SELECT_ACORN},
|
||||
{"space", ACTION_ROTATE},
|
||||
{"escape", ACTION_CANCEL},
|
||||
{"ctrl+q", ACTION_QUIT},
|
||||
@@ -157,6 +169,12 @@ static const char *default_file_content =
|
||||
"\"2\" = \"select:blinker\"\n"
|
||||
"\"3\" = \"select:block\"\n"
|
||||
"\"4\" = \"select:toad\"\n"
|
||||
"\"5\" = \"select:beacon\"\n"
|
||||
"\"6\" = \"select:boat\"\n"
|
||||
"\"7\" = \"select:tub\"\n"
|
||||
"\"8\" = \"select:beehive\"\n"
|
||||
"\"9\" = \"select:rpentomino\"\n"
|
||||
"\"0\" = \"select:acorn\"\n"
|
||||
"\"space\" = \"rotate\"\n"
|
||||
"\"escape\" = \"cancel\"\n"
|
||||
"\"ctrl+q\" = \"quit\"\n"
|
||||
|
||||
@@ -18,6 +18,12 @@ typedef enum {
|
||||
ACTION_SELECT_BLINKER,
|
||||
ACTION_SELECT_BLOCK,
|
||||
ACTION_SELECT_TOAD,
|
||||
ACTION_SELECT_BEACON,
|
||||
ACTION_SELECT_BOAT,
|
||||
ACTION_SELECT_TUB,
|
||||
ACTION_SELECT_BEEHIVE,
|
||||
ACTION_SELECT_RPENTOMINO,
|
||||
ACTION_SELECT_ACORN,
|
||||
ACTION_CLEAR,
|
||||
ACTION_PAUSE,
|
||||
ACTION_STEP,
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-11-08
|
||||
@@ -0,0 +1,30 @@
|
||||
# Design
|
||||
|
||||
## Context
|
||||
|
||||
Pattern module currently has 4 patterns with static offsets. Config maps digits 1-4.
|
||||
|
||||
## Goals / Non-Goals
|
||||
|
||||
**Goals:**
|
||||
- Add 6 patterns with correct offsets.
|
||||
- Extend default config digits 5-0.
|
||||
|
||||
**Non-Goals:**
|
||||
- Pattern editor.
|
||||
- Loading from files.
|
||||
|
||||
## Decisions
|
||||
|
||||
### D1: Pattern storage
|
||||
- Add static offset arrays and entries in `patterns[]`.
|
||||
|
||||
### D2: Key mapping
|
||||
- 5=Beacon, 6=Loaf, 7=Boat, 8=Tub, 9=R-pentomino, 0=Acorn.
|
||||
|
||||
### D3: Config enum
|
||||
- Add `ACTION_SELECT_BEACON` etc. or refactor? Use new enum values for minimal change.
|
||||
|
||||
## Open Questions
|
||||
|
||||
None.
|
||||
@@ -0,0 +1,26 @@
|
||||
# Proposal
|
||||
|
||||
## Why
|
||||
|
||||
The tool currently offers only 4 patterns. Adding a broader set (Beacon, Loaf, Boat, Tub, R-pentomino, Acorn) makes it more useful for exploring Life dynamics.
|
||||
|
||||
## What Changes
|
||||
|
||||
- Add 6 new built-in patterns.
|
||||
- Extend pattern module and count to 10.
|
||||
- Add default key bindings 5–0 for the new patterns.
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
|
||||
None.
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
- `pattern-placement`: additional built-in patterns and their key bindings.
|
||||
|
||||
## Impact
|
||||
|
||||
- Affected code: `pattern.c/h`, `config.c`, `wlgol.c` (enum/actions if needed).
|
||||
- No new dependencies.
|
||||
@@ -0,0 +1,17 @@
|
||||
# Spec Delta
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Additional built-in patterns are available
|
||||
The system SHALL provide additional built-in patterns (Beacon, Loaf, Boat, Tub, R-pentomino, Acorn) selectable via keys 5-0.
|
||||
|
||||
#### Scenario: Select beacon
|
||||
- **WHEN** the user triggers `select:beacon`
|
||||
- **THEN** a beacon preview is shown
|
||||
|
||||
### Requirement: New patterns support rotation
|
||||
The system SHALL support 90-degree rotation for all new patterns.
|
||||
|
||||
#### Scenario: Rotate new pattern
|
||||
- **WHEN** the user rotates a new pattern preview
|
||||
- **THEN** its cells rotate accordingly
|
||||
@@ -0,0 +1,16 @@
|
||||
# Tasks
|
||||
|
||||
## 1. Pattern module
|
||||
|
||||
- [x] 1.1 Add offset arrays for Beacon, Loaf, Boat, Tub, R-pentomino, Acorn.
|
||||
- [x] 1.2 Register new patterns in patterns[] and update pattern_count to 10.
|
||||
|
||||
## 2. Config
|
||||
|
||||
- [x] 2.1 Add select actions for new patterns and default bindings 5-0.
|
||||
- [x] 2.2 Update config defaults and default file content.
|
||||
|
||||
## 3. Verification
|
||||
|
||||
- [x] 3.1 Build and run ctest.
|
||||
- [x] 3.2 Manual test selecting/rotating new patterns.
|
||||
@@ -58,3 +58,17 @@ The system SHALL ignore left clicks when no placement tool is active.
|
||||
#### Scenario: No tool
|
||||
- **WHEN** the user left-clicks while no tool is active
|
||||
- **THEN** the grid is unchanged
|
||||
|
||||
### Requirement: Additional built-in patterns are available
|
||||
The system SHALL provide additional built-in patterns (Beacon, Loaf, Boat, Tub, R-pentomino, Acorn) selectable via keys 5-0.
|
||||
|
||||
#### Scenario: Select beacon
|
||||
- **WHEN** the user triggers `select:beacon`
|
||||
- **THEN** a beacon preview is shown
|
||||
|
||||
### Requirement: New patterns support rotation
|
||||
The system SHALL support 90-degree rotation for all new patterns.
|
||||
|
||||
#### Scenario: Rotate new pattern
|
||||
- **WHEN** the user rotates a new pattern preview
|
||||
- **THEN** its cells rotate accordingly
|
||||
|
||||
@@ -16,14 +16,44 @@ static const cell_offset_t toad_cells[] = {
|
||||
{1,0},{2,0},{3,0},{0,1},{1,1},{2,1}
|
||||
};
|
||||
|
||||
static const cell_offset_t beacon_cells[] = {
|
||||
{0,0},{1,0},{0,1},{1,1},{2,2},{3,2},{2,3},{3,3}
|
||||
};
|
||||
|
||||
static const cell_offset_t boat_cells[] = {
|
||||
{0,0},{1,0},{0,1},{2,1},{1,2}
|
||||
};
|
||||
|
||||
static const cell_offset_t tub_cells[] = {
|
||||
{1,0},{0,1},{2,1},{1,2}
|
||||
};
|
||||
|
||||
static const cell_offset_t beehive_cells[] = {
|
||||
{1,0},{2,0},{0,1},{3,1},{1,2},{2,2}
|
||||
};
|
||||
|
||||
static const cell_offset_t rpent_cells[] = {
|
||||
{1,0},{2,0},{0,1},{1,1},{1,2}
|
||||
};
|
||||
|
||||
static const cell_offset_t acorn_cells[] = {
|
||||
{1,0},{3,1},{0,2},{1,2},{2,2},{3,2},{4,2}
|
||||
};
|
||||
|
||||
static const pattern_t patterns[] = {
|
||||
{"glider", 5, glider_cells},
|
||||
{"blinker", 3, blinker_cells},
|
||||
{"block", 4, block_cells},
|
||||
{"toad", 6, toad_cells},
|
||||
{"beacon", 8, beacon_cells},
|
||||
{"boat", 5, boat_cells},
|
||||
{"tub", 4, tub_cells},
|
||||
{"beehive", 6, beehive_cells},
|
||||
{"rpentomino", 5, rpent_cells},
|
||||
{"acorn", 7, acorn_cells},
|
||||
};
|
||||
|
||||
int pattern_count(void) { return 4; }
|
||||
int pattern_count(void) { return 10; }
|
||||
|
||||
const pattern_t *pattern_get(int index) {
|
||||
if (index < 0 || index >= pattern_count()) return NULL;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "pattern.h"
|
||||
|
||||
int main(void) {
|
||||
assert(pattern_count() == 4);
|
||||
assert(pattern_count() == 10);
|
||||
const void *p = pattern_get(0);
|
||||
(void)p;
|
||||
int dx[16], dy[16];
|
||||
|
||||
@@ -278,6 +278,18 @@ static void handle_key(uint32_t key, uint32_t state, xkb_keysym_t sym, uint32_t
|
||||
active_tool = 2; active_rotation = 0; printf("selected block\n"); break;
|
||||
case ACTION_SELECT_TOAD:
|
||||
active_tool = 3; active_rotation = 0; printf("selected toad\n"); break;
|
||||
case ACTION_SELECT_BEACON:
|
||||
active_tool = 4; active_rotation = 0; printf("selected beacon\n"); break;
|
||||
case ACTION_SELECT_BOAT:
|
||||
active_tool = 5; active_rotation = 0; printf("selected boat\n"); break;
|
||||
case ACTION_SELECT_TUB:
|
||||
active_tool = 6; active_rotation = 0; printf("selected tub\n"); break;
|
||||
case ACTION_SELECT_BEEHIVE:
|
||||
active_tool = 7; active_rotation = 0; printf("selected beehive\n"); break;
|
||||
case ACTION_SELECT_RPENTOMINO:
|
||||
active_tool = 8; active_rotation = 0; printf("selected rpentomino\n"); break;
|
||||
case ACTION_SELECT_ACORN:
|
||||
active_tool = 9; active_rotation = 0; printf("selected acorn\n"); break;
|
||||
case ACTION_CLEAR:
|
||||
printf("clear requested\n");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user