File tree 2 files changed +46
-2
lines changed
2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -3,13 +3,37 @@ import { Decode } from 'console-feed';
3
3
import { dispatchConsoleEvent } from '../actions/console' ;
4
4
import { stopSketch , expandConsole } from '../actions/ide' ;
5
5
6
+ // Helper function to restore p5.Font objects
7
+ function restoreP5Font ( obj ) {
8
+ if ( obj && obj . _isP5Font ) {
9
+ // Return a simplified font-like object for console display
10
+ return {
11
+ _isP5Font : true ,
12
+ name : obj . name ,
13
+ path : obj . path ,
14
+ face : {
15
+ family : obj . face . family ,
16
+ style : obj . face . style ,
17
+ weight : obj . face . weight
18
+ }
19
+ } ;
20
+ }
21
+ return obj ;
22
+ }
23
+
6
24
export default function useHandleMessageEvent ( ) {
7
25
const dispatch = useDispatch ( ) ;
8
26
9
27
const handleMessageEvent = ( data ) => {
10
28
const { source, messages } = data ;
11
29
if ( source === 'sketch' && Array . isArray ( messages ) ) {
12
- const decodedMessages = messages . map ( ( message ) => Decode ( message . log ) ) ;
30
+ const decodedMessages = messages . map ( ( message ) => {
31
+ const decoded = Decode ( message . log ) ;
32
+ if ( decoded . data ) {
33
+ decoded . data = decoded . data . map ( restoreP5Font ) ;
34
+ }
35
+ return decoded ;
36
+ } ) ;
13
37
decodedMessages . every ( ( message , index , arr ) => {
14
38
const { data : args } = message ;
15
39
let hasInfiniteLoop = false ;
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ function handleMessageEvent(e) {
44
44
const decodedMessages = messages . map ( ( message ) => Decode ( message . log ) ) ;
45
45
decodedMessages . forEach ( ( message ) => {
46
46
const { data : args } = message ;
47
- const { result, error } = evaluateExpression ( args ) ;
47
+ const { result, error } = evaluateExpression ( args . map ( handleP5Font ) ) ;
48
48
const resultMessages = [
49
49
{ log : Encode ( { method : error ? 'error' : 'result' , data : [ result ] } ) }
50
50
] ;
@@ -179,3 +179,23 @@ if (_report) {
179
179
_report . apply ( window . p5 , [ newMessage , method , color ] ) ;
180
180
} ;
181
181
}
182
+
183
+ // Helper function to handle p5.Font objects
184
+ function handleP5Font ( obj ) {
185
+ // Check for p5.Font instances in multiple ways
186
+ const isFontName = obj && obj . constructor && ( obj . constructor . name === 'Font' || obj . constructor . name === 'p5.Font' ) ;
187
+ const isFontInstance = window . p5 && obj instanceof window . p5 . Font ;
188
+ if ( isFontName || isFontInstance ) {
189
+ return {
190
+ _isP5Font : true ,
191
+ name : obj . name ,
192
+ path : obj . path ,
193
+ face : {
194
+ family : obj . face ?. family ,
195
+ style : obj . face ?. style ,
196
+ weight : obj . face ?. weight
197
+ }
198
+ } ;
199
+ }
200
+ return obj ;
201
+ }
You can’t perform that action at this time.
0 commit comments