Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"author": "",
"license": "GPL-3.0",
"devDependencies": {
"@alt1/font-loader": "^1.0.0-alpha.2",
"@alt1/imagedata-loader": "^1.0.0-alpha.2",
"@alt1/font-loader": "^1.0.0-alpha.6",
"@alt1/imagedata-loader": "^1.0.0-alpha.6",
"@alt1/webpack": "^1.0.0-alpha.5",
"@types/autobind-decorator": "^2.1.0",
"@types/classnames": "^2.2.11",
Expand Down
22 changes: 20 additions & 2 deletions src/appframe/alt1api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type * as alt1types from "alt1";
import { ipcRenderer } from "electron";
import { FlatImageData, SyncResponse, OverlayCommand, RsClientState } from "../shared";
import { decodeImageString } from "alt1";

let warningsTriggered: string[] = [];
function warn(key: string, message: string) {
Expand Down Expand Up @@ -141,8 +142,25 @@ var alt1api: Partial<typeof alt1> = {
return alt1.overLayTextEx(text, color, size, x, y, time, "", false, true);
},
overLayImage(x, y, imgstr, imgwidth, time) {
warn("overlayimg", "alt1.overLayImage is not implemented");
return false;
const raw = atob(imgstr);
var height = raw.length / 4 / imgwidth;
if (!Number.isInteger(height)) {
height = Math.floor(height);
if (!Number.isInteger(height)) {
throw new Error("Invalid data or width: height not an int");
}
}
var sprite = new ImageData(imgwidth, height);
decodeImageString(imgstr, sprite, 0, 0, imgwidth, height);
let flatImageData: FlatImageData = {
data: sprite.data,
width: imgwidth,
height: height,
};
if (sprite.height > 0 && sprite.width > 0) {
queueOverlayCommand({ command: "draw", time, action: { type: "sprite", x, y, sprite: flatImageData } });
}
return true;
},
overLaySetGroup(groupid: string) { queueOverlayCommand({ command: "setgroup", groupid }); },
overLaySetGroupZIndex(groupid: string, zindex: number) { queueOverlayCommand({ command: "setgroupzindex", groupid, zindex }); },
Expand Down
2 changes: 1 addition & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function relPath(relpath: string) {

export function patchImageDataShow() {
if (process.env.NODE_ENV === "development") {
(ImageData.prototype.show as any) = function (this: ImageData) { showImageData(this); }
(ImageData.prototype.show as any) = function(this: ImageData) { showImageData(this); }
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/overlayframe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ function redraw(now: number, force = false) {
ctx.textBaseline = act.center ? "middle" : "top";
ctx.fillText(act.text, act.x, act.y);
} else if (act.type == "sprite") {
//TODO
// Check if width and height are valid positive numbers before drawing
if (act.sprite.width > 0 && act.sprite.height > 0) {
const imageData = new ImageData(act.sprite.data, act.sprite.width, act.sprite.height);
ctx.putImageData(imageData, act.x, act.y);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class ManagedSettings extends TypedEmitter<SettingsEvents> {
}


set captureMode(mode: CaptureMode) {
if (!Object.keys(checkSettings.props.captureMode.opts).includes(mode)) {
set captureMode(mode: CaptureMode) {
if (!Object.keys(checkSettings.props.captureMode.opts).includes(mode)) {
console.log("unknown capture mode", mode);
return;
}
Expand All @@ -114,4 +114,4 @@ class ManagedSettings extends TypedEmitter<SettingsEvents> {
}
}

export var settings = new ManagedSettings(configFile);
export var settings = new ManagedSettings(configFile);