soiz1 commited on
Commit
bae4d64
·
verified ·
1 Parent(s): 479eba4

Update src/lib/project-fetcher-hoc.jsx

Browse files
Files changed (1) hide show
  1. src/lib/project-fetcher-hoc.jsx +3 -182
src/lib/project-fetcher-hoc.jsx CHANGED
@@ -3,12 +3,8 @@ import PropTypes from 'prop-types';
3
  import { intlShape, injectIntl } from 'react-intl';
4
  import bindAll from 'lodash.bindall';
5
  import { connect } from 'react-redux';
6
- import protobufBundle from './project.protobuf.json';
7
- import protobuf from 'protobufjs';
8
  import JSZip from 'jszip';
9
-
10
- let protoRoot = protobuf.Root.fromJSON(protobufBundle);
11
- let Project = protoRoot.lookupType('project.Project');
12
 
13
  import { setProjectUnchanged } from '../reducers/project-changed';
14
  import {
@@ -63,179 +59,6 @@ const fetchProjectToken = projectId => {
63
  });
64
  };
65
 
66
- function protobufToJson(buffer) {
67
- const message = Project.decode(buffer);
68
- const json = Project.toObject(message);
69
-
70
- const newJson = {
71
- targets: [],
72
- monitors: [],
73
- extensionData: {},
74
- extensions: json.extensions,
75
- extensionURLs: {},
76
- meta: {
77
- semver: json.metaSemver,
78
- vm: json.metaVm,
79
- agent: json.metaAgent || ""
80
- },
81
- customFonts: json.fonts
82
- };
83
-
84
- for (const target of json.targets) {
85
- let newTarget = {
86
- isStage: target.isStage || false,
87
- name: target.name,
88
- variables: {},
89
- lists: {},
90
- broadcasts: {},
91
- customVars: [],
92
- blocks: {},
93
- comments: {},
94
- currentCostume: target.currentCostume,
95
- costumes: [],
96
- sounds: [],
97
- id: target.id,
98
- volume: target.volume,
99
- layerOrder: target.layerOrder,
100
- tempo: target.tempo,
101
- videoTransparency: target.videoTransparency,
102
- videoState: target.videoState,
103
- textToSpeechLanguage: target.textToSpeechLanguage || null,
104
- visible: target.visible,
105
- x: target.x,
106
- y: target.y,
107
- size: target.size,
108
- direction: target.direction,
109
- draggable: target.draggable,
110
- rotationStyle: target.rotationStyle
111
- };
112
-
113
- if (newTarget.isStage) {
114
- delete newTarget.visible, delete newTarget.size, delete newTarget.direction, delete newTarget.draggable, delete newTarget.rotationStyle;
115
- }
116
-
117
- for (const variable in target.variables) {
118
- newTarget.variables[variable] = [target.variables[variable].name, target.variables[variable].value];
119
- }
120
-
121
- for (const list in target.lists) {
122
- newTarget.lists[list] = [target.lists[list].name, target.lists[list].value || []];
123
- }
124
-
125
- for (const broadcast in target.broadcasts) {
126
- newTarget.broadcasts[broadcast] = target.broadcasts[broadcast];
127
- }
128
-
129
- for (const customVar in target.customVars) {
130
- newTarget.customVars.push(target.customVars[customVar]);
131
- }
132
-
133
- for (const block in target.blocks) {
134
- if (target.blocks[block].is_variable_reporter) {
135
- newTarget.blocks[block] = [
136
- target.blocks[block].varReporterBlock.first_num,
137
- target.blocks[block].varReporterBlock.name,
138
- target.blocks[block].varReporterBlock.id,
139
- target.blocks[block].varReporterBlock.second_num,
140
- target.blocks[block].varReporterBlock.third_num,
141
- ]
142
- continue;
143
- }
144
-
145
- newTarget.blocks[block] = {
146
- opcode: target.blocks[block].opcode,
147
- next: target.blocks[block].next || null,
148
- parent: target.blocks[block].parent || null,
149
- inputs: {},
150
- fields: {},
151
- shadow: target.blocks[block].shadow,
152
- topLevel: target.blocks[block].topLevel,
153
- x: target.blocks[block].x,
154
- y: target.blocks[block].y
155
- }
156
-
157
- if (target.blocks[block].mutation) {
158
- newTarget.blocks[block].mutation = {
159
- tagName: target.blocks[block].mutation.tagName,
160
- proccode: target.blocks[block].mutation.proccode,
161
- argumentids: target.blocks[block].mutation.argumentids,
162
- argumentnames: target.blocks[block].mutation.argumentnames,
163
- argumentdefaults: target.blocks[block].mutation.argumentdefaults,
164
- warp: target.blocks[block].mutation.warp,
165
- returns: target.blocks[block].mutation._returns,
166
- edited: target.blocks[block].mutation.edited,
167
- optype: target.blocks[block].mutation.optype,
168
- color: target.blocks[block].mutation.color,
169
- hasnext: target.blocks[block].next ? true : false,
170
- children: []
171
- }
172
- }
173
-
174
- for (const input in target.blocks[block].inputs) {
175
- newTarget.blocks[block].inputs[input] = JSON.parse(target.blocks[block].inputs[input]);
176
- }
177
-
178
- for (const field in target.blocks[block].fields) {
179
- newTarget.blocks[block].fields[field] = JSON.parse(target.blocks[block].fields[field]);
180
- }
181
- }
182
-
183
- for (const comment in target.comments) {
184
- newTarget.comments[comment] = target.comments[comment];
185
- }
186
-
187
- for (const costume in target.costumes) {
188
- newTarget.costumes[costume] = target.costumes[costume];
189
- }
190
-
191
- for (const sound in target.sounds) {
192
- newTarget.sounds[sound] = target.sounds[sound];
193
- }
194
-
195
- newJson.targets.push(newTarget);
196
- }
197
-
198
- for (const monitor in json.monitors) {
199
- let newMonitor = {
200
- id: json.monitors[monitor].id,
201
- mode: json.monitors[monitor].mode,
202
- opcode: json.monitors[monitor].opcode,
203
- params: json.monitors[monitor].params,
204
- spriteName: json.monitors[monitor].spriteName || null,
205
- value: json.monitors[monitor].value,
206
- width: json.monitors[monitor].width,
207
- height: json.monitors[monitor].height,
208
- x: json.monitors[monitor].x,
209
- y: json.monitors[monitor].y,
210
- visible: json.monitors[monitor].visible,
211
- sliderMin: json.monitors[monitor].sliderMin,
212
- sliderMax: json.monitors[monitor].sliderMax,
213
- isDiscrete: json.monitors[monitor].isDiscrete
214
- }
215
-
216
- newJson.monitors.push(newMonitor);
217
- }
218
-
219
- for (const extensionData in json.antiSigmaExtensionData) {
220
- // "legacy" shit
221
- newJson.extensionData[extensionData] = json.antiSigmaExtensionData[extensionData];
222
- }
223
-
224
- for (const extensionData in json.extensionData) {
225
- if (json.extensionData[extensionData].parse) {
226
- newJson.extensionData[extensionData] = JSON.parse(json.extensionData[extensionData].data);
227
- } else {
228
- newJson.extensionData[extensionData] = json.extensionData[extensionData].data;
229
- }
230
- }
231
-
232
- for (const extensionURL in json.extensionURLs) {
233
- newJson.extensionURLs[extensionURL] = json.extensionURLs[extensionURL];
234
- }
235
-
236
- return newJson;
237
- }
238
-
239
  /* Higher Order Component to provide behavior for loading projects by id. If
240
  * there's no id, the default project is loaded.
241
  * @param {React.Component} WrappedComponent component to receive projectData prop
@@ -302,7 +125,6 @@ const ProjectFetcherHOC = function (WrappedComponent) {
302
  }
303
  assetPromise = progressMonitor.fetchWithProgress(projectUrl)
304
  .then(r => {
305
- this.props.vm.runtime.renderer.setPrivateSkinAccess(false);
306
  if (this.props.vm.runtime.renderer?.setPrivateSkinAccess)
307
  this.props.vm.runtime.renderer.setPrivateSkinAccess(false);
308
  if (!r.ok) {
@@ -317,12 +139,11 @@ const ProjectFetcherHOC = function (WrappedComponent) {
317
  storage.setProjectToken(projectId);
318
  assetPromise = storage.load(storage.AssetType.Project, projectId, storage.DataFormat.JSON);
319
  } else {
320
- projectUrl = `https://projects.penguinmod.com/api/v1/projects/getprojectwrapper?safe=true&projectId=${projectId}`
321
  assetPromise = progressMonitor.fetchWithProgress(projectUrl)
322
  .then(async r => {
323
  if (this.props.vm.runtime.renderer?.setPrivateSkinAccess)
324
  this.props.vm.runtime.renderer.setPrivateSkinAccess(false);
325
- this.props.vm.runtime.renderer.setPrivateSkinAccess(false);
326
  if (!r.ok) {
327
  throw new Error(`Request returned status ${r.status}`);
328
  }
@@ -481,4 +302,4 @@ const ProjectFetcherHOC = function (WrappedComponent) {
481
 
482
  export {
483
  ProjectFetcherHOC as default
484
- };
 
3
  import { intlShape, injectIntl } from 'react-intl';
4
  import bindAll from 'lodash.bindall';
5
  import { connect } from 'react-redux';
 
 
6
  import JSZip from 'jszip';
7
+ import { protobufToJson } from 'pmp-protobuf'
 
 
8
 
9
  import { setProjectUnchanged } from '../reducers/project-changed';
10
  import {
 
59
  });
60
  };
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  /* Higher Order Component to provide behavior for loading projects by id. If
63
  * there's no id, the default project is loaded.
64
  * @param {React.Component} WrappedComponent component to receive projectData prop
 
125
  }
126
  assetPromise = progressMonitor.fetchWithProgress(projectUrl)
127
  .then(r => {
 
128
  if (this.props.vm.runtime.renderer?.setPrivateSkinAccess)
129
  this.props.vm.runtime.renderer.setPrivateSkinAccess(false);
130
  if (!r.ok) {
 
139
  storage.setProjectToken(projectId);
140
  assetPromise = storage.load(storage.AssetType.Project, projectId, storage.DataFormat.JSON);
141
  } else {
142
+ projectUrl = `https://projects.penguinmod.com/api/v1/projects/getprojectwrapper?safe=true&projectId=${projectId}`;
143
  assetPromise = progressMonitor.fetchWithProgress(projectUrl)
144
  .then(async r => {
145
  if (this.props.vm.runtime.renderer?.setPrivateSkinAccess)
146
  this.props.vm.runtime.renderer.setPrivateSkinAccess(false);
 
147
  if (!r.ok) {
148
  throw new Error(`Request returned status ${r.status}`);
149
  }
 
302
 
303
  export {
304
  ProjectFetcherHOC as default
305
+ };