mirror of
https://github.com/wassname/metacar.git
synced 2026-09-09 11:26:47 +08:00
Load edit page from storage. Fixe remove bug in edit
This commit is contained in:
Vendored
+3
-3
File diff suppressed because one or more lines are too long
@@ -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);
|
||||
|
||||
Vendored
+3
-3
File diff suppressed because one or more lines are too long
+2
-1
@@ -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;
|
||||
|
||||
@@ -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
@@ -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();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user