dev/prometeuc-improvements (#5)
Co-authored-by: Nilton Constantino <nilton.constantino@visma.com> Reviewed-on: #5
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "@prometeu/sdk",
|
||||
"version": "0.1.0",
|
||||
"main": "src/index.ts",
|
||||
"types": "types/index.d.ts"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export const Audio = audio;
|
||||
export type Audio = Prometeu.Audio;
|
||||
@@ -0,0 +1,25 @@
|
||||
export type Color565 = Prometeu.Color565;
|
||||
|
||||
function clamp8(n: number): number {
|
||||
return n < 0 ? 0 : n > 255 ? 255 : n | 0;
|
||||
}
|
||||
|
||||
export const Color: Prometeu.Color = {
|
||||
black: 0x0000 as Color565,
|
||||
white: 0xffff as Color565,
|
||||
red: 0xf800 as Color565,
|
||||
green: 0x07e0 as Color565,
|
||||
blue: 0x001f as Color565,
|
||||
yellow: 0xffe0 as Color565,
|
||||
cyan: 0x07ff as Color565,
|
||||
magenta: 0xf81f as Color565,
|
||||
indigo: 0x4810 as Color565,
|
||||
|
||||
rgb(r: number, g: number, b: number): Color565 {
|
||||
r = clamp8(r); g = clamp8(g); b = clamp8(b);
|
||||
const r5 = (r >> 3) & 0x1f;
|
||||
const g6 = (g >> 2) & 0x3f;
|
||||
const b5 = (b >> 3) & 0x1f;
|
||||
return ((r5 << 11) | (g6 << 5) | b5) as Color565;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export const Fs = fs;
|
||||
export type Fs = Prometeu.Fs;
|
||||
@@ -0,0 +1 @@
|
||||
export type Gfx = Prometeu.Gfx;
|
||||
@@ -0,0 +1,8 @@
|
||||
export { Color } from "./color";
|
||||
export { Pad, Touch } from "./input";
|
||||
export { Gfx } from "./gfx";
|
||||
export { System } from "./system";
|
||||
export { Audio } from "./audio";
|
||||
export { Fs } from "./fs";
|
||||
export { Log, LogLevel } from "./log";
|
||||
export type { Color565 } from "./color";
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
|
||||
export const Pad: Prometeu.Pad = pad;
|
||||
export const Touch: Prometeu.Touch = touch;
|
||||
@@ -0,0 +1,11 @@
|
||||
export const Log = log;
|
||||
export type Log = Prometeu.Log;
|
||||
|
||||
export enum LogLevel {
|
||||
Trace = 0,
|
||||
Debug = 1,
|
||||
Info = 2,
|
||||
Warn = 3,
|
||||
Error = 4,
|
||||
Fatal = 5,
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export const System = system;
|
||||
export type System = Prometeu.System;
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
export {}; // that is a module, should not include any other scope here
|
||||
|
||||
declare global {
|
||||
namespace Prometeu {
|
||||
type Color565 = number & { readonly __brand: "Color565" };
|
||||
|
||||
interface Button {
|
||||
readonly down: boolean;
|
||||
readonly pressed: boolean;
|
||||
readonly released: boolean;
|
||||
readonly holdFrames: number;
|
||||
}
|
||||
|
||||
interface Pad {
|
||||
readonly up: Button;
|
||||
readonly down: Button;
|
||||
readonly left: Button;
|
||||
readonly right: Button;
|
||||
readonly a: Button;
|
||||
readonly b: Button;
|
||||
readonly x: Button;
|
||||
readonly y: Button;
|
||||
readonly l: Button;
|
||||
readonly r: Button;
|
||||
readonly start: Button;
|
||||
readonly select: Button;
|
||||
}
|
||||
|
||||
interface Touch {
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
readonly button: Button;
|
||||
}
|
||||
|
||||
interface Gfx {
|
||||
fillRect(x: number, y: number, w: number, h: number, color: Color565): void;
|
||||
drawLine(x1: number, y1: number, x2: number, y2: number, color: Color565): void;
|
||||
drawCircle(x: number, y: number, r: number, color: Color565): void;
|
||||
drawDisc(x: number, y: number, r: number, borderColor: Color565, fillColor: Color565): void;
|
||||
drawSquare(x: number, y: number, w: number, h: number, borderColor: Color565, fillColor: Color565): void;
|
||||
clear(color: Color565): void;
|
||||
}
|
||||
|
||||
interface Color {
|
||||
readonly black: Color565;
|
||||
readonly white: Color565;
|
||||
readonly red: Color565;
|
||||
readonly green: Color565;
|
||||
readonly blue: Color565;
|
||||
readonly yellow: Color565;
|
||||
readonly cyan: Color565;
|
||||
readonly magenta: Color565;
|
||||
readonly indigo: Color565;
|
||||
readonly color_key: Color565;
|
||||
readonly orange: Color565;
|
||||
readonly gray: Color565;
|
||||
readonly grey: Color565;
|
||||
rgb(r: number, g: number, b: number): Color565;
|
||||
}
|
||||
|
||||
interface System {
|
||||
hasCart(): boolean;
|
||||
}
|
||||
|
||||
interface Audio {
|
||||
playSample(sampleId: number, voiceId: number, volume: number, pan: number, pitch: number): void;
|
||||
}
|
||||
|
||||
interface Fs {
|
||||
open(path: string): number;
|
||||
read(handle: number): string | null;
|
||||
write(handle: number, content: string): boolean;
|
||||
close(handle: number): void;
|
||||
listDir(path: string): string | null;
|
||||
exists(path: string): boolean;
|
||||
delete(path: string): boolean;
|
||||
}
|
||||
|
||||
interface Log {
|
||||
write(level: number, msg: string): void;
|
||||
writeTag(level: number, tag: number, msg: string): void;
|
||||
}
|
||||
}
|
||||
|
||||
export const pad: Prometeu.Pad;
|
||||
export const touch: Prometeu.Touch;
|
||||
export const gfx: Prometeu.Gfx;
|
||||
export const audio: Prometeu.Audio;
|
||||
export const fs: Prometeu.Fs;
|
||||
export const log: Prometeu.Log;
|
||||
export const color: Prometeu.Color;
|
||||
export const system: Prometeu.System;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user