Skip to content

Commit

Permalink
split README and api
Browse files Browse the repository at this point in the history
  • Loading branch information
thacuber2a03 committed Jul 18, 2024
1 parent fd2b9c3 commit d3ae24d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 68 deletions.
70 changes: 2 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ run `txt` in the command line, pass a file name to run from that

tada.wav

[documentation](/api.md)

## games made with it

### shiftword
Expand All @@ -18,74 +20,6 @@ a little game of shifting letters to make words

https://ppepp.itch.io/shiftword

## doc

you must make a 'Game' class with a `new` constructor and an `update` method that must also take in a parameter for the delta time

all of txt's behavior is within the `TXT` foreign class.

### window methods

note: all window position/size related methods are measured in cells

| method | description |
| :-: | :-: |
| `width` | returns window width |
| `width=(w)` | sets window width to `w` |
| `height` | returns window height |
| `height=(h)` | sets window height to `h` |
| `size` | returns window size as a list |
| `size(w,h)` | shorter version of calling `width(w)` and `height(h)` |
| `size(s)` | sets window size to `s`, s must be a list |
| `title=(t)` | sets window title to `t` |
| `move(x,y)` | moves window by `x`, `y` |
| `move(p)` | shorter version of `move(x, y)`, takes a list |
| `fontSize(px)` | sets font size to `px` |
| `exit()` | exits txt |

### drawing methods

| method | description |
| :-: | :-: |
| `clear(char)` | clears screen with character `char` |
| `write(x,y,value)` | writes `value` at position `x`, `y` |
| `write(p,value)` | version of `write` that takes in a list |
| `read(x,y)` | reads character at position `x`, `y` |
| `read(p)` | version of `read` that takes in a list |
| `color(r,g,b)` | sets color for new characters to `r`, `g`, `b` |
| `color=(g)` | list version of `color(r,g,b)`, set to a num for grayscale instead |
| `bgColor(r,g,b)` | same as `color(r,g,b)` but sets background color instead |
| `bgColor=(g)` | list version of `bgColor(r,g,b)`, set to a num for grayscale instead |

note: both the current color and current background color will reset after the end of the `update` method

### input methods

| method | description |
| :-: | :-: |
| `mousePos` | returns mouse position in cell coordinates as list |
| `mouseDown(btn)` | checks if mouse button `btn` is down |
| `mousePressed(btn)` | checks if mouse button `btn` was just pressed |
| `keyDown(key)` | checks if keyboard key `key` is down |
| `keyPressed(key)` | checks if keyboard key `key` was just pressed |
| `keyPressed` | returns whether *any* key has been pressed |
| `charsPressed` | returns the character just pressed, call multiple times for chars queued |

#### allowed key names
- a-z, 0-9
- arrow keys (`right`, `left`, `up`, `down`)
- `space`, `enter`/`return`, `escape`, `backspace` and `delete`
- `lctrl`/`rctrl`, `lshift`/`rshift`, `tab`

#### allowed mouse button names
- `left`, `middle` and `right`

### miscellaneous

| method | description |
| :-: | :-: |
| `version` | the release version, as a [semver](https://semver.org/) string |

## build

Windows:
Expand Down
67 changes: 67 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# api

you must make a 'Game' class with a `new` constructor and an `update` method that must also take in a parameter for the delta time

all of txt's behavior is within the `TXT` foreign class.

## window methods

note: all window position/size related methods are measured in cells

| method | description |
| :-: | :-: |
| `width` | returns window width |
| `width=(w)` | sets window width to `w` |
| `height` | returns window height |
| `height=(h)` | sets window height to `h` |
| `size` | returns window size as a list |
| `size(w,h)` | shorter version of calling `width(w)` and `height(h)` |
| `size(s)` | sets window size to `s`, s must be a list |
| `title=(t)` | sets window title to `t` |
| `move(x,y)` | moves window by `x`, `y` |
| `move(p)` | shorter version of `move(x, y)`, takes a list |
| `fontSize(px)` | sets font size to `px` |
| `exit()` | exits txt |

## drawing methods

| method | description |
| :-: | :-: |
| `clear(char)` | clears screen with character `char` |
| `write(x,y,value)` | writes `value` at position `x`, `y` |
| `write(p,value)` | version of `write` that takes in a list |
| `read(x,y)` | reads character at position `x`, `y` |
| `read(p)` | version of `read` that takes in a list |
| `color(r,g,b)` | sets color for new characters to `r`, `g`, `b` |
| `color=(g)` | list version of `color(r,g,b)`, set to a num for grayscale instead |
| `bgColor(r,g,b)` | same as `color(r,g,b)` but sets background color instead |
| `bgColor=(g)` | list version of `bgColor(r,g,b)`, set to a num for grayscale instead |

note: both the current color and current background color will reset after the end of the `update` method

## input methods

| method | description |
| :-: | :-: |
| `mousePos` | returns mouse position in cell coordinates as list |
| `mouseDown(btn)` | checks if mouse button `btn` is down |
| `mousePressed(btn)` | checks if mouse button `btn` was just pressed |
| `keyDown(key)` | checks if keyboard key `key` is down |
| `keyPressed(key)` | checks if keyboard key `key` was just pressed |
| `keyPressed` | returns whether *any* key has been pressed |
| `charsPressed` | returns the character just pressed, call multiple times for chars queued |

### allowed key names
- a-z, 0-9
- arrow keys (`right`, `left`, `up`, `down`)
- `space`, `enter`/`return`, `escape`, `backspace` and `delete`
- `lctrl`/`rctrl`, `lshift`/`rshift`, `tab`

### allowed mouse button names
- `left`, `middle` and `right`

## miscellaneous

| method | description |
| :-: | :-: |
| `version` | the release version, as a [semver](https://semver.org/) string |

0 comments on commit d3ae24d

Please sign in to comment.