All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.uwsoft.editor.renderer.components.LayerMapComponent Maven / Gradle / Ivy

Go to download

overlap2d-runtime-libgdx provides functionality to load, manipulate and render scenes generated by Overlap2D.

The newest version!
package com.uwsoft.editor.renderer.components;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

import com.badlogic.ashley.core.Component;
import com.uwsoft.editor.renderer.data.LayerItemVO;

public class LayerMapComponent implements Component {
	private ArrayList layers = new ArrayList();

	private HashMap layerMap = new HashMap();

	public void setLayers(ArrayList layers) {
		this.layers = layers;
		layerMap.clear();
		for (LayerItemVO vo : layers) {
			layerMap.put(vo.layerName, vo);
		}
	}

	public LayerItemVO getLayer(String name) {
		return layerMap.get(name);
	}

	public int getIndexByName(String name) {
		if(layerMap.containsKey(name)) {
			return layers.indexOf(layerMap.get(name));
		}

		return 0;
	}

	public boolean isVisible(String name) {
		LayerItemVO vo = getLayer(name);
		if (vo != null) {
			return vo.isVisible;
		}

		return true;
	}

	public void addLayer(int index, LayerItemVO layerVo) {
		layers.add(index, layerVo);
		layerMap.put(layerVo.layerName, layerVo);
	}

	public void addLayer(LayerItemVO layerVo) {
		layers.add(layerVo);
		layerMap.put(layerVo.layerName, layerVo);
	}

	public ArrayList getLayers() {
		return layers;
	}

	public void deleteLayer(String layerName) {
		layers.remove(getIndexByName(layerName));
		layerMap.remove(layerName);
	}

	public void rename(String prevName, String newName) {
		LayerItemVO vo = layerMap.get(prevName);
		layerMap.remove(prevName);
		layerMap.put(newName, vo);
	}

	public void swap(String source, String target) {
		LayerItemVO sourceVO = getLayer(source);
		LayerItemVO targetVO = getLayer(target);
		Collections.swap(layers, layers.indexOf(sourceVO), layers.indexOf(targetVO));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy