diff --git a/src/lib/project-fetcher-hoc.jsx b/src/lib/project-fetcher-hoc.jsx index f70417a764e..d8bd574d1fa 100644 --- a/src/lib/project-fetcher-hoc.jsx +++ b/src/lib/project-fetcher-hoc.jsx @@ -57,6 +57,170 @@ const fetchProjectToken = projectId => { }); }; +function protobufToJson(buffer) { + const message = Project.decode(buffer); + const json = Project.toObject(message); + + const newJson = { + targets: [], + monitors: [], + extensionData: {}, + extensions: json.extensions, + extensionURLs: {}, + meta: { + semver: json.metaSemver, + vm: json.metaVm, + agent: json.metaAgent || "" + }, + customFonts: json.fonts + }; + + for (const target of json.targets) { + let newTarget = { + isStage: target.isStage || false, + name: target.name, + variables: {}, + lists: {}, + broadcasts: {}, + customVars: [], + blocks: {}, + comments: {}, + currentCostume: target.currentCostume, + costumes: [], + sounds: [], + id: target.id, + volume: target.volume, + layerOrder: target.layerOrder, + tempo: target.tempo, + videoTransparency: target.videoTransparency, + videoState: target.videoState, + textToSpeechLanguage: target.textToSpeechLanguage || null, + visible: target.visible, + x: target.x, + y: target.y, + size: target.size, + direction: target.direction, + draggable: target.draggable, + rotationStyle: target.rotationStyle + }; + + if (newTarget.isStage) { + delete newTarget.visible, delete newTarget.size, delete newTarget.direction, delete newTarget.draggable, delete newTarget.rotationStyle; + } + + for (const variable in target.variables) { + newTarget.variables[variable] = [target.variables[variable].name, target.variables[variable].value]; + } + + for (const list in target.lists) { + newTarget.lists[list] = [target.lists[list].name, target.lists[list].value || []]; + } + + for (const broadcast in target.broadcasts) { + newTarget.broadcasts[broadcast] = target.broadcasts[broadcast]; + } + + for (const customVar in target.customVars) { + newTarget.customVars.push(target.customVars[customVar]); + } + + for (const block in target.blocks) { + if (target.blocks[block].is_variable_reporter) { + newTarget.blocks[block] = [ + target.blocks[block].varReporterBlock.first_num, + target.blocks[block].varReporterBlock.name, + target.blocks[block].varReporterBlock.id, + target.blocks[block].varReporterBlock.second_num, + target.blocks[block].varReporterBlock.third_num, + ] + continue; + } + + newTarget.blocks[block] = { + opcode: target.blocks[block].opcode, + next: target.blocks[block].next || null, + parent: target.blocks[block].parent || null, + inputs: {}, + fields: {}, + shadow: target.blocks[block].shadow, + topLevel: target.blocks[block].topLevel, + x: target.blocks[block].x, + y: target.blocks[block].y + } + + if (target.blocks[block].mutation) { + newTarget.blocks[block].mutation = { + tagName: target.blocks[block].mutation.tagName, + proccode: target.blocks[block].mutation.proccode, + argumentids: target.blocks[block].mutation.argumentids, + argumentnames: target.blocks[block].mutation.argumentnames, + argumentdefaults: target.blocks[block].mutation.argumentdefaults, + warp: target.blocks[block].mutation.warp, + returns: target.blocks[block].mutation._returns, + edited: target.blocks[block].mutation.edited, + optype: target.blocks[block].mutation.optype, + color: target.blocks[block].mutation.color, + hasnext: target.blocks[block].next ? true : false, + children: [] + } + } + + for (const input in target.blocks[block].inputs) { + newTarget.blocks[block].inputs[input] = JSON.parse(target.blocks[block].inputs[input]); + } + + for (const field in target.blocks[block].fields) { + newTarget.blocks[block].fields[field] = JSON.parse(target.blocks[block].fields[field]); + } + } + + for (const comment in target.comments) { + newTarget.comments[comment] = target.comments[comment]; + } + + for (const costume in target.costumes) { + newTarget.costumes[costume] = target.costumes[costume]; + } + + for (const sound in target.sounds) { + newTarget.sounds[sound] = target.sounds[sound]; + } + + newJson.targets.push(newTarget); + } + + for (const monitor in json.monitors) { + let newMonitor = { + id: json.monitors[monitor].id, + mode: json.monitors[monitor].mode, + opcode: json.monitors[monitor].opcode, + params: json.monitors[monitor].params, + spriteName: json.monitors[monitor].spriteName || null, + value: json.monitors[monitor].value, + width: json.monitors[monitor].width, + height: json.monitors[monitor].height, + x: json.monitors[monitor].x, + y: json.monitors[monitor].y, + visible: json.monitors[monitor].visible, + sliderMin: json.monitors[monitor].sliderMin, + sliderMax: json.monitors[monitor].sliderMax, + isDiscrete: json.monitors[monitor].isDiscrete + } + + newJson.monitors.push(newMonitor); + } + + for (const extensionData in json.extensionData) { + newJson.extensionData[extensionData] = JSON.parse(json.extensionData[extensionData]); + } + + for (const extensionURL in json.extensionURLs) { + newJson.extensionURLs[extensionURL] = json.extensionURLs[extensionURL]; + } + + return newJson; +} + /* Higher Order Component to provide behavior for loading projects by id. If * there's no id, the default project is loaded. * @param {React.Component} WrappedComponent component to receive projectData prop diff --git a/src/lib/project.protobuf.json b/src/lib/project.protobuf.json new file mode 100644 index 00000000000..41abae47dca --- /dev/null +++ b/src/lib/project.protobuf.json @@ -0,0 +1,1240 @@ +{ + "nested": { + "project": { + "nested": { + "monitor": { + "oneofs": { + "_id": { + "oneof": [ + "id" + ] + }, + "_mode": { + "oneof": [ + "mode" + ] + }, + "_opcode": { + "oneof": [ + "opcode" + ] + }, + "_spriteName": { + "oneof": [ + "spriteName" + ] + }, + "_value": { + "oneof": [ + "value" + ] + }, + "_width": { + "oneof": [ + "width" + ] + }, + "_height": { + "oneof": [ + "height" + ] + }, + "_x": { + "oneof": [ + "x" + ] + }, + "_y": { + "oneof": [ + "y" + ] + }, + "_visible": { + "oneof": [ + "visible" + ] + }, + "_sliderMin": { + "oneof": [ + "sliderMin" + ] + }, + "_sliderMax": { + "oneof": [ + "sliderMax" + ] + }, + "_isDiscrete": { + "oneof": [ + "isDiscrete" + ] + } + }, + "fields": { + "id": { + "type": "string", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "mode": { + "type": "string", + "id": 2, + "options": { + "proto3_optional": true + } + }, + "opcode": { + "type": "string", + "id": 3, + "options": { + "proto3_optional": true + } + }, + "params": { + "keyType": "string", + "type": "string", + "id": 4 + }, + "spriteName": { + "type": "string", + "id": 5, + "options": { + "proto3_optional": true + } + }, + "value": { + "type": "string", + "id": 6, + "options": { + "proto3_optional": true + } + }, + "width": { + "type": "int32", + "id": 7, + "options": { + "proto3_optional": true + } + }, + "height": { + "type": "int32", + "id": 8, + "options": { + "proto3_optional": true + } + }, + "x": { + "type": "int32", + "id": 9, + "options": { + "proto3_optional": true + } + }, + "y": { + "type": "int32", + "id": 10, + "options": { + "proto3_optional": true + } + }, + "visible": { + "type": "bool", + "id": 11, + "options": { + "proto3_optional": true + } + }, + "sliderMin": { + "type": "int32", + "id": 12, + "options": { + "proto3_optional": true + } + }, + "sliderMax": { + "type": "int32", + "id": 13, + "options": { + "proto3_optional": true + } + }, + "isDiscrete": { + "type": "bool", + "id": 14, + "options": { + "proto3_optional": true + } + } + } + }, + "font": { + "oneofs": { + "_system": { + "oneof": [ + "system" + ] + }, + "_family": { + "oneof": [ + "family" + ] + }, + "_fallback": { + "oneof": [ + "fallback" + ] + }, + "_md5ext": { + "oneof": [ + "md5ext" + ] + } + }, + "fields": { + "system": { + "type": "bool", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "family": { + "type": "string", + "id": 2, + "options": { + "proto3_optional": true + } + }, + "fallback": { + "type": "string", + "id": 3, + "options": { + "proto3_optional": true + } + }, + "md5ext": { + "type": "string", + "id": 4, + "options": { + "proto3_optional": true + } + } + } + }, + "Project": { + "oneofs": { + "_metaSemver": { + "oneof": [ + "metaSemver" + ] + }, + "_metaVm": { + "oneof": [ + "metaVm" + ] + }, + "_agent": { + "oneof": [ + "agent" + ] + } + }, + "fields": { + "metaSemver": { + "type": "string", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "metaVm": { + "type": "string", + "id": 2, + "options": { + "proto3_optional": true + } + }, + "agent": { + "type": "string", + "id": 3, + "options": { + "proto3_optional": true + } + }, + "targets": { + "rule": "repeated", + "type": "Sprite.Sprite", + "id": 4 + }, + "monitors": { + "rule": "repeated", + "type": "monitor", + "id": 5 + }, + "extensionData": { + "keyType": "string", + "type": "string", + "id": 6 + }, + "extensions": { + "rule": "repeated", + "type": "string", + "id": 7 + }, + "extensionURLs": { + "keyType": "string", + "type": "string", + "id": 8 + }, + "fonts": { + "rule": "repeated", + "type": "font", + "id": 9 + } + } + } + } + }, + "Sprite": { + "nested": { + "_varValue": { + "oneofs": { + "_name": { + "oneof": [ + "name" + ] + }, + "_value": { + "oneof": [ + "value" + ] + } + }, + "fields": { + "name": { + "type": "string", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "value": { + "type": "string", + "id": 2, + "options": { + "proto3_optional": true + } + } + } + }, + "_listValue": { + "oneofs": { + "_name": { + "oneof": [ + "name" + ] + } + }, + "fields": { + "name": { + "type": "string", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "value": { + "rule": "repeated", + "type": "string", + "id": 2 + } + } + }, + "_mutation": { + "oneofs": { + "_tagName": { + "oneof": [ + "tagName" + ] + }, + "_proccode": { + "oneof": [ + "proccode" + ] + }, + "_argumentids": { + "oneof": [ + "argumentids" + ] + }, + "_argumentnames": { + "oneof": [ + "argumentnames" + ] + }, + "_argumentdefaults": { + "oneof": [ + "argumentdefaults" + ] + }, + "_warp": { + "oneof": [ + "warp" + ] + }, + "__returns": { + "oneof": [ + "_returns" + ] + }, + "_edited": { + "oneof": [ + "edited" + ] + }, + "_optype": { + "oneof": [ + "optype" + ] + }, + "_color": { + "oneof": [ + "color" + ] + } + }, + "fields": { + "tagName": { + "type": "string", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "proccode": { + "type": "string", + "id": 3, + "options": { + "proto3_optional": true + } + }, + "argumentids": { + "type": "string", + "id": 4, + "options": { + "proto3_optional": true + } + }, + "argumentnames": { + "type": "string", + "id": 5, + "options": { + "proto3_optional": true + } + }, + "argumentdefaults": { + "type": "string", + "id": 6, + "options": { + "proto3_optional": true + } + }, + "warp": { + "type": "bool", + "id": 7, + "options": { + "proto3_optional": true + } + }, + "_returns": { + "type": "string", + "id": 8, + "options": { + "proto3_optional": true + } + }, + "edited": { + "type": "bool", + "id": 9, + "options": { + "proto3_optional": true + } + }, + "optype": { + "type": "string", + "id": 10, + "options": { + "proto3_optional": true + } + }, + "color": { + "type": "string", + "id": 11, + "options": { + "proto3_optional": true + } + } + } + }, + "var_reporter_block": { + "oneofs": { + "_first_num": { + "oneof": [ + "first_num" + ] + }, + "_name": { + "oneof": [ + "name" + ] + }, + "_id": { + "oneof": [ + "id" + ] + }, + "_second_num": { + "oneof": [ + "second_num" + ] + }, + "_third_num": { + "oneof": [ + "third_num" + ] + } + }, + "fields": { + "first_num": { + "type": "int32", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "name": { + "type": "string", + "id": 2, + "options": { + "proto3_optional": true + } + }, + "id": { + "type": "string", + "id": 3, + "options": { + "proto3_optional": true + } + }, + "second_num": { + "type": "int32", + "id": 4, + "options": { + "proto3_optional": true + } + }, + "third_num": { + "type": "int32", + "id": 5, + "options": { + "proto3_optional": true + } + } + } + }, + "block": { + "oneofs": { + "_opcode": { + "oneof": [ + "opcode" + ] + }, + "_next": { + "oneof": [ + "next" + ] + }, + "_parent": { + "oneof": [ + "parent" + ] + }, + "_shadow": { + "oneof": [ + "shadow" + ] + }, + "_topLevel": { + "oneof": [ + "topLevel" + ] + }, + "_x": { + "oneof": [ + "x" + ] + }, + "_y": { + "oneof": [ + "y" + ] + }, + "_mutation": { + "oneof": [ + "mutation" + ] + }, + "_varReporterBlock": { + "oneof": [ + "varReporterBlock" + ] + } + }, + "fields": { + "opcode": { + "type": "string", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "next": { + "type": "string", + "id": 2, + "options": { + "proto3_optional": true + } + }, + "parent": { + "type": "string", + "id": 3, + "options": { + "proto3_optional": true + } + }, + "inputs": { + "keyType": "string", + "type": "string", + "id": 4 + }, + "fields": { + "keyType": "string", + "type": "string", + "id": 5 + }, + "shadow": { + "type": "bool", + "id": 6, + "options": { + "proto3_optional": true + } + }, + "topLevel": { + "type": "bool", + "id": 7, + "options": { + "proto3_optional": true + } + }, + "x": { + "type": "int32", + "id": 8, + "options": { + "proto3_optional": true + } + }, + "y": { + "type": "int32", + "id": 9, + "options": { + "proto3_optional": true + } + }, + "mutation": { + "type": "_mutation", + "id": 10, + "options": { + "proto3_optional": true + } + }, + "is_variable_reporter": { + "type": "bool", + "id": 11 + }, + "varReporterBlock": { + "type": "var_reporter_block", + "id": 12, + "options": { + "proto3_optional": true + } + } + } + }, + "comment": { + "oneofs": { + "_blockId": { + "oneof": [ + "blockId" + ] + }, + "_x": { + "oneof": [ + "x" + ] + }, + "_y": { + "oneof": [ + "y" + ] + }, + "_width": { + "oneof": [ + "width" + ] + }, + "_height": { + "oneof": [ + "height" + ] + }, + "_minimized": { + "oneof": [ + "minimized" + ] + }, + "_text": { + "oneof": [ + "text" + ] + } + }, + "fields": { + "blockId": { + "type": "string", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "x": { + "type": "float", + "id": 2, + "options": { + "proto3_optional": true + } + }, + "y": { + "type": "float", + "id": 3, + "options": { + "proto3_optional": true + } + }, + "width": { + "type": "int32", + "id": 4, + "options": { + "proto3_optional": true + } + }, + "height": { + "type": "int32", + "id": 5, + "options": { + "proto3_optional": true + } + }, + "minimized": { + "type": "bool", + "id": 6, + "options": { + "proto3_optional": true + } + }, + "text": { + "type": "string", + "id": 7, + "options": { + "proto3_optional": true + } + } + } + }, + "costume": { + "oneofs": { + "_name": { + "oneof": [ + "name" + ] + }, + "_bitmapResolution": { + "oneof": [ + "bitmapResolution" + ] + }, + "_dataFormat": { + "oneof": [ + "dataFormat" + ] + }, + "_assetId": { + "oneof": [ + "assetId" + ] + }, + "_md5ext": { + "oneof": [ + "md5ext" + ] + }, + "_rotationCenterX": { + "oneof": [ + "rotationCenterX" + ] + }, + "_rotationCenterY": { + "oneof": [ + "rotationCenterY" + ] + } + }, + "fields": { + "name": { + "type": "string", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "bitmapResolution": { + "type": "int32", + "id": 2, + "options": { + "proto3_optional": true + } + }, + "dataFormat": { + "type": "string", + "id": 3, + "options": { + "proto3_optional": true + } + }, + "assetId": { + "type": "string", + "id": 4, + "options": { + "proto3_optional": true + } + }, + "md5ext": { + "type": "string", + "id": 5, + "options": { + "proto3_optional": true + } + }, + "rotationCenterX": { + "type": "double", + "id": 6, + "options": { + "proto3_optional": true + } + }, + "rotationCenterY": { + "type": "double", + "id": 7, + "options": { + "proto3_optional": true + } + } + } + }, + "sound": { + "oneofs": { + "_name": { + "oneof": [ + "name" + ] + }, + "_assetId": { + "oneof": [ + "assetId" + ] + }, + "_dataFormat": { + "oneof": [ + "dataFormat" + ] + }, + "_rate": { + "oneof": [ + "rate" + ] + }, + "_sampleCount": { + "oneof": [ + "sampleCount" + ] + }, + "_md5ext": { + "oneof": [ + "md5ext" + ] + } + }, + "fields": { + "name": { + "type": "string", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "assetId": { + "type": "string", + "id": 2, + "options": { + "proto3_optional": true + } + }, + "dataFormat": { + "type": "string", + "id": 3, + "options": { + "proto3_optional": true + } + }, + "rate": { + "type": "int32", + "id": 4, + "options": { + "proto3_optional": true + } + }, + "sampleCount": { + "type": "int32", + "id": 5, + "options": { + "proto3_optional": true + } + }, + "md5ext": { + "type": "string", + "id": 6, + "options": { + "proto3_optional": true + } + } + } + }, + "customVar": { + "oneofs": { + "_type": { + "oneof": [ + "type" + ] + }, + "_id": { + "oneof": [ + "id" + ] + }, + "_name": { + "oneof": [ + "name" + ] + }, + "_value": { + "oneof": [ + "value" + ] + } + }, + "fields": { + "type": { + "type": "string", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "id": { + "type": "string", + "id": 2, + "options": { + "proto3_optional": true + } + }, + "name": { + "type": "string", + "id": 3, + "options": { + "proto3_optional": true + } + }, + "value": { + "type": "string", + "id": 4, + "options": { + "proto3_optional": true + } + } + } + }, + "Sprite": { + "oneofs": { + "_id": { + "oneof": [ + "id" + ] + }, + "_isStage": { + "oneof": [ + "isStage" + ] + }, + "_name": { + "oneof": [ + "name" + ] + }, + "_currentCostume": { + "oneof": [ + "currentCostume" + ] + }, + "_volume": { + "oneof": [ + "volume" + ] + }, + "_layerOrder": { + "oneof": [ + "layerOrder" + ] + }, + "_x": { + "oneof": [ + "x" + ] + }, + "_y": { + "oneof": [ + "y" + ] + }, + "_size": { + "oneof": [ + "size" + ] + }, + "_direction": { + "oneof": [ + "direction" + ] + }, + "_draggable": { + "oneof": [ + "draggable" + ] + }, + "_rotationStyle": { + "oneof": [ + "rotationStyle" + ] + }, + "_tempo": { + "oneof": [ + "tempo" + ] + }, + "_videoTransparency": { + "oneof": [ + "videoTransparency" + ] + }, + "_videoState": { + "oneof": [ + "videoState" + ] + }, + "_textToSpeechLanguage": { + "oneof": [ + "textToSpeechLanguage" + ] + }, + "_visible": { + "oneof": [ + "visible" + ] + } + }, + "fields": { + "id": { + "type": "string", + "id": 1, + "options": { + "proto3_optional": true + } + }, + "isStage": { + "type": "bool", + "id": 2, + "options": { + "proto3_optional": true + } + }, + "name": { + "type": "string", + "id": 3, + "options": { + "proto3_optional": true + } + }, + "variables": { + "keyType": "string", + "type": "_varValue", + "id": 4 + }, + "lists": { + "keyType": "string", + "type": "_listValue", + "id": 5 + }, + "broadcasts": { + "keyType": "string", + "type": "string", + "id": 6 + }, + "customVars": { + "rule": "repeated", + "type": "customVar", + "id": 7 + }, + "blocks": { + "keyType": "string", + "type": "block", + "id": 8 + }, + "comments": { + "keyType": "string", + "type": "comment", + "id": 9 + }, + "currentCostume": { + "type": "int32", + "id": 10, + "options": { + "proto3_optional": true + } + }, + "costumes": { + "rule": "repeated", + "type": "costume", + "id": 11 + }, + "sounds": { + "rule": "repeated", + "type": "sound", + "id": 12 + }, + "volume": { + "type": "int32", + "id": 13, + "options": { + "proto3_optional": true + } + }, + "layerOrder": { + "type": "int32", + "id": 14, + "options": { + "proto3_optional": true + } + }, + "x": { + "type": "int32", + "id": 15, + "options": { + "proto3_optional": true + } + }, + "y": { + "type": "int32", + "id": 16, + "options": { + "proto3_optional": true + } + }, + "size": { + "type": "int32", + "id": 17, + "options": { + "proto3_optional": true + } + }, + "direction": { + "type": "int32", + "id": 18, + "options": { + "proto3_optional": true + } + }, + "draggable": { + "type": "bool", + "id": 19, + "options": { + "proto3_optional": true + } + }, + "rotationStyle": { + "type": "string", + "id": 20, + "options": { + "proto3_optional": true + } + }, + "tempo": { + "type": "int32", + "id": 21, + "options": { + "proto3_optional": true + } + }, + "videoTransparency": { + "type": "int32", + "id": 22, + "options": { + "proto3_optional": true + } + }, + "videoState": { + "type": "string", + "id": 23, + "options": { + "proto3_optional": true + } + }, + "textToSpeechLanguage": { + "type": "string", + "id": 24, + "options": { + "proto3_optional": true + } + }, + "visible": { + "type": "bool", + "id": 25, + "options": { + "proto3_optional": true + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/playground/render-interface.jsx b/src/playground/render-interface.jsx index b4134ac5ae9..99c53ed283d 100644 --- a/src/playground/render-interface.jsx +++ b/src/playground/render-interface.jsx @@ -306,7 +306,8 @@ class Interface extends React.Component { const projectReleaseYear = extraProjectInfo.releaseDate.getFullYear(); const projectReleaseMonth = monthNames[extraProjectInfo.releaseDate.getMonth()]; const projectReleaseDay = addNumberSuffix(extraProjectInfo.releaseDate.getDate()); - const projectReleaseHour = (extraProjectInfo.releaseDate.getHours() % 12) + 1; + const hour24 = extraProjectInfo.releaseDate.getHours(); + const projectReleaseHour = hour24 === 0 ? 12 : (hour24 > 12 ? hour24 - 12 : hour24); const projectReleaseHalf = extraProjectInfo.releaseDate.getHours() > 11 ? 'PM' : 'AM';