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;
}
// animation state (used during animation playback)
class AgentAnimationState {
char: Agent;
anim: AcsAnimation;
@ -40,12 +41,12 @@ class AgentAnimationState {
this.finishCallback();
return;
}
//@ts-ignore
this.interval = setTimeout(() => {
this.nextFrame();
}, this.anim.frameInfo[this.frameIndex].frameDuration * 10)
}, this.anim.frameInfo[this.frameIndex].frameDuration * 10);
}
}
export class Agent {
@ -74,11 +75,15 @@ export class Agent {
this.setLoc();
this.cnv.addEventListener('mousedown', () => {
this.dragging = true;
document.addEventListener('mouseup', () => {
document.addEventListener(
'mouseup',
() => {
this.dragging = false;
}, {once: true});
},
{ once: true }
);
});
document.addEventListener('mousemove', e => {
document.addEventListener('mousemove', (e) => {
if (!this.dragging) return;
this.x += e.movementX;
this.y += e.movementY;
@ -94,8 +99,8 @@ export class Agent {
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.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.left = this.x + "px";
this.cnv.style.top = this.y + 'px';
this.cnv.style.left = this.x + 'px';
}
renderFrame(frame: AcsAnimationFrameInfo) {
@ -149,8 +154,7 @@ export class Agent {
// add promise versions later.
playAnimation(index: number, finishCallback: () => void) {
if(this.animState != null)
throw new Error('Cannot play multiple animations at once.');
if (this.animState != null) throw new Error('Cannot play multiple animations at once.');
let animInfo = this.data.animInfo[index];
// Create and start the animation state
@ -163,8 +167,7 @@ export class Agent {
playAnimationByName(name: String, finishCallback: () => void) {
let index = this.data.animInfo.findIndex((n) => n.name == name);
if(index !== -1)
this.playAnimation(index, finishCallback);
if (index !== -1) this.playAnimation(index, finishCallback);
}
animationFinished() {
@ -173,16 +176,13 @@ export class Agent {
show() {
this.cnv.style.display = 'block';
this.playAnimationByName("Show", () => {});
this.playAnimationByName('Show', () => {});
}
hide(remove: boolean = false) {
this.playAnimationByName("Hide", () => {
if(remove)
this.remove();
else
this.cnv.style.display = 'none';
this.playAnimationByName('Hide', () => {
if (remove) this.remove();
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 { Agent } from './agent.js';
// Experiment for storing parsed data
// Data
export class AcsData {
characterInfo = new AcsCharacterInfo();
animInfo: AcsAnimationEntry[] = [];
images: AcsImageEntry[] = [];
}
function logOffset(o: number, name: string) {
let n = o >>> 0;
console.log(name, 'offset:', '0x' + n.toString(16));
}
function agentCharacterParseACS(buffer: BufferStream) {
function agentCharacterParseACS(buffer: BufferStream): AcsData {
// Make sure the magic is correct for the ACS file.
if (buffer.readU32LE() != 0xabcdabc3) {
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 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, () => {
acsData.characterInfo = AcsCharacterInfo.read(buffer);
@ -53,19 +44,12 @@ function agentCharacterParseACS(buffer: BufferStream) {
});
});
console.log(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
// 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?)
export function agentCreateCharacter(data: Uint8Array): Promise<void> {
throw new Error('Not implemented yet');
export function agentCreateCharacter(data: Uint8Array): Agent {
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 () => {
let buffer = await input.files![0].arrayBuffer();
console.log("About to parse character");
let agent = msagent.agentParseCharacterTestbed(new Uint8Array(buffer));
console.log("Creating agent");
let agent = msagent.agentCreateCharacter(new Uint8Array(buffer));
// destroy the previous agent
if(w.agent != null) {
@ -20,7 +20,7 @@ input.addEventListener("change", async () => {
agent.addToDom(document.body);
agent.show();
console.log("parsed character");
console.log("Agent created");
})
document.addEventListener("DOMContentLoaded", async () => {