Skip to content

Commit

Permalink
2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dituon committed May 30, 2022
1 parent 8f10d5a commit 1e17d65
Show file tree
Hide file tree
Showing 30 changed files with 788 additions and 372 deletions.
Binary file added res/petpet/Nanomachine son/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/petpet/Nanomachine son/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/petpet/Nanomachine son/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/petpet/Nanomachine son/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/petpet/Nanomachine son/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/petpet/Nanomachine son/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/petpet/Nanomachine son/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/petpet/Nanomachine son/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions res/petpet/Nanomachine son/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{

"type": "GIF",
"avatar": "DOUBLE",
"pos": [
[
[90, 60, 70, 70],[88, 58, 70, 70],[80, 56, 70, 70],[70, 65, 70, 70],
[90, 98, 70, 70],[70, 102, 70, 70],[65, 120, 70, 70],[85, 85, 70, 70]
],[
[260, 5, 70, 70],[257, 0, 70, 70],[250, -10, 70, 70],[257, 0, 70, 70],
[260, 5, 70, 70],[257, 0, 70, 70],[260, 10, 70, 70],[270, 10, 70, 70]
]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": true
}
14 changes: 14 additions & 0 deletions res/petpet/bite/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": "GIF",
"avatar": "SINGLE",
"pos": [
[90, 90, 105, 150], [90, 83, 96, 172], [90, 90, 106, 148],
[88, 88, 97, 167], [90, 85, 89, 179], [90, 90, 106, 151],
[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": false
}
12 changes: 12 additions & 0 deletions res/petpet/hammer/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "GIF",
"avatar": "SINGLE",
"pos": [
[62, 143, 158, 113], [52, 177, 173, 105], [42, 192, 192, 92], [46, 182, 184, 100],
[54, 169, 174, 110], [69, 128, 144, 135], [65, 130, 152, 124]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": false
}
18 changes: 18 additions & 0 deletions res/petpet/kiss/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "GIF",
"avatar": "DOUBLE",
"pos": [
[ [92, 64, 40, 40], [135, 40, 40, 40], [84, 105, 40, 40], [80, 110, 40, 40],
[155, 82, 40, 40], [60, 96, 40, 40], [50, 80, 40, 40], [98, 55, 40, 40],
[35, 65, 40, 40], [38, 100, 40, 40], [70, 80, 40, 40], [84, 65, 40, 40],
[75, 65, 40, 40]],
[[58, 90, 50, 50], [62, 95, 50, 50], [42, 100, 50, 50], [50, 100, 50, 50],
[56, 100, 50, 50], [18, 120, 50, 50], [28, 110, 50, 50], [54, 100, 50, 50],
[46, 100, 50, 50], [60, 100, 50, 50], [35, 115, 50, 50], [20, 120, 50, 50],
[40, 96, 50, 50]]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": true
}
12 changes: 12 additions & 0 deletions res/petpet/knock/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "GIF",
"avatar": "SINGLE",
"pos": [
[60, 308, 210, 195], [60, 308, 210, 198], [45, 330, 250, 172], [58, 320, 218, 180],
[60, 310, 215, 193], [40, 320, 250, 285], [48, 308, 226, 192], [51, 301, 223, 200]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": false
}
12 changes: 12 additions & 0 deletions res/petpet/petpet/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{

"type": "GIF",
"avatar": "SINGLE",
"pos": [
[14, 20, 98, 98], [12, 33, 101, 85], [8, 40, 110, 76], [10, 33, 102, 84], [12, 20, 98, 98]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": false
}
18 changes: 18 additions & 0 deletions res/petpet/play/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{

"type": "GIF",
"avatar": "SINGLE",
"pos": [
[180, 60, 100, 100], [184, 75, 100, 100], [183, 98, 100, 100],
[179, 118, 110, 100], [156, 194, 150, 48], [178, 136, 122, 69],
[175, 66, 122, 85], [170, 42, 130, 96], [175, 34, 118, 95],
[179, 35, 110, 93], [180, 54, 102, 93], [183, 58, 97, 92],
[174, 35, 120, 94], [179, 35, 109, 93], [181, 54, 101, 92],
[182, 59, 98, 92], [183, 71, 90, 96], [180, 131, 92, 101],
[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": false
}
13 changes: 13 additions & 0 deletions res/petpet/pound/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{

"type": "GIF",
"avatar": "SINGLE",
"pos": [
[135, 240, 138, 47], [135, 240, 138, 47], [150, 190, 105, 95], [150, 190, 105, 95],
[148, 188, 106, 98], [146, 196, 110, 88], [145, 223, 112, 61], [145, 223, 112, 61]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": false
}
13 changes: 13 additions & 0 deletions res/petpet/roll/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{

"type": "GIF",
"avatar": "SINGLE",
"pos": [
[87, 77, 220, 220], [96, 85, 220, 220], [92, 79, 220, 220], [92, 78, 220, 220],
[92, 75, 220, 220], [92, 75, 220, 220], [93, 76, 220, 220], [90, 80, 220, 220]
],
"text": "",
"round": true,
"rotate": true,
"avatarOnTop": false
}
15 changes: 15 additions & 0 deletions res/petpet/rub/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{

"type": "GIF",
"avatar": "DOUBLE",
"pos": [
[[102, 95, 70, 80], [108, 60, 50, 100], [97, 18, 65, 95],
[65, 5, 75, 75], [95, 57, 100, 55], [109, 107, 65, 75]],
[[39, 91, 75, 75], [49, 101, 75, 75], [67, 98, 75, 75],
[55, 86, 75, 75], [61, 109, 75, 75], [65, 101, 75, 75]]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": true
}
14 changes: 14 additions & 0 deletions res/petpet/suck/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{

"type": "GIF",
"avatar": "SINGLE",
"pos": [
[82, 100, 130, 119], [82, 94, 126, 125], [82, 120, 128, 99], [81, 164, 132, 55],
[79, 163, 132, 55], [82, 140, 127, 79], [83, 152, 125, 67], [75, 157, 140, 62],
[72, 165, 144, 54], [80, 132, 128, 87], [81, 127, 127, 92], [79, 111, 132, 108]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": false
}
15 changes: 15 additions & 0 deletions res/petpet/throw/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{

"type": "GIF",
"avatar": "DOUBLE",
"pos": [
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
[289, 70, 33, 33], [280, 73, 32, 32], [259, 31, 35, 35], [-50, 220, 175, 175]],
[[108, 36, 32, 32], [122, 36, 32, 32], [0, 0, 0, 0], [19, 129, 123, 123],
[-50, 200, 185, 185], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": true
}
11 changes: 11 additions & 0 deletions res/petpet/thump/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "GIF",
"avatar": "SINGLE",
"pos": [
[65, 128, 77, 72], [67, 128, 73, 72], [54, 139, 94, 61], [57, 135, 86, 65]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": false
}
14 changes: 14 additions & 0 deletions res/petpet/tightly/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": "GIF",
"avatar": "SINGLE",
"pos": [
[39, 169, 267, 141], [40, 167, 264, 143], [38, 174, 270, 135], [40, 167, 264, 143], [38, 174, 270, 135],
[40, 167, 264, 143], [38, 174, 270, 135], [40, 167, 264, 143], [38, 174, 270, 135], [28, 176, 293, 134],
[5, 215, 333, 96], [10, 210, 321, 102], [3, 210, 330, 104], [4, 210, 328, 102], [4, 212, 328, 100],
[4, 212, 328, 100], [4, 212, 328, 100], [4, 212, 328, 100], [4, 212, 328, 100], [29, 195, 285, 120]
],
"text": "",
"round": true,
"rotate": false,
"avatarOnTop": false
}
12 changes: 12 additions & 0 deletions res/petpet/twist/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "GIF",
"avatar": "SINGLE",
"pos": [
[25, 66, 80, 80], [25, 66, 80, 80], [23, 68, 80, 80],
[20, 69, 80, 80], [22, 68, 80, 80]
],
"text": "",
"round": true,
"rotate": true,
"avatarOnTop": false
}
22 changes: 21 additions & 1 deletion src/main/java/xmmt/dituon/ConfigJSON.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@ package xmmt.dituon

import kotlinx.serialization.*
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray

@Serializable
data class ConfigJSON(
val command: String, val probability: Int, val antialias: Boolean
val version: Float, val command: String, val probability: Int, val antialias: Boolean,
val disabled: JsonArray, val resPath: String
)

fun decode(str: String): ConfigJSON {
return Json.decodeFromString(str)
}

enum class Type {
GIF, IMG
}

enum class Avatar {
SINGLE , DOUBLE
}

@Serializable
data class DataJSON(
val type: Type, val avatar: Avatar, val pos: JsonArray, val text: String ,
val round: Boolean, val rotate: Boolean, val avatarOnTop: Boolean
)

fun getData(str: String): DataJSON{
return Json.decodeFromString(str)
}
101 changes: 101 additions & 0 deletions src/main/java/xmmt/dituon/GifBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package xmmt.dituon;

import javax.imageio.*;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageOutputStream;
import java.awt.image.RenderedImage;
import java.io.*;

public class GifBuilder {

protected ImageWriter writer;
protected ImageWriteParam params;
protected IIOMetadata metadata;
protected ImageOutputStream image;
protected InputStream output;

public GifBuilder(int imageType, int delay, boolean loop) throws IOException {
writer = ImageIO.getImageWritersBySuffix("gif").next();
params = writer.getDefaultWriteParam();

ImageTypeSpecifier imageTypeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(imageType);
metadata = writer.getDefaultImageMetadata(imageTypeSpecifier, params);

configureRootMetadata(delay, loop);

ByteArrayOutputStream os = new ByteArrayOutputStream();
image = ImageIO.createImageOutputStream(os);
writer.setOutput(image);
writer.prepareWriteSequence(null);
}

public byte[] getBytes(ImageOutputStream ios) {
ByteArrayOutputStream bos = new ByteArrayOutputStream(255);
try {
ios.seek(0);
} catch (IOException e1) {
e1.printStackTrace();
}

while (true) {
try {
bos.write(ios.readByte());
} catch (EOFException e) {
break;
} catch (IOException e) {
System.out.println("Error processing the Image Stream");
break;
}
}
return bos.toByteArray();
}

private void configureRootMetadata(int delay, boolean loop) throws IIOInvalidTreeException {
String metaFormatName = metadata.getNativeMetadataFormatName();
IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(metaFormatName);

IIOMetadataNode graphicsControlExtensionNode = getNode(root, "GraphicControlExtension");
graphicsControlExtensionNode.setAttribute("disposalMethod", "none");
graphicsControlExtensionNode.setAttribute("userInputFlag", "FALSE");
graphicsControlExtensionNode.setAttribute("transparentColorFlag", "FALSE");
graphicsControlExtensionNode.setAttribute("delayTime", Integer.toString(delay / 10));
graphicsControlExtensionNode.setAttribute("transparentColorIndex", "0");

IIOMetadataNode appExtensionsNode = getNode(root, "ApplicationExtensions");
IIOMetadataNode child = new IIOMetadataNode("ApplicationExtension");
child.setAttribute("applicationID", "NETSCAPE");
child.setAttribute("authenticationCode", "2.0");

int loopContinuously = loop ? 0 : 1;
child.setUserObject(new byte[]{ 0x1, (byte) (loopContinuously & 0xFF), (byte) (0)});
appExtensionsNode.appendChild(child);
metadata.setFromTree(metaFormatName, root);
}

private static IIOMetadataNode getNode(IIOMetadataNode rootNode, String nodeName){
int nNodes = rootNode.getLength();
for (int i = 0; i < nNodes; i++){
if (rootNode.item(i).getNodeName().equalsIgnoreCase(nodeName)){
return (IIOMetadataNode) rootNode.item(i);
}
}
IIOMetadataNode node = new IIOMetadataNode(nodeName);
rootNode.appendChild(node);
return(node);
}

public void writeToSequence(RenderedImage img) throws IOException {
writer.writeToSequence(new IIOImage(img, null, metadata), params);
}

public InputStream getOutput(){
return output;
}

public void close() throws IOException {
writer.endWriteSequence();
output = new ByteArrayInputStream(getBytes(image));
}
}
Loading

0 comments on commit 1e17d65

Please sign in to comment.