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.
50 lines
1.2 KiB
50 lines
1.2 KiB
package com.jotuntech.sketcher.server.command;
|
|
|
|
import java.nio.ByteBuffer;
|
|
import java.util.Deque;
|
|
|
|
import com.jotuntech.sketcher.common.UndoEntry;
|
|
import com.jotuntech.sketcher.common.User;
|
|
import com.jotuntech.sketcher.server.Command;
|
|
import com.jotuntech.sketcher.server.Connection;
|
|
import com.jotuntech.sketcher.server.Server;
|
|
|
|
public class MergeCommand implements Command {
|
|
|
|
public int perform(Server server, Connection connection) {
|
|
User user = connection.getUser();
|
|
|
|
if(user == null || user.getLayer() == null) {
|
|
return Connection.SEND_NONE;
|
|
}
|
|
|
|
if(user.isViewer()) {
|
|
return Connection.SEND_NONE;
|
|
}
|
|
|
|
if(user.getPhantomLayer().isEmpty()) {
|
|
return Connection.SEND_NONE;
|
|
}
|
|
|
|
UndoEntry undoEntry = new UndoEntry();
|
|
undoEntry.setLayer(user.getLayer());
|
|
undoEntry.setUndoData(user.getLayer().merge(user.getPhantomLayer()));
|
|
Deque<UndoEntry> undoDeque = user.getUndoDeque();
|
|
undoDeque.addFirst(undoEntry);
|
|
while(undoDeque.size() > 10) {
|
|
undoDeque.removeLast();
|
|
}
|
|
|
|
server.setMergeDirty(null);
|
|
|
|
return Connection.SEND_OTHERS;
|
|
}
|
|
|
|
public void decode(ByteBuffer in) {
|
|
|
|
}
|
|
|
|
public void encode(ByteBuffer out) {
|
|
|
|
}
|
|
}
|
|
|