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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v5
with:
cache: npm
node-version-file: .nvmrc
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v5
with:
cache: npm
node-version-file: .nvmrc
Expand Down
59 changes: 58 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function App()
const [windowTitle, setWindowTitle] = useState<string>("Report");



const [charts, setCharts] = useState<{id: string; code: string}[]>([]);


Expand All @@ -58,6 +57,25 @@ function App()
};


const handleAgentInformation = (data: {agent: string, mssg: string}) =>{
console.log("Agent information received", data.agent, data.mssg);
const curReport:AgentInformation = {
mssg: data.mssg,
agent: data.agent,
}
// check if the report'department is already in the list, if yes, update the report; if no, add the report
const index = agentProfiles.findIndex((r) => r.agent === data.agent);
if(index !== -1){
agentProfiles[index] = curReport;
setAgentProfiles([...agentProfiles]);
}else{
agentProfiles.push(curReport);
setAgentProfiles([...agentProfiles]);
}

console.log("agentProfiles", agentProfiles);
}

const handleAgentInformation = (data: {agent: string, mssg: string}) =>{
console.log("Agent information received", data.agent, data.mssg);
const curReport:AgentInformation = {
Expand Down Expand Up @@ -159,6 +177,45 @@ function App()
}



const handleAgentInformationOpen = (data: { agent: string}) => {
const index = agentProfiles.findIndex((r) => r.agent === data.agent);
if(index !== -1){
setCurrentReport(agentProfiles[index].mssg);

marked.use({
extensions: [
{
name: 'highlight',
level: 'inline',
start(src) { return src.indexOf("=="); },
tokenizer(src, tokens) {
const rule = /^==([^=]+)==/;
const match = rule.exec(src);
if (match) {
return {
type: 'highlight',
raw: match[0],
text: match[1],
tokens: this.lexer.inlineTokens(match[1]),
};
}
},
renderer(token: any) {
return `<mark>${marked.parser(token.tokens)}</mark>`;
},
},
],
});

console.log("agentProfiles[index].mssg", agentProfiles[index].mssg);

setHtmlReport(agentProfiles[index].mssg);
if(!isOpen)setIsOpen(true);
}
}


// EventBus.on("d3-code", (data: {d3Code: string, id: string}) => {
// setCharts(prev => [
// ...prev,
Expand Down
4 changes: 3 additions & 1 deletion src/game/assets/sprites/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ export { default as idle_icon } from "./idle_char_icon.png"
export { default as record_icon } from "./record_char_icon.png"
export { default as pdf } from "./pdf.png"
export { default as agent_mssg } from "./agent-mssg.png"

export { default as agent_idle } from "./agent-idle.png"
export { default as final_report } from "./final_report.png"
export { default as final_report } from "./final_report.png"

87 changes: 84 additions & 3 deletions src/game/sprites/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class Agent extends Phaser.Physics.Arcade.Sprite {

public isDrag: boolean = false; // track drag state


// public static biasedAgentsCount: number = 0; // Calculate the current number of biased agents in this level

public static biasedAgentsCount: number = 0; // Current number of "labeled hallucinations"
Expand All @@ -44,6 +45,49 @@ export class Agent extends Phaser.Physics.Arcade.Sprite {
public static currentBiasedAgent: Agent | null = null; // Reservation: pointing to the "last selected"


private agentInformation:string = "aaaaaaa";

public addMssgSprite(scene: Phaser.Scene, texture: string, frame?: string | number) {
if (this.mssgSprite) {
console.log("Updating message sprite for agent:", this.name);
this.mssgSprite.setTexture(texture, frame);

this.mssgSprite.removeAllListeners();
this.mssgSprite.disableInteractive();

if (texture === "agent_mssg") {
this.mssgSprite.setInteractive({ useHandCursor: true });
this.mssgSprite.on('pointerdown', () => {
console.log(`Message sprite of ${this.name} clicked!`);
this.changeNameTagColor('#00ff00');
EventBus.emit("open-agent-information", {
agent: this.name
});
});
}
return;
}

console.log("Adding message sprite to agent:", this.name);
this.mssgSprite = scene.add.image(this.x, this.y, texture, frame)
.setOrigin(0.5, 1)
.setDepth(10);

if (texture === "agent_mssg") {
this.mssgSprite.setInteractive({ useHandCursor: true });
this.mssgSprite.on('pointerdown', () => {
console.log(`Message sprite of ${this.name} clicked!`);
this.changeNameTagColor('#00ff00');
EventBus.emit("open-agent-information", {
agent: this.name
});
});
}
}
public static biasedAgentsCount: number = 0; // Calculate the current number of biased agents in this level



private agentInformation:string = "aaaaaaa";

public addMssgSprite(scene: Phaser.Scene, texture: string, frame?: string | number) {
Expand Down Expand Up @@ -114,6 +158,20 @@ export class Agent extends Phaser.Physics.Arcade.Sprite {
});
}


public getAgentInformation(){
return this.agentInformation;
}

public setAgentInformation(info: string) {
this.agentInformation = info;
EventBus.emit("agent-information", {
agent: this.name,
mssg: this.getAgentInformation()
});
}


public playDialogue(
scene: Phaser.Scene,
text: string,
Expand Down Expand Up @@ -166,14 +224,15 @@ public playDialogue(
}
});

// Make the bubble position always follow Agent

scene.events.on("update", () => {
if (textObj && textObj.active) {
textObj.setPosition(this.x + 40, this.y - 40);
}
});
}


public assignToWorkplace: boolean = false;
private activationFunction: (state: any) => any = (state: any) => {
console.log(`---Step for Agent: ${this.name}---`);
Expand Down Expand Up @@ -399,6 +458,30 @@ update() {
if (oldest && oldest !== this) oldest.setToUnbiased();
this.setToBiased();
}
if (gameObject === this) {
console.log(`Agent ${this.name} clicked!`);

const agentInfo = this.getAgentInformation();
console.log(`Agent Information: ${agentInfo}`);

// If there is already another biased agent, restore it first.
if (Agent.currentBiasedAgent && Agent.currentBiasedAgent !== this) {
Agent.currentBiasedAgent.setToUnbiased();
}

if (!this.isBiased) {
// Set to biased
this.name = "Biased " + this.name;
this.isBiased = true;
this.setTexture(key.atlas.bias);
this.createAnimations(key.atlas.bias);
this.bias = 'biased';
// Agent.biasedAgentsCount = 1;
// Agent.currentBiasedAgent = this;

console.log("Agent is now biased:", this.name);
}
}
}

// Add method to revert to normal agent
Expand Down Expand Up @@ -453,8 +536,6 @@ update() {
}




private createWorkAnimations(atlasKey: string) {
const anims = this.scene.anims;

Expand Down
Loading