Compare commits

..

No commits in common. "main" and "v0.1.0-alpha.1" have entirely different histories.

24 changed files with 96 additions and 107 deletions

View File

@ -1,25 +1,13 @@
# Faux # fantasy-console
This is a custom fantasy-console (like Pico 8) written in Deno/Typescript. To run,
Go to the [Releases](https://git.playbox.link/dylan/fantasy-console/releases) page to find downloadable executables.
NOTE: If you are running Faux on Linux, you will need to have `xsel` installed.
## Developing
Faux is written in [TypeScript](https://www.typescriptlang.org/) to be run or compiled by [Deno](https://deno.com/runtime).
If you want to build from source, you should have Deno installed, clone this repo, and then...
To run:
``` ```
deno task run deno task run
``` ```
To compile: To compile
``` ```
deno task build_all deno task build
``` ```
NOTE: Development is happening solely on Linux, so some build commands may fail if you are not on Linux or do not have some build dependencies installed. You may need to install `xsel` on Linux machines to use this.

View File

@ -8,15 +8,15 @@ outlineCircle,
fillEllipse, fillEllipse,
outlineEllipse, outlineEllipse,
setPixelColor, setPixelColor,
} from "../io/window.ts"; } from "./window.ts";
import { CHAR, Font, font } from "../data/font.ts"; import { CHAR, Font, font } from "./font.ts";
import { K, keyDown, keyPressed, keyReleased } from "../io/keyboard.ts"; import { K, keyDown, keyPressed, keyReleased } from "./keyboard.ts";
import { addToContext, runCode } from "./runcode.ts"; import { addToContext, runCode } from "./runcode.ts";
import { resetRepl } from "../repl/repl.ts"; import { resetRepl } from "./repl.ts";
import { COLOR } from "../data/colors.ts"; import { COLOR } from "./colors.ts";
import { getSheet, getCodeSheet, getMapSheet } from "../io/sheet.ts"; import { getSheet, getCodeSheet, getMapSheet } from "./sheet.ts";
import { saveCart, loadCart } from "../io/cart.ts"; import { saveCart, loadCart } from "./cart.ts";
import { outlineRect } from "../util/util.ts"; import { outlineRect } from "./util.ts";
let spritesheet: number | null = null; let spritesheet: number | null = null;

View File

@ -1,5 +1,5 @@
import { path } from "../deps.ts"; import { path } from "./deps.ts";
import initialCart from "../data/initialCart.json" assert { type: "json" }; import initialCart from "./initialCart.json" assert { type: "json" };
import { Sheet } from "./sheet.ts"; import { Sheet } from "./sheet.ts";
const extension = ".faux"; const extension = ".faux";

View File

@ -1,13 +1,13 @@
import { clearScreen, fillRect } from "../io/window.ts"; import { clearScreen, fillRect } from "./window.ts";
import { CHAR, font } from "../data/font.ts"; import { CHAR, font } from "./font.ts";
import { drawText, measureText } from "../runtime/builtins.ts"; import { drawText, measureText } from "./builtins.ts";
import { COLOR } from "../data/colors.ts"; import { COLOR } from "./colors.ts";
import { getCodeSheet, setSheet } from "../io/sheet.ts"; import { getCodeSheet, setSheet } from "./sheet.ts";
import { K, ctrlKeyDown, getKeyboardString, keyPressed, shiftKeyDown } from "../io/keyboard.ts"; import { K, ctrlKeyDown, getKeyboardString, keyPressed, shiftKeyDown } from "./keyboard.ts";
import { clipboard, tokenize } from "../deps.ts"; import { clipboard, tokenize } from "./deps.ts";
import { getBuiltins } from "../runtime/runcode.ts"; import { getBuiltins } from "./runcode.ts";
import { page } from "./viewsheets.ts"; import { page } from "./viewsheets.ts";
import { mouseDown, mouseHeld, mousePos } from "../io/mouse.ts"; import { mouseDown, mouseHeld, mousePos } from "./mouse.ts";
const historyDebounceFrames = 20; const historyDebounceFrames = 20;

View File

