Skip to content

Commit

Permalink
serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyMakesThings committed Oct 9, 2024
1 parent 7baee58 commit 97438c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/serialization/sb3.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ const serializeTarget = function (target, extensions) {
obj.currentCostume = target.currentCostume;
obj.costumes = target.costumes.map(serializeCostume);
obj.sounds = target.sounds.map(serializeSound);
obj.sceneStates = target.sceneStates;
if (Object.prototype.hasOwnProperty.call(target, 'volume')) obj.volume = target.volume;
if (Object.prototype.hasOwnProperty.call(target, 'layerOrder')) obj.layerOrder = target.layerOrder;
if (obj.isStage) { // Only the stage should have these properties
Expand Down Expand Up @@ -787,6 +788,14 @@ const serialize = function (runtime, targetId, {allowOptimization = true} = {})
obj.customFonts = fonts;
}

const scene = runtime.scene;
const scenes = runtime.scenes;

if (scene) {
obj.scene = scene;
obj.scenes = scenes;
}

// Assemble metadata
const meta = Object.create(null);
meta.semver = '3.0.0';
Expand Down Expand Up @@ -1323,6 +1332,9 @@ const parseScratchObject = function (object, runtime, extensions, zip, assets) {
if (Object.prototype.hasOwnProperty.call(object, 'extensionStorage')) {
target.extensionStorage = object.extensionStorage;
}
if (Object.prototype.hasOwnProperty.call(object, 'sceneStates')) {
target.sceneStates = object.sceneStates;
}
Promise.all(costumePromises).then(costumes => {
sprite.costumes = costumes;
});
Expand Down Expand Up @@ -1557,6 +1569,13 @@ const deserialize = async function (json, runtime, zip, isSingleSprite) {
}
}

console.log(json);

if (json.scene) {
runtime.scene = json.scene;
runtime.scenes = json.scenes;
}

// Extract any custom fonts before loading costumes.
let fontPromise;
if (json.customFonts) {
Expand Down
1 change: 1 addition & 0 deletions src/sprites/rendered-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ class RenderedTarget extends Target {
variables: this.variables,
costumes: costumes,
sounds: this.getSounds(),
sceneStates: this.sceneStates,
textToSpeechLanguage: this.textToSpeechLanguage,
tempo: this.tempo,
volume: this.volume,
Expand Down

0 comments on commit 97438c5

Please sign in to comment.