Sketcher2 source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.4 KiB

package com.jotuntech.sketcher.client.command;
import java.nio.ByteBuffer;
import com.jotuntech.sketcher.client.Client;
import com.jotuntech.sketcher.client.Command;
import com.jotuntech.sketcher.client.Connection;
import com.jotuntech.sketcher.common.Canvas;
import com.jotuntech.sketcher.common.Layer;
import com.jotuntech.sketcher.common.User;
public class LayerDataCommand implements Command {
int layerKey;
boolean phantom;
byte[] data;
public LayerDataCommand() {
}
public LayerDataCommand(int layerKey, boolean phantom, byte[] data) {
this.layerKey = layerKey;
this.phantom = phantom;
this.data = data;
}
public int perform(Client client, User user) {
Canvas canvas = client.getCanvas();
if(canvas == null) {
return Connection.SEND_NONE;
}
Layer layer;
if(phantom) {
if(user == null) {
return Connection.SEND_NONE;
}
layer = user.getPhantomLayer();
} else {
layer = canvas.getLayerMap().get(layerKey);
if(layer == null) {
return Connection.SEND_NONE;
}
}
layer.decode(data);
return Connection.SEND_NONE;
}
public void decode(ByteBuffer in) {
layerKey = in.getInt();
phantom = in.get() != 0;
data = new byte[in.remaining()];
in.get(data);
}
public void encode(ByteBuffer out) {
out.putInt(layerKey);
out.put((byte) (phantom ? 0xFF : 0x00));
out.put(data);
}
}