Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera event changes #63

Merged
merged 2 commits into from
Sep 24, 2024
Merged
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
3 changes: 3 additions & 0 deletions src/engine/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const EventEmitter = require('events');

const Cast = require('../util/cast');
const MathUtil = require('../util/math-util');
const Runtime = require('./engine/runtime');

/**
* @fileoverview
Expand Down Expand Up @@ -120,6 +121,8 @@ class Camera extends EventEmitter {
this.zoom
);

this.runtime.emit(Runtime.CAMERA_UPDATE, this);

this.runtime.requestRedraw();
}

Expand Down
21 changes: 2 additions & 19 deletions src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class VirtualMachine extends EventEmitter {
this.runtime.on(Runtime.VISUAL_REPORT, visualReport => {
this.emit(Runtime.VISUAL_REPORT, visualReport);
});
this.runtime.on(Runtime.CAMERA_UPDATE, emitProjectChanged => {
this.emitCameraUpdate(emitProjectChanged);
this.runtime.on(Runtime.CAMERA_UPDATE, cameraState => {
this.emit(Runtime.CAMERA_UPDATE, cameraState);
});
this.runtime.on(Runtime.TARGETS_UPDATE, emitProjectChanged => {
this.emitTargetsUpdate(emitProjectChanged);
Expand Down Expand Up @@ -1667,23 +1667,6 @@ class VirtualMachine extends EventEmitter {
}
}

/**
* Emit metadata about the camera instance.
* An editor UI could use this to display information about the camera.
* @param {bool} triggerProjectChange If true, also emit a project changed event.
* Disabled selectively by updates that don't affect project serialization.
* Defaults to true.
*/
emitCameraUpdate (triggerProjectChange) {
if (typeof triggerProjectChange === 'undefined') triggerProjectChange = true;
this.emit('cameraUpdate', {
camera: this.runtime.camera
});
if (triggerProjectChange) {
this.runtime.emitProjectChanged();
}
}

/**
* Emit an Blockly/scratch-blocks compatible XML representation
* of the current editing target's blocks.
Expand Down
Loading