/*
 * Copyright 2014-2015 See AUTHORS file.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.kotcrab.vis.editor.module.project;

import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.ObjectMap;
import com.kotcrab.vis.editor.module.scene.SceneMetadata;

public class SceneMetadataModule extends ProjectModule {
	private FileHandle configFile;

	private Json json;

	private SceneMetadataList metadata;

	@Override
	public void init () {
		json = new Json();

		FileAccessModule fileAccess = projectContainer.get(FileAccessModule.class);

		FileHandle moduleFolder = fileAccess.getModuleFolder(".metadata");
		configFile = moduleFolder.child("sceneMetadata");

		if (configFile.exists())
			metadata = json.fromJson(SceneMetadataList.class, configFile);
		else {
			metadata = new SceneMetadataList();
			metadata.map = new ObjectMap<>();
		}
	}

	@Override
	public void dispose () {
		save();
	}

	public ObjectMap<String, SceneMetadata> getMap () {
		return metadata.map;
	}

	public void save () {
		json.toJson(metadata, configFile);
	}

	public static class SceneMetadataList {
		public ObjectMap<String, SceneMetadata> map;

		public SceneMetadataList () {
		}
	}
}

@@ -763,16 +763,113 @@
 ectMap;%0A
+import com.badlogic.gdx.utils.ObjectMap.Keys;%0Aimport com.kotcrab.vis.editor.module.InjectModule;%0A
 import c
@@ -976,16 +976,61 @@
 odule %7B%0A
+%09@InjectModule FileAccessModule fileAccess;%0A%0A
 %09private
@@ -1041,22 +1041,24 @@
 eHandle 
-config
+metadata
 File;%0A%0A%09
@@ -1321,22 +1321,24 @@
 ta%22);%0A%09%09
-config
+metadata
 File = m
@@ -1380,22 +1380,24 @@
 %0A%0A%09%09if (
-config
+metadata
 File.exi
@@ -1456,22 +1456,24 @@
 .class, 
-config
+metadata
 File);%0A%09
@@ -1555,24 +1555,248 @@
 Map%3C%3E();%0A%09%09%7D
+%0A%0A%09%09//clear not existent scenes%0A%09%09Keys%3CString%3E it = metadata.map.keys().iterator();%0A%09%09while (it.hasNext()) %7B%0A%09%09%09String path = it.next();%0A%0A%09%09%09if(fileAccess.getAssetsFolder().child(path).exists() == false)%0A%09%09%09%09it.remove();%0A%09%09%7D
 %0A%09%7D%0A%0A%09@Overr
@@ -1970,14 +1970,16 @@
 ta, 
-config
+metadata
 File

Clear metadata after project loading