Compare commits
15 Commits
deno-test-
...
v0.1.0-alp
Author | SHA1 | Date | |
---|---|---|---|
f416e7a427 | |||
c09c6c0a71 | |||
267e49f532 | |||
792c282fdc | |||
6d7d65dc67 | |||
31f77c22da | |||
a6d093d728 | |||
7b04080e9e | |||
69a954696a | |||
3bc7212d86 | |||
8303cef501 | |||
51f6856fba | |||
2ec4243027 | |||
d542b2a2bc | |||
1aea0b1221 |
15
builtins.ts
15
builtins.ts
@ -127,12 +127,13 @@ const faux = {
|
||||
}
|
||||
return getMapSheet(mapSheet).get(x, y)[1];
|
||||
},
|
||||
mset: (mapSheet: number, x: number, y: number, sprSheet: number, spr: number) => {
|
||||
if (x < 0 || x >= 64 || y < 0 || y >= 64) {
|
||||
return;
|
||||
}
|
||||
getMapSheet(mapSheet).set(x, y, [sprSheet, spr]);
|
||||
},
|
||||
// Temporarily removing mset, since it would overwrite static cart data
|
||||
// mset: (mapSheet: number, x: number, y: number, sprSheet: number, spr: number) => {
|
||||
// if (x < 0 || x >= 64 || y < 0 || y >= 64) {
|
||||
// return;
|
||||
// }
|
||||
// getMapSheet(mapSheet).set(x, y, [sprSheet, spr]);
|
||||
// },
|
||||
// Input
|
||||
[CHAR.UP]: K.ARROW_UP,
|
||||
[CHAR.DOWN]: K.ARROW_DOWN,
|
||||
@ -169,6 +170,8 @@ const faux = {
|
||||
WeakSet,
|
||||
isFinite,
|
||||
isNaN,
|
||||
parseFloat,
|
||||
parseInt,
|
||||
// Math
|
||||
max: Math.max,
|
||||
min: Math.min,
|
||||
|
14
cart.ts
14
cart.ts
@ -2,19 +2,25 @@ import { path } from "./deps.ts";
|
||||
import initialCart from "./initialCart.json" assert { type: "json" };
|
||||
import { Sheet } from "./sheet.ts";
|
||||
|
||||
let cart = initialCart as Array<Sheet>;
|
||||
const extension = ".faux";
|
||||
|
||||
let staticCart = initialCart as Array<Sheet>;
|
||||
let cart: Array<Sheet> = JSON.parse(JSON.stringify(staticCart));
|
||||
|
||||
const virtualPathToRealPath = (virtualFname: string) => {
|
||||
const realPath = path.join(".", "carts", ...virtualFname.split("/"));
|
||||
const vfname = virtualFname + extension;
|
||||
const realPath = path.join(".", "carts", ...vfname.split("/"));
|
||||
return realPath;
|
||||
}
|
||||
|
||||
export const saveCart = async (fname: string) => {
|
||||
await Deno.writeTextFile(virtualPathToRealPath(fname+".fx"), JSON.stringify(getCart()));
|
||||
await Deno.writeTextFile(virtualPathToRealPath(fname), JSON.stringify(getCart()));
|
||||
}
|
||||
|
||||
export const loadCart = async (fname: string) => {
|
||||
cart = JSON.parse(await Deno.readTextFile(virtualPathToRealPath(fname+".fx")));
|
||||
const json = await Deno.readTextFile(virtualPathToRealPath(fname));
|
||||
staticCart = JSON.parse(json);
|
||||
cart = JSON.parse(json);
|
||||
}
|
||||
|
||||
export const getCart = () => {
|
||||
|
1
carts/logo.faux
Normal file
1
carts/logo.faux
Normal file
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
[{"sheet_type":"code","value":"// Sample\n\nlet r = 0;\nlet d = 1;\nreturn {\n\tinit() {},\n\tupdate() {\n\t\tif (r >= 20) {\n\t\t\td = -1;\n\t\t} else if (r < 0) {\n\t\t\td = 1;\n\t\t}\n\t\tr += d*0.1;\t\n\t},\n\tdraw() {\n\t\tcls();\n\t\tcirc(50, 50, 6, 17);\n\t\ttxt(10,10,\"Hello, World!\");\n\t}\n}"},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null}]
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
[{"sheet_type":"code","value":"// Sample\n\nlet r = 0;\nlet d = 1;\nreturn {\n\tinit() {},\n\tupdate() {\n\t\tif (r >= 20) {\n\t\t\td = -1;\n\t\t} else if (r < 0) {\n\t\t\td = 1;\n\t\t}\n\t\tr += d*0.1;\t\n\t},\n\tdraw() {\n\t\tcls();\n\t\trectfill(50,50,46,21,6);\n\t\toval(50, 50, 95, 70, 17);\n\t\ttxt(10,10,\"Hello, World!\");\n\t}\n}"},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null}]
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
[{"sheet_type":"code","value":"\nx = 0;\nbool = true;\nstring = \"hi\";\n\nreturn {\n\tinit() {\n\t\t// init\n\t},\n\tupdate() {\n\t\t// update\n\t},\n\tdraw() {\n\t\t// draw\n\t\tcls();\n\t\ttxt(20, 20, \"hello, world\");\n\t}\n}"},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null}]
|
@ -1 +0,0 @@
|
||||
[{"sheet_type":"code","value":"\nx = 0;\nbool = true;\nstring = \"hi\";\ntext = code(1);\n\nreturn {\n\tinit() {\n\t\t// init\n\t},\n\tupdate() {\n\t\t// update\n\t},\n\tdraw() {\n\t\t// draw\n\t\tcls();\n\t\ttxt(20, 20, text);\n\t}\n}"},{"sheet_type":"code","value":"return \"hi from sheet 01.\";"},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null},{"sheet_type":"none","value":null}]
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -6,6 +6,7 @@
|
||||
"run": "deno run -A --unstable index.ts",
|
||||
"build": "deno compile --output build/faux -A --unstable index.ts",
|
||||
"build_linux": "deno compile --output build/faux_linux --target x86_64-unknown-linux-gnu -A --unstable index.ts",
|
||||
"build_windows": "deno compile --output build/faux_windows --target x86_64-pc-windows-msvc -A --unstable index.ts"
|
||||
"build_windows": "deno compile --output build/faux_windows --target x86_64-pc-windows-msvc -A --unstable index.ts",
|
||||
"build_all": "deno task build_linux & deno task build_windows"
|
||||
}
|
||||
}
|
||||
|
134
manual.md
Normal file
134
manual.md
Normal file
@ -0,0 +1,134 @@
|
||||
# Faux Manual
|
||||
|
||||
This document is up-to-date as of May 14, 2023.
|
||||
|
||||
Faux is a [fantasy console](https://en.wikipedia.org/wiki/Fantasy_video_game_console) heavily inspired by [PICO-8](https://www.lexaloffle.com/pico-8.php), but with several alternative design choices. It is probably nowhere near as resource efficient either.
|
||||
|
||||
This console being in its infancy, this document is literally the only documentation that exists. As such, anything not found in this documentation should be asked of the author, or assumed to be similar to PICO-8.
|
||||
|
||||
## What's different from PICO-8?
|
||||
|
||||
Glad you asked.
|
||||
|
||||
Probably the most important difference is that cartridges are written in JavaScript rather than Lua.
|
||||
|
||||
Another huge design difference is that rather than having a fixed amount of sprite/map/music data, a Faux cartridge is made up of up to 16 "sheets". Each sheet can store a certain amount of data in a specific format. Sheets can be used to hold sprite data, map data, code, and eventually music/sfx, fonts, and other types of data. The first sheet must always be a code sheet and must return an object with three properties: `init`, `update`, and `draw`, each of which should be a function.
|
||||
|
||||
## Code
|
||||
|
||||
The code used in faux cartridges is JavaScript, but without a lot of the language built-ins. Instead, faux provides it's own api to accomplish things like drawing sprites, etc.
|
||||
|
||||
In the code editor, a few special characters can be inserted by holding alt while pressing another key. Currently, the characters that can be added in this way are:
|
||||
|
||||
Symbols for arrows:
|
||||
|
||||
- `⬆️` (Alt+W)
|
||||
- `⬅️` (Alt+A)
|
||||
- `⬇️` (Alt+S)
|
||||
- `➡️` (Alt+D)
|
||||
|
||||
And math symbols:
|
||||
|
||||
- `π` (Alt+P)
|
||||
|
||||
### Graphics
|
||||
|
||||
- `cls(color?: number)` clears the screen to the given color if provided, otherwise, black.
|
||||
- `camera(x: number, y: number)` draws everything from here on with an offset of (-x, -y).
|
||||
- `sprsht(sheet: number)` sets the current spritesheet used for drawing sprites with the `spr` function below.
|
||||
- `spr(x: number, y: number, sprite: number)` draws the given sprite from the current spritesheet at (x,y).
|
||||
- `txt(x: number, y: number, text: string, color?: number)` draws the given text at (x,y) in the provided color (or white if none provided).
|
||||
- `rectfill(x: number, y: number, w: number, h: number, color: number)` fills a rectangle with the given color with a top-left corner at (x,y) and a width of w and a height of h.
|
||||
- `rect(x: number, y: number, w: number, h: number, color: number)` outlines a rectangle with the given color with a top-left corner at (x,y) and a width of w and a height of h.
|
||||
- `circfill(x: number, y: number, r: number, color: number)` fills a circle with the given color with a center at (x,y) and a radius of r.
|
||||
- `circ(x: number, y: number, r: number, color: number)` outlines a circle with the given color with a center at (x,y) and a radius of r.
|
||||
- `ovalfill(x0: number, y0: number, x1: number, y1: number, color: number)` fills an ellipse with the given color whose bounding box has a top-left corner at (x0,y0) and a bottom-right corner at (x1,y1).
|
||||
- `oval(x0: number, y0: number, x1: number, y1: number, color: number)` outlines an ellipse with the given color whose bounding box has a top-left corner at (x0,y0) and a bottom-right corner at (x1,y1).
|
||||
- `pset(x: number, y: number, color: number)` sets the color of the pixel at (x,y) to the given color.
|
||||
- `map(mapSheet: number, tileX: number, tileY: number, screenX: number, screenY: number, tileW: number, tileH: number)` draws the map of the given sheet to the screen at (screenX,screenY) beginning from from the tile at (tileX,tileY) and drawing tileW many tiles across, and tileH many tiles down.
|
||||
|
||||
### Map
|
||||
|
||||
- `mgetsht(mapSheet: number, x: number, y: number)` returns the sheet number of the sprite at tile (x,y) in the given map
|
||||
- `mgetspr(mapSheet: number, x: number, y: number)` returns the sprite number within it's sheet of the sprite at tile (x,y) in the given map
|
||||
- `mset(mapSheet: number, x: number, y: number, sprSheet: number, spr: number)` sets the sprite at tile (x,y) in the given map to the given sprite of the given spritesheet. **(THIS FUNCTION IS TEMPORARILY UNAVAILABLE.)**
|
||||
|
||||
### Input
|
||||
|
||||
- `btn(key: string | number)` returns a boolean indicating whether the given key is currently held down.
|
||||
- `btnp(key: string | number)` returns a boolean indicating whether the given key has just been pressed. Fires repeatedly after a time, as when typing.
|
||||
- `btnr(key: string | number)` returns a boolean indicating whether the given key has just been released.
|
||||
|
||||
There are also values:
|
||||
|
||||
- `⬆️` a number that corresponds to the up arrow.
|
||||
- `⬅️` a number that corresponds to the left arrow.
|
||||
- `⬇️` a number that corresponds to the down arrow.
|
||||
- `➡️` a number that corresponds to the right arrow.
|
||||
|
||||
### System
|
||||
|
||||
- `save(name: string)` saves the cartridge
|
||||
- `load(name: string)` loads the cartridge
|
||||
- `play()` plays the cartridge
|
||||
|
||||
### Misc.
|
||||
|
||||
- `code(sheet: number)` executes the code in the given sheet as a function and returns any return value.
|
||||
- `log(...args: any)` logs the given args to the stdout of faux.
|
||||
|
||||
### REPL Only
|
||||
|
||||
- `print(val: any)` only really should be used in the repl.
|
||||
- `printVal(val: any)` only really should be used in the repl.
|
||||
|
||||
### Math functions
|
||||
|
||||
These are all identical to what Javascript typically has under the [`Math`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math) namespace:
|
||||
|
||||
- `max`
|
||||
- `min`
|
||||
- `floor`
|
||||
- `ceil`
|
||||
- `sin`
|
||||
- `cos`
|
||||
- `atan2`
|
||||
- `sqrt`
|
||||
- `abs`
|
||||
- `rand`
|
||||
|
||||
Faux also provides:
|
||||
|
||||
- `π` which is just `Math.PI` in regular JS.
|
||||
|
||||
### JS Objects
|
||||
|
||||
The following JS objects/functions/value are exactly provided as is in a typical JS environment:
|
||||
|
||||
- [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
|
||||
- [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
|
||||
- [`Boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
|
||||
- [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
|
||||
- [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
|
||||
- [`Function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
|
||||
- [`Infinity`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity)
|
||||
- [`JSON`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON)
|
||||
- [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
|
||||
- [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN)
|
||||
- [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
|
||||
- [`Object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
|
||||
- [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
||||
- [`Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
|
||||
- [`Reflect`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect)
|
||||
- [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
|
||||
- [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
|
||||
- [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
|
||||
- [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
|
||||
- [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
|
||||
- [`WeakRef`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
|
||||
- [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
|
||||
- [`isFinite`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
|
||||
- [`isNaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN)
|
||||
- [`eval`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
|
||||
- [`parseFloat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
|
||||
- [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
|
49
mouse.ts
49
mouse.ts
@ -13,8 +13,11 @@ const mouseButtonsDown = {
|
||||
[M.RIGHT]: false,
|
||||
[M.MIDDLE]: false,
|
||||
};
|
||||
|
||||
type MouseEventType = "click" | "down" | "up" | "move" | "dblclick";
|
||||
|
||||
const mouseEvents: Array<{
|
||||
type: "click" | "down" | "up" | "move" | "dblclick",
|
||||
type: MouseEventType,
|
||||
button: typeof M[keyof typeof M],
|
||||
x: number,
|
||||
y: number,
|
||||
@ -27,37 +30,59 @@ let mouseY = 0;
|
||||
|
||||
const eventPixelCoords = (evt: WindowMouseEvent) => {
|
||||
const {width, height} = gameWindow.size;
|
||||
const pixX = Math.floor(128*evt.clientX/width);
|
||||
const pixY = Math.floor(128*evt.clientY/height);
|
||||
const min = Math.min(width, height);
|
||||
const pixX = Math.floor(128*(evt.clientX-(width-min)/2)/min);
|
||||
const pixY = Math.floor(128*(evt.clientY-(height-min)/2)/min);
|
||||
if (pixX < 0 || pixX > 128 || pixY < 0 || pixY > 128) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
x: pixX,
|
||||
y: pixY,
|
||||
}
|
||||
}
|
||||
|
||||
const pushEvent = (type: MouseEventType, evt: WindowMouseEvent, extra?: Partial<typeof mouseEvents[0]>) => {
|
||||
const coords = eventPixelCoords(evt);
|
||||
if (!coords) {
|
||||
return
|
||||
}
|
||||
mouseEvents.push({type, button: evt.button, ...coords, ...(extra ?? {})});
|
||||
}
|
||||
|
||||
const evtInBounds = (evt: WindowMouseEvent) => {
|
||||
return !!eventPixelCoords(evt);
|
||||
}
|
||||
|
||||
addEventListener("dblclick", (evt) => {
|
||||
mouseEvents.push({type: "dblclick", button: evt.button, ...eventPixelCoords(evt)});
|
||||
pushEvent("dblclick", evt);
|
||||
});
|
||||
|
||||
addEventListener("click", (evt) => {
|
||||
mouseEvents.push({type: "click", button: evt.button, ...eventPixelCoords(evt)});
|
||||
pushEvent("click", evt);
|
||||
});
|
||||
|
||||
addEventListener("mousedown", (evt) => {
|
||||
mouseButtonsDown[evt.button] = true;
|
||||
mouseEvents.push({type: "down", button: evt.button, ...eventPixelCoords(evt)});
|
||||
if (evtInBounds(evt)) {
|
||||
mouseButtonsDown[evt.button] = true;
|
||||
}
|
||||
pushEvent("down", evt);
|
||||
});
|
||||
|
||||
addEventListener("mouseup", (evt) => {
|
||||
mouseButtonsDown[evt.button] = false;
|
||||
mouseEvents.push({type: "up", button: evt.button, ...eventPixelCoords(evt)});
|
||||
if (evtInBounds(evt)) {
|
||||
mouseButtonsDown[evt.button] = false;
|
||||
}
|
||||
pushEvent("up", evt);
|
||||
});
|
||||
|
||||
addEventListener("mousemove", (evt) => {
|
||||
const coords = eventPixelCoords(evt);
|
||||
mouseEvents.push({type: "move", button: evt.button, ...eventPixelCoords(evt), prevX: mouseX, prevY: mouseY});
|
||||
mouseX = coords.x;
|
||||
mouseY = coords.y;
|
||||
pushEvent("up", evt, {prevX: mouseX, prevY: mouseY});
|
||||
if (coords) {
|
||||
mouseX = coords.x;
|
||||
mouseY = coords.y;
|
||||
}
|
||||
});
|
||||
|
||||
export const mousePos = () => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
- [x] load
|
||||
- [x] save
|
||||
- [ ] folder
|
||||
- [ ] ls
|
||||
- [ ] ls (cd?)
|
||||
- [x] run
|
||||
- [ ] stop
|
||||
- [ ] resume
|
||||
|
28
runcode.ts
28
runcode.ts
@ -1,9 +1,20 @@
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const G: any = {
|
||||
eval: eval,
|
||||
};
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const builtins: any = {};
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const G: any = {};
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export const addToContext = (name: string, value: any) => {
|
||||
builtins[name] = value;
|
||||
}
|
||||
|
||||
export const getBuiltins = () => {
|
||||
return builtins;
|
||||
}
|
||||
|
||||
addToContext("eval", eval);
|
||||
|
||||
const context = new Proxy(G, {
|
||||
get: (target, prop) => {
|
||||
if (prop in builtins) {
|
||||
@ -44,13 +55,4 @@ export const evalCode = (code: string) => {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export const addToContext = (name: string, value: any) => {
|
||||
builtins[name] = value;
|
||||
}
|
||||
|
||||
export const getBuiltins = () => {
|
||||
return builtins;
|
||||
}
|
3
sheet.ts
3
sheet.ts
@ -18,7 +18,7 @@ export type Sheet = {
|
||||
}
|
||||
export type SheetType = Sheet["sheet_type"];
|
||||
|
||||
export const getSheet = (n: number) => {
|
||||
export const getSheet = (n: number): Sheet => {
|
||||
return getCart()[n];
|
||||
}
|
||||
|
||||
@ -51,5 +51,6 @@ export const getMapSheet = (sheet: number) => {
|
||||
if (sheet_type !== "map") {
|
||||
throw "Trying to use a non-map sheet as a map."
|
||||
}
|
||||
sheet_type
|
||||
return LinearGrid(value, 64);
|
||||
}
|
19
window.ts
19
window.ts
@ -8,9 +8,9 @@ import { COLOR, palette } from "./colors.ts";
|
||||
|
||||
export const gameWindow = createWindow({
|
||||
title: "Faux",
|
||||
width: 1024,
|
||||
height: 1024,
|
||||
resizable: false,
|
||||
width: 512,
|
||||
height: 512,
|
||||
resizable: true,
|
||||
glVersion: [3, 2],
|
||||
gles: true,
|
||||
});
|
||||
@ -92,16 +92,20 @@ if (status[0] === gl.FALSE) {
|
||||
|
||||
gl.ClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
addEventListener("resize", (event) => {
|
||||
gl.Viewport(0, 0, event.width, event.height);
|
||||
});
|
||||
|
||||
const pixelsPerRow = 128;
|
||||
|
||||
const top = 1;
|
||||
const left = -1;
|
||||
const cell = 2/pixelsPerRow;
|
||||
|
||||
const getHalfAsInt = (n: number) => Number(parseInt(Math.floor(n/2).toString()));
|
||||
|
||||
addEventListener("resize", (event) => {
|
||||
const {width, height} = event;
|
||||
const min = Math.min(width, height);
|
||||
gl.Viewport(getHalfAsInt(width-min), getHalfAsInt(height-min), min, min);
|
||||
});
|
||||
|
||||
const px = (x: number, y: number) => {
|
||||
// deno-fmt-ignore
|
||||
return [
|
||||
@ -238,7 +242,6 @@ export const fillRectRaw = (x: number, y: number, w: number, h: number, color: n
|
||||
|
||||
export const clearScreen = (color?: number) => {
|
||||
fillRectRaw(0, 0, 128, 128, color ?? COLOR.BLACK);
|
||||
// allPixelColors.fill(0);
|
||||
}
|
||||
|
||||
export const frame = () => {
|
||||
|
Reference in New Issue
Block a user