Skip to content

Commit

Permalink
Merge pull request #196 from jvfe/fix/issue_132
Browse files Browse the repository at this point in the history
Stop overwriting preload function
  • Loading branch information
berinhard authored Nov 2, 2021
2 parents 147a211 + 45b2950 commit df93918
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Development
- Add `keyIsDown` event to Transcrypt mode - [PR #187](https://github.com/berinhard/pyp5js/pull/187)
- Fix bug with multiple events calls - PR #187 too
- Serve JS files if `--local` flag [PR #195](https://github.com/berinhard/pyp5js/pull/195)
- Fix preload function bug in both modes - [PR #196](https://github.com/berinhard/pyp5js/pull/196)

0.7.0
-----
Expand Down
12 changes: 7 additions & 5 deletions pyp5js/templates/pyodide/target_sketch.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,6 @@ def getURLPath(*args):
def getURLParams(*args):
return _P5_INSTANCE.getURLParams(*args)

def preload(*args):
return _P5_INSTANCE.preload(*args)

def remove(*args):
return _P5_INSTANCE.remove(*args)

Expand Down Expand Up @@ -1565,10 +1562,11 @@ def global_p5_injection(p5_sketch):
return decorator


def start_p5(setup_func, draw_func, event_functions):
def start_p5(preload_func, setup_func, draw_func, event_functions):
"""
This is the entrypoint function. It accepts 2 parameters:

- preload_func: A Python preload callable
- setup_func: a Python setup callable
- draw_func: a Python draw callable
- event_functions: a config dict for the event functions in the format:
Expand All @@ -1581,6 +1579,7 @@ def start_p5(setup_func, draw_func, event_functions):
"""
Callback function called to configure new p5 instance
"""
p5_sketch.preload = global_p5_injection(p5_sketch)(preload_func)
p5_sketch.setup = global_p5_injection(p5_sketch)(setup_func)
p5_sketch.draw = global_p5_injection(p5_sketch)(draw_func)

Expand All @@ -1602,6 +1601,9 @@ def start_p5(setup_func, draw_func, event_functions):
`;

const placeholder = `
def preload():
pass

def setup():
pass

Expand Down Expand Up @@ -1652,7 +1654,7 @@ event_functions = {
"windowResized": windowResized,
}

start_p5(setup, draw, event_functions)
start_p5(preload, setup, draw, event_functions)
`;

function runCode() {
Expand Down
4 changes: 3 additions & 1 deletion pyp5js/templates/transcrypt/pyp5js.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,10 +1189,11 @@ def wrapper():
return decorator


def start_p5(setup_func, draw_func, event_functions):
def start_p5(preload_func, setup_func, draw_func, event_functions):
"""
This is the entrypoint function. It accepts 2 parameters:
- preload_func: a Python preload callable
- setup_func: a Python setup callable
- draw_func: a Python draw callable
- event_functions: a config dict for the event functions in the format:
Expand All @@ -1202,6 +1203,7 @@ def start_p5(setup_func, draw_func, event_functions):
"""

def sketch_setup(p5_sketch):
p5_sketch.preload = global_p5_injection(p5_sketch)(preload_func)
p5_sketch.setup = global_p5_injection(p5_sketch)(setup_func)
p5_sketch.draw = global_p5_injection(p5_sketch)(draw_func)

Expand Down
5 changes: 4 additions & 1 deletion pyp5js/templates/transcrypt/target_sketch.py.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from pyp5js import *

def preload():
pass

def setup():
pass

Expand Down Expand Up @@ -50,4 +53,4 @@ event_functions = {
"keyIsDown": keyIsDown,
}

start_p5(setup, draw, event_functions)
start_p5(preload, setup, draw, event_functions)

0 comments on commit df93918

Please sign in to comment.