diff --git a/pocs/petrinaut-hazel/src/main/app.tsx b/pocs/petrinaut-hazel/src/main/app.tsx index 99ec0f9..b6b87de 100644 --- a/pocs/petrinaut-hazel/src/main/app.tsx +++ b/pocs/petrinaut-hazel/src/main/app.tsx @@ -51,14 +51,19 @@ const isValidNetDefinition = ( /** * Converts SimulationState to a 2D array format. * Each step becomes an array of objects with placeId, marking, and placeLabel. + * + * Marking is also converted to a representation of an association list. */ -const simulationStateTo2DArray = ( +const simulationStateToHazelFormat = ( simulationState: SimulationState, ): HazelSimulationState => { return simulationState.map((step) => { return Object.entries(step).map(([placeId, { marking, placeLabel }]) => ({ placeId, - marking, + marking: Object.entries(marking).map(([tokenId, count]) => ({ + 0: tokenId, + 1: count, + })), placeLabel, })); }); @@ -77,7 +82,7 @@ const convertSimulationStateForHazel = ( return undefined; } - return simulationStateTo2DArray(simulationState); + return simulationStateToHazelFormat(simulationState); }; /** @@ -95,8 +100,6 @@ export const App = () => { id, codec: "json", onInit: (value) => { - console.log("Received value", value); - try { const parsedValue = JSON.parse(value); @@ -123,7 +126,6 @@ export const App = () => { const reportSimulationState = useCallback( (simulationState: SimulationState) => { - console.log("Simulation state reported"); setSimulationState(simulationState); setSyntax({ diff --git a/pocs/petrinaut-hazel/src/main/app/use-hazel-integration.ts b/pocs/petrinaut-hazel/src/main/app/use-hazel-integration.ts index 256fa58..cd2da93 100644 --- a/pocs/petrinaut-hazel/src/main/app/use-hazel-integration.ts +++ b/pocs/petrinaut-hazel/src/main/app/use-hazel-integration.ts @@ -1,7 +1,4 @@ -import type { - PetriNetDefinitionObject, - TokenCounts, -} from "@hashintel/petrinaut"; +import type { PetriNetDefinitionObject } from "@hashintel/petrinaut"; import { useCallback, useEffect, useState } from "react"; export type MessageToHazel = @@ -40,7 +37,14 @@ type HazelIntegrationConfig = { }; export type HazelSimulationState = Array< - Array<{ placeId: string; marking: TokenCounts; placeLabel: string }> + Array<{ + placeId: string; + /** + * Marking represented as a association list where the tokenId is the key and the count is the value, represented in the format Hazel expects. + */ + marking: Array<{ 0: string; 1: number }>; + placeLabel: string; + }> >; export type HazelValue = {