@ -5,8 +5,8 @@
"tasks": { "tasks": {
"run": "deno run -A --unstable index.ts", "run": "deno run -A --unstable index.ts",
"build": "deno compile --output build/faux -A --unstable index.ts", "build": "deno compile --output build/faux -A --unstable index.ts",
"build_linux": "mkdir -p ./build/zips ; mkdir -p ./build/linux ; cp ./manual.md ./build/linux/README.md ; deno compile --output build/linux/faux --target x86_64-unknown-linux-gnu -A --unstable index.ts ; cd ./build/linux ; zip -r ../zips/faux_linux.zip . ; cd ../..", "build_linux": "deno compile --output build/faux_linux --target x86_64-unknown-linux-gnu -A --unstable index.ts",
"build_windows": "mkdir -p ./build/zips ; mkdir -p ./build/windows ; cp ./manual.md ./build/windows/README.md ; deno compile --output build/windows/faux --target x86_64-pc-windows-msvc -A --unstable index.ts ; cd ./build/windows ; zip -r ../zips/faux_windows.zip . ; cd ../..", "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" "build_all": "deno task build_linux & deno task build_windows"
} }
} }

View File

@ -1,13 +1,13 @@
import { clearScreen, fillRect } from "../io/window.ts"; import { clearScreen, fillRect } from "./window.ts";
import { codetab } from "./codetab.ts"; import { codetab } from "./codetab.ts";
import { spritetab } from "./spritetab.ts"; import { spritetab } from "./spritetab.ts";
import { viewsheets, page } from "./viewsheets.ts"; import { viewsheets, page } from "./viewsheets.ts";
import { COLOR } from "../data/colors.ts"; import { COLOR } from "./colors.ts";
import { mouseClick, mousePos } from "../io/mouse.ts"; import { mouseClick, mousePos } from "./mouse.ts";
import { drawIcon } from "../runtime/builtins.ts"; import { drawIcon } from "./builtins.ts";
import { inRect } from "../util/util.ts"; import { inRect } from "./util.ts";
import { sheetsIcon, trashIcon } from "../data/icons.ts"; import { sheetsIcon, trashIcon } from "./icons.ts";
import { SheetType, setSheet } from "../io/sheet.ts"; import { SheetType, setSheet } from "./sheet.ts";
import { nonetab } from "./nonetab.ts"; import { nonetab } from "./nonetab.ts";
import { maptab } from "./maptab.ts"; import { maptab } from "./maptab.ts";

View File

