remove debug prints, axe testbed-only APIs

This commit is contained in:
Lily Tsuru 2024-07-09 23:50:16 -04:00
parent f720acc738
commit b6b069450d
3 changed files with 103 additions and 119 deletions

View file

@ -13,6 +13,7 @@ function dwAlign(off: number): number {
return ul; return ul;
} }
// animation state (used during animation playback)
class AgentAnimationState { class AgentAnimationState {
char: Agent; char: Agent;
anim: AcsAnimation; anim: AcsAnimation;
@ -40,12 +41,12 @@ class AgentAnimationState {
this.finishCallback(); this.finishCallback();
return; return;
} }
//@ts-ignore //@ts-ignore
this.interval = setTimeout(() => { this.interval = setTimeout(() => {
this.nextFrame(); this.nextFrame();
}, this.anim.frameInfo[this.frameIndex].frameDuration * 10) }, this.anim.frameInfo[this.frameIndex].frameDuration * 10);
} }
} }
export class Agent { export class Agent {
@ -74,11 +75,15 @@ export class Agent {
this.setLoc(); this.setLoc();
this.cnv.addEventListener('mousedown', () => { this.cnv.addEventListener('mousedown', () => {
this.dragging = true; this.dragging = true;
document.addEventListener('mouseup', () => { document.addEventListener(
'mouseup',
() => {
this.dragging = false; this.dragging = false;
}, {once: true}); },
{ once: true }
);
}); });
document.addEventListener('mousemove', e => { document.addEventListener('mousemove', (e) => {
if (!this.dragging) return; if (!this.dragging) return;
this.x += e.movementX; this.x += e.movementX;
this.y += e.movementY; this.y += e.movementY;
@ -94,8 +99,8 @@ export class Agent {
if (this.y < 0) this.y = 0; if (this.y < 0) this.y = 0;
if (this.x > document.documentElement.clientWidth - this.cnv.width) this.x = document.documentElement.clientWidth - this.cnv.width; if (this.x > document.documentElement.clientWidth - this.cnv.width) this.x = document.documentElement.clientWidth - this.cnv.width;
if (this.y > document.documentElement.clientHeight - this.cnv.height) this.y = document.documentElement.clientHeight - this.cnv.height; if (this.y > document.documentElement.clientHeight - this.cnv.height) this.y = document.documentElement.clientHeight - this.cnv.height;
this.cnv.style.top = this.y + "px"; this.cnv.style.top = this.y + 'px';
this.cnv.style.left = this.x + "px"; this.cnv.style.left = this.x + 'px';
} }
renderFrame(frame: AcsAnimationFrameInfo) { renderFrame(frame: AcsAnimationFrameInfo) {
@ -149,8 +154,7 @@ export class Agent {
// add promise versions later. // add promise versions later.
playAnimation(index: number, finishCallback: () => void) { playAnimation(index: number, finishCallback: () => void) {
if(this.animState != null) if (this.animState != null) throw new Error('Cannot play multiple animations at once.');
throw new Error('Cannot play multiple animations at once.');
let animInfo = this.data.animInfo[index]; let animInfo = this.data.animInfo[index];
// Create and start the animation state // Create and start the animation state
@ -163,8 +167,7 @@ export class Agent {
playAnimationByName(name: String, finishCallback: () => void) { playAnimationByName(name: String, finishCallback: () => void) {
let index = this.data.animInfo.findIndex((n) => n.name == name); let index = this.data.animInfo.findIndex((n) => n.name == name);
if(index !== -1) if (index !== -1) this.playAnimation(index, finishCallback);
this.playAnimation(index, finishCallback);
} }
animationFinished() { animationFinished() {
@ -173,16 +176,13 @@ export class Agent {
show() { show() {
this.cnv.style.display = 'block'; this.cnv.style.display = 'block';
this.playAnimationByName("Show", () => {}); this.playAnimationByName('Show', () => {});
} }
hide(remove: boolean = false) { hide(remove: boolean = false) {
this.playAnimationByName("Hide", () => { this.playAnimationByName('Hide', () => {
if(remove) if (remove) this.remove();
this.remove(); else this.cnv.style.display = 'none';
else
this.cnv.style.display = 'none';
}); });
} }
} }

View file

@ -6,19 +6,14 @@ import { AcsAnimationEntry } from './structs/animation.js';
import { AcsImageEntry } from './structs/image.js'; import { AcsImageEntry } from './structs/image.js';
import { Agent } from './agent.js'; import { Agent } from './agent.js';
// Experiment for storing parsed data // Data
export class AcsData { export class AcsData {
characterInfo = new AcsCharacterInfo(); characterInfo = new AcsCharacterInfo();
animInfo: AcsAnimationEntry[] = []; animInfo: AcsAnimationEntry[] = [];
images: AcsImageEntry[] = []; images: AcsImageEntry[] = [];
} }
function logOffset(o: number, name: string) { function agentCharacterParseACS(buffer: BufferStream): AcsData {
let n = o >>> 0;
console.log(name, 'offset:', '0x' + n.toString(16));
}
function agentCharacterParseACS(buffer: BufferStream) {
// Make sure the magic is correct for the ACS file. // Make sure the magic is correct for the ACS file.
if (buffer.readU32LE() != 0xabcdabc3) { if (buffer.readU32LE() != 0xabcdabc3) {
throw new Error('The provided data buffer does not contain valid ACS data.'); throw new Error('The provided data buffer does not contain valid ACS data.');
@ -32,10 +27,6 @@ function agentCharacterParseACS(buffer: BufferStream) {
let imageInfoLocation = LOCATION.read(buffer); let imageInfoLocation = LOCATION.read(buffer);
let audioInfoLocation = LOCATION.read(buffer); let audioInfoLocation = LOCATION.read(buffer);
logOffset(characterInfoLocation.offset, 'character info');
logOffset(animationInfoLocation.offset, 'animation info');
logOffset(imageInfoLocation.offset, 'image info');
logOffset(audioInfoLocation.offset, 'audio info');
buffer.withOffset(characterInfoLocation.offset, () => { buffer.withOffset(characterInfoLocation.offset, () => {
acsData.characterInfo = AcsCharacterInfo.read(buffer); acsData.characterInfo = AcsCharacterInfo.read(buffer);
@ -53,19 +44,12 @@ function agentCharacterParseACS(buffer: BufferStream) {
}); });
}); });
console.log(acsData);
return acsData; return acsData;
} }
// For the testbed code only, remove when that gets axed
// (or don't, I'm not your dad)
export function agentParseCharacterTestbed(buffer: Uint8Array) {
return new Agent(agentCharacterParseACS(new BufferStream(buffer)));
}
// TODO this will be the public API // TODO this will be the public API
// Dunno about maintaining canvases. We can pass a div into agentInit and add a characterInit() which recieves it // Dunno about maintaining canvases. We can pass a div into agentInit and add a characterInit() which recieves it
// (which we then mount characters and their wordballoons into?) // (which we then mount characters and their wordballoons into?)
export function agentCreateCharacter(data: Uint8Array): Promise<void> { export function agentCreateCharacter(data: Uint8Array): Agent {
throw new Error('Not implemented yet'); return new Agent(agentCharacterParseACS(new BufferStream(data)));
} }

View file

@ -8,8 +8,8 @@ let input = document.getElementById("testbed-input") as HTMLInputElement;
input.addEventListener("change", async () => { input.addEventListener("change", async () => {
let buffer = await input.files![0].arrayBuffer(); let buffer = await input.files![0].arrayBuffer();
console.log("About to parse character"); console.log("Creating agent");
let agent = msagent.agentParseCharacterTestbed(new Uint8Array(buffer)); let agent = msagent.agentCreateCharacter(new Uint8Array(buffer));
// destroy the previous agent // destroy the previous agent
if(w.agent != null) { if(w.agent != null) {
@ -20,7 +20,7 @@ input.addEventListener("change", async () => {
agent.addToDom(document.body); agent.addToDom(document.body);
agent.show(); agent.show();
console.log("parsed character"); console.log("Agent created");
}) })
document.addEventListener("DOMContentLoaded", async () => { document.addEventListener("DOMContentLoaded", async () => {