Load edit page from storage. Fixe remove bug in edit

This commit is contained in:
Thibault Neveu
2018-06-15 16:35:30 +01:00
parent 19105d4314
commit 9e16c49a46
6 changed files with 45 additions and 28 deletions
+3 -3
View File
File diff suppressed because one or more lines are too long
+11 -4
View File
@@ -1,8 +1,15 @@
// Get the url of the desired level
let levelUrl = metacar.level.level0;
// Create the editor (canvasID, levelUrl)
var editor = new metacar.editor("editor", levelUrl);
// Get the url of the desired level
let levelToLoad = metacar.level.level0;
// If a level is avaiable in the storage, load this level instead.
var levelObject = localStorage.getItem('mylevel.json');
if (levelObject){
levelToLoad = JSON.parse(levelObject);
}
// Create the editor (canvasID, levelUrl)
var editor = new metacar.editor("editor", levelToLoad);
editor.load().then(() => {
editor.addEvent("save", (content) => {
console.log(content);
+3 -3
View File
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -97,7 +97,8 @@ export class Editor extends World {
this.app.stage.removeChild(item.lidar);
}
if (item.mapId == MAP.CAR){
item.road.cars.splice(item.road.cars.indexOf(item.car_id), 1);
if (item.road)
item.road.cars.splice(item.road.cars.indexOf(item.carId), 1);
}
if (item.agent)
this.agent = undefined;
-1
View File
@@ -52,7 +52,6 @@ export class MetaCar {
public load(): Promise<void>{
return new Promise((resolve, reject) => {
console.log(typeof this.levelToLoad, this.levelToLoad);
if (typeof this.levelToLoad == "string"){
U.loadCustomURL(<string>this.levelToLoad, (content: LevelInfo) => {
this.level = new Level(content, this.canvasId);
+26 -16
View File
@@ -10,24 +10,22 @@ export class MetaCarEditor {
private agent: any;
private level: Editor;
private canvasId: string;
private levelUrl: string;
private levelToLoad: string|Object;
private event: UIEvent;
private eventList: string[] = ["save"]
private eventCallback: any[];
constructor(canvasId: string, levelUrl: string) {
/**
* @canvasId: HTML canvas ID to used
* @level: URL or Local storage URL.
* localstorage://level-name
* embedded://
* http(s)://
*/
if (!canvasId || this.levelUrl){
console.error("You must specify the canvasId and the levelUrl");
/**
* @canvasId: HTML canvas ID
* @levelToLoad: URL of the level or directly the level's object.
* URL format: embedded://... or http(s)://...
*/
constructor(canvasId: string, levelToLoad: string) {
if (!canvasId || this.levelToLoad){
console.error("You must specify the canvasId and the levelToLoad");
}
this.canvasId = canvasId;
this.levelUrl = levelUrl;
this.levelToLoad = levelToLoad;
}
public load(level: string, agent: any): Promise<void>{
@@ -37,8 +35,21 @@ export class MetaCarEditor {
@agent (Agent class)
*/
return new Promise((resolve, reject) => {
U.loadCustomURL(this.levelUrl, (content: LevelInfo) => {
this.level = new Editor(content, this.canvasId);
if (typeof this.levelToLoad == "string"){
U.loadCustomURL(<string>this.levelToLoad, (content: LevelInfo) => {
this.level = new Editor(content, this.canvasId);
this.level.load((delta: number) => this.loop(delta));
this.event = new UIEvent(this.level, this.canvasId);
this.event.createEditorElementsEvents();
this.eventCallback = [
(fc: any, options: eventEditorLoadOptions) => this.event.onSaveEditor(fc, options)
];
resolve();
});
}
else{
this.level = new Editor(<LevelInfo>this.levelToLoad, this.canvasId);
this.level.load((delta: number) => this.loop(delta));
this.event = new UIEvent(this.level, this.canvasId);
this.event.createEditorElementsEvents();
@@ -46,9 +57,8 @@ export class MetaCarEditor {
this.eventCallback = [
(fc: any, options: eventEditorLoadOptions) => this.event.onSaveEditor(fc, options)
];
resolve();
});
}
});
}