|
|
@@ -1,5 +1,7 @@
|
|
|
import { project } from "./project.js";
|
|
|
import { submission } from "./submission.js";
|
|
|
+import { element } from "./element.js";
|
|
|
+import { exists, is_string } from "./functions.js";
|
|
|
|
|
|
class loader {
|
|
|
#load_from;
|
|
|
@@ -33,13 +35,18 @@ class loader {
|
|
|
}
|
|
|
|
|
|
const content = this.#content;
|
|
|
+
|
|
|
+ if (!exists(content.name)) {
|
|
|
+ content.name = "Unnamed";
|
|
|
+ }
|
|
|
+
|
|
|
const result = new project(content.name);
|
|
|
|
|
|
- if (typeof(content.description) !== "undefined") {
|
|
|
+ if (exists(content.description)) {
|
|
|
result.description = content.description;
|
|
|
}
|
|
|
|
|
|
- if (typeof(content.submissions) === "undefined") {
|
|
|
+ if (!exists(content.submissions)) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -54,12 +61,64 @@ class loader {
|
|
|
|
|
|
result.add(item);
|
|
|
});
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
#prepare_image(url) {
|
|
|
return this.#database + "/" + url;
|
|
|
}
|
|
|
|
|
|
+ #prepare_element(input) {
|
|
|
+ if (exists(input.name)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ const element = new element(input.name);
|
|
|
+
|
|
|
+ if (exists(input.description)) {
|
|
|
+ element.description = input.description;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exists(input.mesh)) {
|
|
|
+ element.mesh = this.#prepare_image(input.mesh);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exists(input.thumbnail)) {
|
|
|
+ element.thumbnail = this.#prepare_image(input.thumbnail);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exists(input.pictures)) {
|
|
|
+ const pictures = Array.from(input.pictures);
|
|
|
+
|
|
|
+ pictures.forEach(picture => {
|
|
|
+ if (!is_string(picture) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ element.pictures.add(this.#prepare_image(picture));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exists(input.params)) {
|
|
|
+ const names = Object.keys(input.params);
|
|
|
+
|
|
|
+ names.forEach(name => {
|
|
|
+ if (!is_string(name) || !is_string(input.params[name])) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ element.params.set(name, input.params[name]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exists(input.shop)) {
|
|
|
+ element.shop = input.shop;
|
|
|
+ }
|
|
|
+
|
|
|
+ return element;
|
|
|
+ }
|
|
|
+
|
|
|
#prepare_one(input) {
|
|
|
if (typeof(input.name) === "undefined") {
|
|
|
return null;
|
|
|
@@ -75,6 +134,20 @@ class loader {
|
|
|
submission.thumbnail = this.#prepare_image(input.thumbnail);
|
|
|
}
|
|
|
|
|
|
+ if (typeof(input.elements) === "undefined") {
|
|
|
+ return submission;
|
|
|
+ }
|
|
|
+
|
|
|
+ const elements = Array.from(input.elements);
|
|
|
+
|
|
|
+ elements.forEach(data => {
|
|
|
+ const element = new this.#prepare_element(data);
|
|
|
+
|
|
|
+ if (element !== null) {
|
|
|
+ submission.add(element);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
return submission;
|
|
|
}
|
|
|
}
|