Skip to content

Commit 0288984

Browse files
committed
First Documentation Write
1 parent 943dcbc commit 0288984

File tree

18 files changed

+424
-124
lines changed

18 files changed

+424
-124
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11

22
# llcacodec Changelog
33

4-
# April 1, 2023
4+
# April 2, 2023: Version 0.1.0
5+
6+
Fixed throws function, as output was returning true when not throwing and false when throwing, which is
7+
the opposite of what should have been happening
8+
9+
# April 1, 2023: Version 0.1.0
510

611
Changed all functions with "PlainText" in the name to "Plaintext" instead
712

@@ -11,7 +16,9 @@ Changed name to just be llcacodec from llcacodec.js
1116

1217
Added RLE File Writing
1318

14-
## March 30, 2023
19+
Fixed Life 1.05 Reading
20+
21+
## March 30, 2023: Version 0.1.0
1522

1623
Removed public api function readLifeFileLiveCoordinates. Now all file types return coordinates, and they can be read through readLifeFile(string, format).liveCoordinates
1724

DEV_DOCUMENTATION.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
# llcacodec 0.1.0 Developer Documentation
3+
4+
Currently unwritten, will be here soon.
5+
6+
## Test data downloads
7+
8+
Here will reside some links to test files to download that can be read by llcacodec. Feel free to add any new links
9+
that could provide more data.
10+
11+
[Life Page Links](http://conwaylife.com/ref/DRH/lifelinks.html)
12+
13+
[Conway Life Wiki Pattern Index](https://conwaylife.com/patterns/)
14+
[Zip File for all patterns found on Conway Life Wiki](https://conwaylife.com/patterns/all.zip)
15+
16+
[Alan Hensel lifep](www.ibiblio.org/lifepatterns/lifep.zip)
17+
[Alan Hensel lifebc](www.ibiblio.org/lifepatterns/lifebc.zip)
18+
[Alan Hensel lifepw](www.ibiblio.org/lifepatterns/lifepw.zip)
19+
[Stamp Collection](http://conwaylife.com/ref/DRH/stamps.html)
20+
[Dean Hickerson Patterns](http://conwaylife.com/ref/DRH/life.html)
21+
22+
## Further Reading
23+
24+
[Alan Hensel Applet](http://www.ibiblio.org/lifepatterns/lifeapplet.html)
25+
26+
## Unsupported File Formats
27+
28+
- Extended RLE Format | [Golly Source Format Documentation](https://golly.sourceforge.net/Help/formats.html#rle)
29+
- MacroCell Format | [Golly Source Format Documentation](https://golly.sourceforge.net/Help/formats.html#rle)
30+
- Rule Format | [Golly Source Format Documentation](https://golly.sourceforge.net/Help/formats.html#rle)
31+
- Small Object Format | [LifeWiki](https://conwaylife.com/wiki/Small_object_format) [Pentdecathlon](https://web.archive.org/web/20211102020428/http://pentadecathlon.com/objects/definitions/definitions.php)

DOCUMENTATION.md

Lines changed: 276 additions & 69 deletions
Large diffs are not rendered by default.

NEXT.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
# An incrementally struck-out list of the next plans for llcacodec
3+
4+
Start: Version 0.1.0
5+
6+
- Create a function to test the validity of life-like strings before calling **readLifeString**. **isValidLifeString**.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ llcacodec - Short for **L**ife-**L**ike **C**ellular **A**utomata **Codec**
77

88
![llacodec logo](assets/llcacodec_logo_112x112.png)
99

10+
[Documentation, Supported File and Rule Formats](DOCUMENTATION.md)
11+
1012
Decoding and Encoding of Life-Like Cellular Automata Data Files implemented in Typescript
1113

12-
> **NOTE**: cacodec.js is currently in pre-alpha testing, which means that there may be many unaccounted bugs and
14+
> **NOTE**: llcacodec is currently in pre-alpha testing, which means that there may be many unaccounted bugs and
1315
> unpredicted behaviors present, as well as that the API is subject to change at any time.
1416
15-
- [Documentation, Supported File and Rule Formats](DOCUMENTATION.md)
1617
- [cobyj33's automata project page](https://cobyj33.github.io/automata)
1718
- [cobyj33's automata project github](https://www.github.com/cobyj33/automata)

dist/api.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.writeLifeString = exports.getLifeFileFormat = exports.isLifeStringFormat = exports.readLifeString = exports.getLifeRuleFormat = exports.isValidLifeRule = exports.makeLifeRule = exports.readLifeRule = exports.CONWAY_LIFE_RULE_DATA = void 0;
3+
exports.writeLifeString = exports.getLifeStringFormat = exports.isLifeStringFormat = exports.readLifeString = exports.getLifeRuleFormat = exports.isValidLifeRule = exports.makeLifeRule = exports.readLifeRule = exports.CONWAY_LIFE_RULE_DATA = void 0;
44
const life106_1 = require("./formats/file/life106");
55
const plaintext_1 = require("./formats/file/plaintext");
66
const rle_1 = require("./formats/file/rle");
@@ -16,7 +16,7 @@ function readLifeString(data, format = "") {
1616
if (format === undefined) {
1717
throw new Error("Cannot parse undefined life file");
1818
}
19-
const foundFormat = format === "" ? getLifeFileFormat(data) : format;
19+
const foundFormat = format === "" ? getLifeStringFormat(data) : format;
2020
switch (foundFormat) {
2121
case "plaintext": return (0, plaintext_1.readPlaintextString)(data);
2222
case "life 1.06": return (0, life106_1.readLife106String)(data);
@@ -35,7 +35,7 @@ function isLifeStringFormat(data, format) {
3535
}
3636
}
3737
exports.isLifeStringFormat = isLifeStringFormat;
38-
function getLifeFileFormat(data) {
38+
function getLifeStringFormat(data) {
3939
if ((0, life106_1.isLife106String)(data)) {
4040
return "life 1.06";
4141
}
@@ -50,7 +50,7 @@ function getLifeFileFormat(data) {
5050
}
5151
return "";
5252
}
53-
exports.getLifeFileFormat = getLifeFileFormat;
53+
exports.getLifeStringFormat = getLifeStringFormat;
5454
function writeLifeString(data) {
5555
switch (data.format) {
5656
case "life 1.06": return (0, life106_1.writeLife106String)(data);

dist/types/api.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export declare function readLifeString(data: string, format: "rle"): RLEDecodedD
1111
export declare function readLifeString(data: string, format: "life 1.05"): Life105DecodedData;
1212
export declare function readLifeString(data: string): Life106DecodedData | PlaintextDecodedData | RLEDecodedData | Life105DecodedData;
1313
export declare function isLifeStringFormat(data: string, format: SupportedLifeLikeFormats): boolean;
14-
export declare function getLifeFileFormat(data: string): SupportedLifeLikeFormats | "";
14+
export declare function getLifeStringFormat(data: string): SupportedLifeLikeFormats | "";
1515
type FileFormatData = (Life106EncodingData & {
1616
format: "life 1.06";
1717
}) | (PlaintextMatrixWriteData & {

src/api.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export function readLifeString(data: string, format: "life 1.05"): Life105Decode
1515
export function readLifeString(data: string): Life106DecodedData | PlaintextDecodedData | RLEDecodedData | Life105DecodedData
1616
export function readLifeString(data: string, format: SupportedLifeLikeFormats | "" = ""): Life106DecodedData | PlaintextDecodedData | RLEDecodedData | Life105DecodedData {
1717
if (format === undefined) {
18-
throw new Error("Cannot parse undefined life file")
18+
throw new Error("[llcacodec]: Cannot parse undefined life file")
1919
}
2020

21-
const foundFormat = format === "" ? getLifeFileFormat(data) : format;
21+
const foundFormat = format === "" ? getLifeStringFormat(data) : format;
2222
switch (foundFormat) {
2323
case "plaintext": return readPlaintextString(data);
2424
case "life 1.06": return readLife106String(data);
@@ -37,7 +37,11 @@ export function isLifeStringFormat(data: string, format: SupportedLifeLikeFormat
3737
}
3838
}
3939

40-
export function getLifeFileFormat(data: string): SupportedLifeLikeFormats | "" {
40+
export function getLifeStringFormat(data: string): SupportedLifeLikeFormats | "" {
41+
// Note how the tests are ordered. They are ordered from the most simple to identify
42+
// to the least simple to identify. Life 1.06 and Life 1.05 can simply be identified by
43+
// if their file begins with the appropriate header data. isRLEString is identified by the existence of
44+
// a
4145
if (isLife106String(data)) {
4246
return "life 1.06"
4347
} else if (isLife105String(data)) {

src/core/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export function isRectangularMatrix(matrix: unknown[][]): boolean {
2828
export function throws(action: () => unknown): boolean {
2929
try {
3030
action();
31-
return true;
32-
} catch (e) {
3331
return false;
32+
} catch (e) {
33+
return true;
3434
}
3535
}
3636

src/formats/file/life105.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export interface Life105DecodedData {
3737
cellBlocks: Life105CellBlock[]
3838
liveCoordinates: [number, number][]
3939
descriptions: string[],
40-
ruleString: string | null,
41-
rule: LifeRuleData | null,
40+
rule: string | null,
41+
parsedRule: LifeRuleData | null,
4242
hashLines: HashLine[]
4343
}
4444

@@ -124,13 +124,13 @@ export function isLife105String(file: string): boolean {
124124
export function readLife105String(file: string): Life105DecodedData {
125125
file = file.replace("\r", "")
126126

127-
const life105FileData: Life105DecodedData = {
127+
const life105StringData: Life105DecodedData = {
128128
format: "life 1.05",
129129
cellBlocks: [],
130130
liveCoordinates: [],
131131
descriptions: [],
132-
ruleString: CONWAY_RULE_STRING_SB,
133-
rule: CONWAY_LIFE_RULE_DATA(),
132+
rule: null,
133+
parsedRule: null,
134134
hashLines: []
135135
}
136136

@@ -148,18 +148,18 @@ export function readLife105String(file: string): Life105DecodedData {
148148
const trimmedContent = afterID.trim();
149149

150150
if (id === "D") {
151-
life105FileData.descriptions.push(trimmedContent)
151+
life105StringData.descriptions.push(trimmedContent)
152152
} else if (id === "R") {
153-
life105FileData.ruleString = trimmedContent
154-
life105FileData.rule = readLifeRule(trimmedContent)
153+
life105StringData.rule = trimmedContent
154+
life105StringData.parsedRule = readLifeRule(trimmedContent)
155155
} else if (id === "N") {
156-
life105FileData.ruleString = CONWAY_RULE_STRING_SB
157-
life105FileData.rule = CONWAY_LIFE_RULE_DATA()
156+
life105StringData.rule = CONWAY_RULE_STRING_SB
157+
life105StringData.parsedRule = CONWAY_LIFE_RULE_DATA()
158158
} else if (id === "P") { // encountered beginning of Cell Block Data
159159
break;
160160
}
161161

162-
life105FileData.hashLines.push({
162+
life105StringData.hashLines.push({
163163
id: id,
164164
content: trimmedContent,
165165
full: lines[currentLineIndex].trim()
@@ -172,13 +172,11 @@ export function readLife105String(file: string): Life105DecodedData {
172172

173173
for (let i = 0; i < cellBlockStrings.length; i++) {
174174
const cellBlock = readLife105CellBlock(cellBlockStrings[i])
175-
life105FileData.cellBlocks.push(cellBlock)
176-
life105FileData.liveCoordinates.push(...cellBlock.liveCoordinates)
175+
life105StringData.cellBlocks.push(cellBlock)
176+
life105StringData.liveCoordinates.push(...cellBlock.liveCoordinates)
177177
}
178178

179-
life105FileData.liveCoordinates = uniqueNumberPairArray(life105FileData.liveCoordinates)
179+
life105StringData.liveCoordinates = uniqueNumberPairArray(life105StringData.liveCoordinates)
180180

181-
return life105FileData
182-
}
183-
184-
// function writeLife105String()
181+
return life105StringData
182+
}

0 commit comments

Comments
 (0)