+ Added Catch Command
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import utils.ImageOverlayBuilder;
|
||||
import utils.ImageUtils;
|
||||
|
||||
public class CommandCatch extends Command
|
||||
{
|
||||
// Required constructor
|
||||
public CommandCatch(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
private static Long num = 0l;
|
||||
|
||||
@Override
|
||||
public String HelpText() { return LocStrings.Stub("CatchInfo"); }
|
||||
|
||||
// Called when the command is run!
|
||||
@Override
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String name = null;
|
||||
File catchFile = null;
|
||||
File catcheeFile = null;
|
||||
|
||||
synchronized(num)
|
||||
{
|
||||
name = "catch_" + num + ".gif";
|
||||
++num;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
KittyUser person = null;
|
||||
|
||||
if(input.mentions == null)
|
||||
person = user;
|
||||
else
|
||||
person = input.mentions[0];
|
||||
|
||||
String catchFilename = ImageUtils.DownloadFromURL(person.avatarID, ".png");
|
||||
if(catchFilename == null)
|
||||
return;
|
||||
|
||||
catcheeFile = new File(catchFilename);
|
||||
ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/catch/frames/", "catch ", 92, 18);
|
||||
builder.Overlay(ImageIO.read(catcheeFile), name);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
catchFile = new File (name);
|
||||
res.CallFile(catchFile, "gif");
|
||||
|
||||
// Thread cleanup...
|
||||
ImageUtils.BlockingFileDelete(catchFile);
|
||||
ImageUtils.BlockingFileDelete(catcheeFile);
|
||||
}
|
||||
}
|
||||
@@ -375,6 +375,7 @@ public class ObjectBuilderFactory
|
||||
manager.Register(LocCommands.Stub("tony, stark, dontfeelgood, dontfeelsogood"), new CommandStark(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("blur"), new CommandBlurry(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("eightball, 8ball"), new CommandEightBall(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("catch"), new CommandCatch(KittyRole.General, KittyRating.Safe));
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.awt.image.RenderedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Iterator;
|
||||
import javax.imageio.IIOException;
|
||||
@@ -80,24 +81,32 @@ public class ImageOverlayBuilder
|
||||
// Processing the image frames to construct a gif. Relies on (0,255,0) pixel for image center specification.
|
||||
private void ProcessOverlay(BufferedImage overlay, String outfileName) throws IOException
|
||||
{
|
||||
BufferedImage[] frames = new BufferedImage[frameCount];
|
||||
|
||||
ArrayList<BufferedImage> frames = new ArrayList<BufferedImage>(frameCount);
|
||||
//BufferedImage[] frames = new BufferedImage[frameCount];
|
||||
|
||||
for(int i = 0; i < frameCount; ++i)
|
||||
{
|
||||
BufferedImage out = CombineImages(basePath + baseName + i + FRAME_FILE_EXTENSION , overlay);
|
||||
|
||||
if(out != null)
|
||||
frames[i] = out;
|
||||
frames.add(out);// = out;
|
||||
else
|
||||
Error("There was an issue with overlaying frame " + i);
|
||||
Warn("Skipping frame " + i + " of base " + basePath + baseName);
|
||||
}
|
||||
|
||||
Verbose("Processed " + frameCount + " frames, writing...");
|
||||
if(frames.isEmpty())
|
||||
{
|
||||
Error("No frames were found at all, so the gif could not be made!");
|
||||
return;
|
||||
}
|
||||
|
||||
Verbose("Processed " + frameCount + " frames, found " + frames.size() + " valid, writing...");
|
||||
ImageOutputStream output = new FileImageOutputStream(new File(outfileName));
|
||||
GifSequenceWriter writer = new GifSequenceWriter(output, frames[0].getType(), fps, true);
|
||||
|
||||
for(int i = 0; i < frameCount; ++i)
|
||||
writer.writeToSequence(frames[i]);
|
||||
GifSequenceWriter writer = new GifSequenceWriter(output, frames.get(0).getType(), fps, true);
|
||||
|
||||
Iterator<BufferedImage> buffIter = frames.iterator();
|
||||
while(buffIter.hasNext())
|
||||
writer.writeToSequence(buffIter.next());
|
||||
|
||||
writer.close();
|
||||
output.close();
|
||||
@@ -112,7 +121,11 @@ public class ImageOverlayBuilder
|
||||
BufferedImage imageBase = null;
|
||||
BufferedImage imageOverlay = overlay;
|
||||
|
||||
imageBase = ImageIO.read(new File(pathBase));
|
||||
File potentialImage = new File(pathBase);
|
||||
if(!potentialImage.exists())
|
||||
return null;
|
||||
|
||||
imageBase = ImageIO.read(potentialImage);
|
||||
|
||||
// Grab data we know won't change. As a side note, I discovered you can get specific pixels a bit
|
||||
// differently later, but it was too late, I wrote the pixel specific code already.
|
||||
|
||||
Reference in New Issue
Block a user