package model;

import com.jme.util.export.InputCapsule;
import com.jme.util.export.JMEExporter;
import com.jme.util.export.JMEImporter;
import com.jme.util.export.OutputCapsule;
import com.jme.util.export.Savable;
import java.io.IOException;

/**
 * 
 */
public class Sensor implements Savable{

    double x, y;
    Material3D material;
    Thing thing;

    public Sensor(){ //Savable matters only!

    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }


    public Material3D getMaterial() {
        if (thing != null) {
            return thing.getMaterial();
        } else {
            //System.out.println("====  thing is null ======");
            return null;
        }
    }

    public void setX(double x) {
        this.x = x;
    }

    public void setY(double y) {
        this.y = y;
    }
    //public void setMaterial(Material3D material) { this.material = material; }

    public void setThing(Thing th) {
        thing = th;
    }

    public Thing getThing() {
        return thing;
    }

    public void write(JMEExporter jmee) throws IOException {
        OutputCapsule capsule = jmee.getCapsule(this);
        capsule.write(x, "x", 0);
        capsule.write(y, "y", 0);
        capsule.write(material, "material", null);
        capsule.write(thing, "thing", null);

    }

    public void read(JMEImporter jmei) throws IOException {
        InputCapsule ic = jmei.getCapsule(this);
        x = ic.readDouble("x", 0);
        y = ic.readDouble("y", 0);
        material = (Material3D) ic.readSavable("material", null);
        thing = (Thing) ic.readSavable("thing", null);
    }

     public Class getClassTag() {
        return this.getClass();
    }
}