@ -2,24 +2,24 @@ import {
mainloop, mainloop,
frame, frame,
clearScreen, clearScreen,
} from "./io/window.ts"; } from "./window.ts";
import { runCode } from "./runtime/runcode.ts"; import { runCode } from "./runcode.ts";
import { getCodeSheet } from "./io/sheet.ts"; import { getCodeSheet } from "./sheet.ts";
import { refreshKeyboard, keyPressed, K } from "./io/keyboard.ts"; import { refreshKeyboard, keyPressed, K } from "./keyboard.ts";
import { repl, resetRepl } from "./repl/repl.ts"; import { repl, resetRepl } from "./repl.ts";
import { addToContext } from "./runtime/runcode.ts"; import { addToContext } from "./runcode.ts";
import { editmode } from "./editor/editmode.ts"; import { editmode } from "./editmode.ts";
import { refreshMouse } from "./io/mouse.ts"; import { refreshMouse } from "./mouse.ts";
import { camera } from "./runtime/builtins.ts"; import { camera } from "./builtins.ts";
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
let game: any = null; let game: any = null;
let mode: "play" | "edit" | "repl" = "repl"; let mode: "play" | "edit" | "repl" = "repl";
addToContext("play", async () => { addToContext("play", () => {
game = await runCode(getCodeSheet(0));
mode = "play"; mode = "play";
game = runCode(getCodeSheet(0));
game.init(); game.init();
}); });
@ -43,8 +43,8 @@ await mainloop(async (_t) => {
} else { } else {
if (mode === "play") { if (mode === "play") {
if (game) { if (game) {
await game.update(); game.update();
await game.draw(); game.draw();
} }
frame(); frame();
} else if (mode === "repl") { } else if (mode === "repl") {

View File

@ -1,4 +1,4 @@
import { font, CHAR } from "../data/font.ts"; import { font, CHAR } from "./font.ts";
const keyboard = new Map<number, {first: boolean, repeat: boolean, held: boolean}>(); const keyboard = new Map<number, {first: boolean, repeat: boolean, held: boolean}>();

View File

@ -1,11 +1,13 @@
import { clearScreen, fillRect } from "../io/window.ts"; import { clearScreen, fillRect } from "./window.ts";
import { drawSprite, drawText, useSpritesheet } from "../runtime/builtins.ts"; import { drawSprite, drawText } from "./builtins.ts";
import { COLOR } from "../data/colors.ts"; import { COLOR } from "./colors.ts";
import { getMapSheet, getSheet, setSheet } from "../io/sheet.ts"; import { getMapSheet, getSheet, setSheet } from "./sheet.ts";
import { M, mouseClick, mouseDown, mouseHeld, mousePos } from "../io/mouse.ts"; import { M, mouseClick, mouseDown, mouseHeld, mousePos } from "./mouse.ts";
import { drawTransparentRect, drawVoidRect, inRect, reGrid } from "../util/util.ts"; import { drawTransparentRect, drawVoidRect, inRect, reGrid } from "./util.ts";
import { page } from "./viewsheets.ts"; import { page } from "./viewsheets.ts";
import { keyPressed, K } from "../io/keyboard.ts"; import { useSpritesheet } from "./builtins.ts";
import { keyPressed } from "./keyboard.ts";
import { K } from "./keyboard.ts";
const state = { const state = {
selectedSpriteSheet: 0, selectedSpriteSheet: 0,

View File

@ -1,11 +1,12 @@
import { clearScreen, fillRect } from "../io/window.ts"; import { clearScreen, fillRect } from "./window.ts";
import { drawIcon, drawText, useSpritesheet } from "../runtime/builtins.ts"; import { drawIcon, drawText } from "./builtins.ts";
import { COLOR } from "../data/colors.ts"; import { COLOR } from "./colors.ts";
import { getSheet, setSheet } from "../io/sheet.ts"; import { getSheet, setSheet } from "./sheet.ts";
import { mouseClick, mousePos } from "../io/mouse.ts"; import { mouseClick, mousePos } from "./mouse.ts";
import { reGridWithGap } from "../util/util.ts"; import { reGridWithGap } from "./util.ts";
import { page } from "./viewsheets.ts"; import { page } from "./viewsheets.ts";
import { codeIcon, mapIcon, spriteIcon } from "../data/icons.ts"; import { useSpritesheet } from "./builtins.ts";
import { codeIcon, mapIcon, spriteIcon } from "./icons.ts";
const gridX = 8; const gridX = 8;
const gridY = 40; const gridY = 40;

View File

@ -1,9 +1,9 @@
import { drawText} from "../runtime/builtins.ts"; import { drawText} from "./builtins.ts";
import { getKeysPressed, shiftKeyDown, shiftMap, K } from "../io/keyboard.ts"; import { getKeysPressed, shiftKeyDown, shiftMap, K } from "./keyboard.ts";
import { font } from "../data/font.ts"; import { font } from "./font.ts";
import { addToContext, evalCode } from "../runtime/runcode.ts"; import { addToContext, evalCode } from "./runcode.ts";
import { clearScreen, fillRect } from "../io/window.ts"; import { clearScreen, fillRect } from "./window.ts";
import { COLOR } from "../data/colors.ts"; import { COLOR } from "./colors.ts";
const lineHeight = 6; const lineHeight = 6;

View File

@ -13,9 +13,6 @@ export const getBuiltins = () => {
return builtins; return builtins;
} }
// deno-lint-ignore no-explicit-any
const AsyncFunction = (async function () {}).constructor as any;
addToContext("eval", eval); addToContext("eval", eval);
const context = new Proxy(G, { const context = new Proxy(G, {
@ -34,18 +31,18 @@ const context = new Proxy(G, {
}, },
}); });
export const runCode = async (code: string) => { export const runCode = (code: string) => {
try { try {
new AsyncFunction(code); new Function(code);
} catch (err) { } catch (err) {
throw err; throw err;
} }
const fn = new AsyncFunction("context", ` const fn = new Function("context", `
with (context) { with (context) {
${code} ${code}
} }
`); `);
return await fn(context); return fn(context);
} }
export const evalCode = (code: string) => { export const evalCode = (code: string) => {

View File

@ -1,5 +1,5 @@
import { getCart } from "./cart.ts"; import { getCart } from "./cart.ts";
import { LinearGrid } from "../util/util.ts"; import { LinearGrid } from "./util.ts";
// import { runCode, addToContext } from "./runcode.ts"; // import { runCode, addToContext } from "./runcode.ts";
// "code" | "spritesheet" | "map" | "sfx" | "patterns" | "fonts" // "code" | "spritesheet" | "map" | "sfx" | "patterns" | "fonts"

View File

@ -1,10 +1,11 @@
import { clearScreen, fillRect } from "../io/window.ts"; import { clearScreen, fillRect } from "./window.ts";
import { drawSprite, drawText, useSpritesheet } from "../runtime/builtins.ts"; import { drawSprite, drawText } from "./builtins.ts";
import { COLOR } from "../data/colors.ts"; import { COLOR } from "./colors.ts";
import { getSpriteSheet, setSheet } from "../io/sheet.ts"; import { getSpriteSheet, setSheet } from "./sheet.ts";
import { mouseClick, mouseHeld, mousePos } from "../io/mouse.ts"; import { mouseClick, mouseHeld, mousePos } from "./mouse.ts";
import { drawTransparentRect, inRect, outlineRect, reGrid } from "../util/util.ts"; import { drawTransparentRect, inRect, outlineRect, reGrid } from "./util.ts";
import { page } from "./viewsheets.ts"; import { page } from "./viewsheets.ts";
import { useSpritesheet } from "./builtins.ts";
const state = { const state = {
selectedSprite: 0, selectedSprite: 0,

View File

@ -1,5 +1,5 @@
import { COLOR } from "../data/colors.ts"; import { COLOR } from "./colors.ts";
import { fillRect, setPixelColor } from "../io/window.ts"; import { fillRect, setPixelColor } from "./window.ts";
export const inRect = (x: number, y: number, rectX: number, rectY: number, rectW: number, rectH: number) => { export const inRect = (x: number, y: number, rectX: number, rectY: number, rectW: number, rectH: number) => {
return ( return (

View File

@ -1,12 +1,12 @@
import { clearScreen, fillRect } from "../io/window.ts"; import { clearScreen, fillRect } from "./window.ts";
import { drawIcon, drawText } from "../runtime/builtins.ts"; import { drawIcon, drawText } from "./builtins.ts";
import { COLOR } from "../data/colors.ts"; import { COLOR } from "./colors.ts";
import { getSheet } from "../io/sheet.ts"; import { getSheet } from "./sheet.ts";
import { mouseClick, mousePos } from "../io/mouse.ts"; import { mouseClick, mousePos } from "./mouse.ts";
import { getCart } from "../io/cart.ts"; import { getCart } from "./cart.ts";
import { font } from "../data/font.ts"; import { font } from "./font.ts";
import { codeIcon, spriteIcon, mapIcon } from "../data/icons.ts"; import { codeIcon, spriteIcon, mapIcon } from "./icons.ts";
import { reGridWithGap } from "../util/util.ts"; import { reGridWithGap } from "./util.ts";
const fontHeight = font.height; const fontHeight = font.height;

View File

@ -2,9 +2,9 @@ import {
createWindow, createWindow,
getProcAddress, getProcAddress,
gl, gl,
} from "../deps.ts"; } from "./deps.ts";
export {mainloop} from "../deps.ts"; export {mainloop} from "./deps.ts";
import { COLOR, palette } from "../data/colors.ts"; import { COLOR, palette } from "./colors.ts";
export const gameWindow = createWindow({ export const gameWindow = createWindow({
title: "Faux", title: "Faux",