merged texture packs
This commit is contained in:
parent
47db5ab389
commit
5c6c134bd9
Binary file not shown.
37842
javascript/classes.js
37842
javascript/classes.js
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -10,9 +10,7 @@
|
|||
- backported 1.8's double buffering
|
||||
- backported 1.8's FXAA shader
|
||||
|
||||
Release date: §9MM/DD/YYYY§r
|
||||
|
||||
Time spent: §9~5 days§r
|
||||
Release date: §910/27/2023§r
|
||||
|
||||
§0Made §0by §4lax1dude§r
|
||||
|
||||
|
|
|
@ -517,6 +517,7 @@ texturePack.openFolder=Open texture pack folder
|
|||
texturePack.title=Select Texture Pack
|
||||
texturePack.folderInfo=(Place texture pack files here)
|
||||
texturePack.incompatible=Incompatible
|
||||
texturePack.wannaDelete=Do you want to delete this texture pack?
|
||||
|
||||
book.pageIndicator=Page %1$s of %2$s
|
||||
book.byAuthor=by %1$s
|
||||
|
|
|
@ -1225,16 +1225,22 @@ public class EaglerAdapterImpl2 {
|
|||
yee.setDialogTitle("select a file");
|
||||
yee.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
yee.setMultiSelectionEnabled(false);
|
||||
|
||||
String[] exts = ext.split(",.");
|
||||
yee.setFileFilter(new FileFilter() {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return ext+" files";
|
||||
return String.join("/", exts)+" files";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
return f.isDirectory() || f.getName().endsWith("."+ext);
|
||||
if (f.isDirectory()) return true;
|
||||
for (String e : exts) {
|
||||
if (f.getName().endsWith("."+e)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if(yee.showOpenDialog(eagler) == JFileChooser.APPROVE_OPTION) {
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package net.lax1dude.eaglercraft.adapter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class SimpleStorage {
|
||||
private static final Path directory;
|
||||
private static final boolean available = true;
|
||||
|
||||
public static boolean isAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
static {
|
||||
File file = new File("eagstorage");
|
||||
file.mkdirs();
|
||||
directory = file.toPath().toAbsolutePath();
|
||||
}
|
||||
|
||||
public static byte[] get(String key) {
|
||||
try {
|
||||
return Files.readAllBytes(directory.resolve(key));
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean set(String key, byte[] value) {
|
||||
try {
|
||||
if (value == null) {
|
||||
Files.deleteIfExists(directory.resolve(key));
|
||||
} else {
|
||||
Files.write(directory.resolve(key), value);
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
} catch (IOException e) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] list() {
|
||||
try {
|
||||
return Files.list(directory).map(Path::getFileName).toArray(String[]::new);
|
||||
} catch (IOException e) {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ import org.json.JSONObject;
|
|||
public class AssetRepository {
|
||||
|
||||
private static final HashMap<String,byte[]> filePool = new HashMap();
|
||||
private static final HashMap<String,byte[]> filePoolTemp = new HashMap();
|
||||
public static final HashMap<String, String> fileNameOverrides = new HashMap();
|
||||
|
||||
public static final void loadOverrides(JSONObject json) {
|
||||
|
@ -34,7 +35,33 @@ public class AssetRepository {
|
|||
}
|
||||
}
|
||||
|
||||
private static byte[] def = null;
|
||||
|
||||
public static final void reset() throws IOException {
|
||||
if (def != null) {
|
||||
filePool.clear();
|
||||
install(def);
|
||||
}
|
||||
}
|
||||
|
||||
public static final void installTemp(byte[] pkg) throws IOException {
|
||||
filePoolTemp.clear();
|
||||
filePoolTemp.putAll(filePool);
|
||||
reset();
|
||||
install(pkg);
|
||||
}
|
||||
|
||||
public static final void resetTemp() throws IOException {
|
||||
filePool.clear();
|
||||
filePool.putAll(filePoolTemp);
|
||||
filePoolTemp.clear();
|
||||
}
|
||||
|
||||
public static final void install(byte[] pkg) throws IOException {
|
||||
if (def == null) {
|
||||
def = pkg;
|
||||
}
|
||||
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(pkg);
|
||||
|
||||
byte[] header = new byte[8];
|
||||
|
|
151
src/main/java/net/lax1dude/eaglercraft/EPK2Compiler.java
Normal file
151
src/main/java/net/lax1dude/eaglercraft/EPK2Compiler.java
Normal file
|
@ -0,0 +1,151 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
|
||||
import com.jcraft.jzlib.CRC32;
|
||||
|
||||
public class EPK2Compiler {
|
||||
|
||||
private final ByteArrayOutputStream os;
|
||||
private final CRC32 checkSum = new CRC32();
|
||||
private int lengthIntegerOffset = 0;
|
||||
private int totalFileCount = 0;
|
||||
|
||||
public EPK2Compiler() {
|
||||
String name = "__TEXTUREPACK__";
|
||||
String owner = "__INTERNAL__";
|
||||
String type = "epk/resources";
|
||||
os = new ByteArrayOutputStream(0x200000);
|
||||
try {
|
||||
|
||||
os.write(new byte[]{(byte)69,(byte)65,(byte)71,(byte)80,(byte)75,(byte)71,(byte)36,(byte)36}); // EAGPKG$$
|
||||
os.write(new byte[]{(byte)6,(byte)118,(byte)101,(byte)114,(byte)50,(byte)46,(byte)48}); // 6 + ver2.0
|
||||
Date d = new Date();
|
||||
|
||||
byte[] filename = (name + ".epk").getBytes(StandardCharsets.UTF_8);
|
||||
os.write(filename.length);
|
||||
os.write(filename);
|
||||
|
||||
byte[] comment = ("\n\n # Eagler EPK v2.0\n\n")
|
||||
.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
os.write((comment.length >> 8) & 255);
|
||||
os.write(comment.length & 255);
|
||||
os.write(comment);
|
||||
|
||||
writeLong(d.getTime(), os);
|
||||
|
||||
lengthIntegerOffset = os.size();
|
||||
os.write(new byte[]{(byte)255,(byte)255,(byte)255,(byte)255}); // this will be replaced with the file count
|
||||
|
||||
os.write('0'); // compression type: none
|
||||
|
||||
os.write(new byte[]{(byte)72,(byte)69,(byte)65,(byte)68}); // HEAD
|
||||
os.write(new byte[]{(byte)9,(byte)102,(byte)105,(byte)108,(byte)101,(byte)45,(byte)116,(byte)121,
|
||||
(byte)112,(byte)101}); // 9 + file-type
|
||||
|
||||
byte[] typeBytes = type.getBytes(StandardCharsets.UTF_8);
|
||||
writeInt(typeBytes.length, os);
|
||||
os.write(typeBytes); // write type
|
||||
os.write('>');
|
||||
|
||||
++totalFileCount;
|
||||
|
||||
os.write(new byte[]{(byte)72,(byte)69,(byte)65,(byte)68}); // HEAD
|
||||
os.write(new byte[]{(byte)10,(byte)119,(byte)111,(byte)114,(byte)108,(byte)100,(byte)45,(byte)110,
|
||||
(byte)97,(byte)109,(byte)101}); // 10 + name
|
||||
|
||||
byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8);
|
||||
writeInt(nameBytes.length, os);
|
||||
os.write(nameBytes); // write name
|
||||
os.write('>');
|
||||
|
||||
++totalFileCount;
|
||||
|
||||
os.write(new byte[]{(byte)72,(byte)69,(byte)65,(byte)68}); // HEAD
|
||||
os.write(new byte[]{(byte)11,(byte)119,(byte)111,(byte)114,(byte)108,(byte)100,(byte)45,(byte)111,
|
||||
(byte)119,(byte)110,(byte)101,(byte)114}); // 11 + owner
|
||||
|
||||
byte[] ownerBytes = owner.getBytes(StandardCharsets.UTF_8);
|
||||
writeInt(ownerBytes.length, os);
|
||||
os.write(ownerBytes); // write owner
|
||||
os.write('>');
|
||||
|
||||
++totalFileCount;
|
||||
|
||||
}catch(IOException ex) {
|
||||
throw new RuntimeException("This happened somehow", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void append(String name, byte[] dat) {
|
||||
try {
|
||||
|
||||
checkSum.reset();
|
||||
checkSum.update(dat, 0, dat.length);
|
||||
long sum = checkSum.getValue();
|
||||
|
||||
os.write(new byte[]{(byte)70,(byte)73,(byte)76,(byte)69}); // FILE
|
||||
|
||||
byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8);
|
||||
os.write(nameBytes.length);
|
||||
os.write(nameBytes);
|
||||
|
||||
writeInt(dat.length + 5, os);
|
||||
writeInt((int)sum, os);
|
||||
|
||||
os.write(dat);
|
||||
|
||||
os.write(':');
|
||||
os.write('>');
|
||||
|
||||
++totalFileCount;
|
||||
|
||||
}catch(IOException ex) {
|
||||
throw new RuntimeException("This happened somehow", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] complete() {
|
||||
try {
|
||||
|
||||
os.write(new byte[]{(byte)69,(byte)78,(byte)68,(byte)36}); // END$
|
||||
os.write(new byte[]{(byte)58,(byte)58,(byte)58,(byte)89,(byte)69,(byte)69,(byte)58,(byte)62}); // :::YEE:>
|
||||
|
||||
byte[] ret = os.toByteArray();
|
||||
|
||||
ret[lengthIntegerOffset] = (byte)((totalFileCount >> 24) & 0xFF);
|
||||
ret[lengthIntegerOffset + 1] = (byte)((totalFileCount >> 16) & 0xFF);
|
||||
ret[lengthIntegerOffset + 2] = (byte)((totalFileCount >> 8) & 0xFF);
|
||||
ret[lengthIntegerOffset + 3] = (byte)(totalFileCount & 0xFF);
|
||||
|
||||
return ret;
|
||||
|
||||
}catch(IOException ex) {
|
||||
throw new RuntimeException("This happened somehow", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeInt(int i, OutputStream os) throws IOException {
|
||||
os.write((i >> 24) & 0xFF);
|
||||
os.write((i >> 16) & 0xFF);
|
||||
os.write((i >> 8) & 0xFF);
|
||||
os.write(i & 0xFF);
|
||||
}
|
||||
|
||||
public static void writeLong(long i, OutputStream os) throws IOException {
|
||||
os.write((int)((i >> 56) & 0xFF));
|
||||
os.write((int)((i >> 48) & 0xFF));
|
||||
os.write((int)((i >> 40) & 0xFF));
|
||||
os.write((int)((i >> 32) & 0xFF));
|
||||
os.write((int)((i >> 24) & 0xFF));
|
||||
os.write((int)((i >> 16) & 0xFF));
|
||||
os.write((int)((i >> 8) & 0xFF));
|
||||
os.write((int)(i & 0xFF));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package net.minecraft.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.AssetRepository;
|
||||
import net.lax1dude.eaglercraft.DefaultSkinRenderer;
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.EaglerProfile;
|
||||
|
@ -18,6 +20,7 @@ import net.lax1dude.eaglercraft.IntegratedServerLAN;
|
|||
import net.lax1dude.eaglercraft.LocalStorageManager;
|
||||
import net.lax1dude.eaglercraft.Voice;
|
||||
import net.lax1dude.eaglercraft.WorkerNetworkManager;
|
||||
import net.lax1dude.eaglercraft.adapter.SimpleStorage;
|
||||
import net.lax1dude.eaglercraft.adapter.Tessellator;
|
||||
import net.lax1dude.eaglercraft.glemu.FixedFunctionShader;
|
||||
import net.minecraft.src.AchievementList;
|
||||
|
@ -81,6 +84,7 @@ import net.minecraft.src.StatCollector;
|
|||
import net.minecraft.src.StatStringFormatKeyInv;
|
||||
import net.minecraft.src.StringTranslate;
|
||||
import net.minecraft.src.TextureManager;
|
||||
import net.minecraft.src.TexturePackCustom;
|
||||
import net.minecraft.src.TexturePackList;
|
||||
import net.minecraft.src.Timer;
|
||||
import net.minecraft.src.WorldClient;
|
||||
|
@ -336,6 +340,14 @@ public class Minecraft implements Runnable {
|
|||
String s = EaglerAdapter.getServerToJoinOnLaunch();
|
||||
GuiScreen scr;
|
||||
|
||||
if (!TexturePackList.defaultTexturePack.getTexturePackFileName().equals(this.gameSettings.skin)) {
|
||||
try {
|
||||
AssetRepository.reset();
|
||||
AssetRepository.install(SimpleStorage.get(this.gameSettings.skin));
|
||||
this.texturePackList.selectedTexturePack = new TexturePackCustom(this.gameSettings.skin, TexturePackList.defaultTexturePack);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
if(s != null) {
|
||||
scr = new GuiScreenEditProfile(new GuiConnecting(new GuiMainMenu(), this, new ServerData("Eaglercraft Server", s, false)));
|
||||
}else {
|
||||
|
|
|
@ -545,6 +545,7 @@ public class GameSettings {
|
|||
if(yee.hasKey("hideJoinCode")) hideJoinCode = yee.getBoolean("hideJoinCode");
|
||||
if(yee.hasKey("relayTimeout")) relayTimeout = yee.getByte("relayTimeout");
|
||||
if(yee.hasKey("adderall")) adderall = yee.getBoolean("adderall");
|
||||
if(yee.hasKey("skin")) skin = yee.getString("skin");
|
||||
|
||||
if(voiceListenRadius < 5) voiceListenRadius = 5;
|
||||
else if(voiceListenRadius > 22) voiceListenRadius = 22;
|
||||
|
@ -626,6 +627,7 @@ public class GameSettings {
|
|||
yee.setBoolean("hideJoinCode", hideJoinCode);
|
||||
yee.setByte("relayTimeout", (byte)relayTimeout);
|
||||
yee.setBoolean("adderall", adderall);
|
||||
yee.setString("skin", skin);
|
||||
|
||||
for (int var4 = 0; var4 < this.keyBindings.length; ++var4) {
|
||||
yee.setInteger(keyBindings[var4].keyDescription, keyBindings[var4].keyCode);
|
||||
|
|
|
@ -52,17 +52,16 @@ public class GuiOptions extends GuiScreen {
|
|||
++var2;
|
||||
}
|
||||
|
||||
GuiButton b, b2;
|
||||
GuiButton b;
|
||||
|
||||
this.buttonList.add(new GuiButton(101, this.width / 2 - 152, this.height / 6 + 96 - 6, 150, 20, var1.translateKey("options.video")));
|
||||
this.buttonList.add(new GuiButton(100, this.width / 2 + 2, this.height / 6 + 96 - 6, 150, 20, var1.translateKey("options.controls")));
|
||||
this.buttonList.add(new GuiButton(102, this.width / 2 - 152, this.height / 6 + 120 - 6, 150, 20, var1.translateKey("options.language")));
|
||||
this.buttonList.add(new GuiButton(103, this.width / 2 + 2, this.height / 6 + 120 - 6, 150, 20, var1.translateKey("options.multiplayer.title")));
|
||||
this.buttonList.add(b = new GuiButton(105, this.width / 2 - 152, this.height / 6 + 144 - 6, 150, 20, var1.translateKey("options.texture.pack")));
|
||||
this.buttonList.add(b2 = new GuiButton(104, this.width / 2 + 2, this.height / 6 + 144 - 6, 150, 20, var1.translateKey("options.snooper.view")));
|
||||
this.buttonList.add(new GuiButton(105, this.width / 2 - 152, this.height / 6 + 144 - 6, 150, 20, var1.translateKey("options.texture.pack")));
|
||||
this.buttonList.add(b = new GuiButton(104, this.width / 2 + 2, this.height / 6 + 144 - 6, 150, 20, var1.translateKey("options.snooper.view")));
|
||||
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, var1.translateKey("gui.done")));
|
||||
b.enabled = false;
|
||||
b2.enabled = false;
|
||||
|
||||
}
|
||||
|
||||
|
@ -97,6 +96,11 @@ public class GuiOptions extends GuiScreen {
|
|||
this.mc.displayGuiScreen(new GuiScreenChatOptions(this, this.options));
|
||||
}
|
||||
|
||||
if (par1GuiButton.id == 105) {
|
||||
this.mc.gameSettings.saveOptions();
|
||||
this.mc.displayGuiScreen(new GuiTexturePacks(this, this.options));
|
||||
}
|
||||
|
||||
if (par1GuiButton.id == 200) {
|
||||
this.mc.gameSettings.saveOptions();
|
||||
this.mc.displayGuiScreen(this.parentScreen);
|
||||
|
|
|
@ -9,7 +9,7 @@ class GuiTexturePackSlot extends GuiSlot {
|
|||
final GuiTexturePacks parentTexturePackGui;
|
||||
|
||||
public GuiTexturePackSlot(GuiTexturePacks par1GuiTexturePacks) {
|
||||
super(GuiTexturePacks.func_73950_a(par1GuiTexturePacks), par1GuiTexturePacks.width, par1GuiTexturePacks.height, 32, par1GuiTexturePacks.height - 55 + 4, 36);
|
||||
super(par1GuiTexturePacks.mc, par1GuiTexturePacks.width, par1GuiTexturePacks.height, 32, par1GuiTexturePacks.height - 55 + 4, 36);
|
||||
this.parentTexturePackGui = par1GuiTexturePacks;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ class GuiTexturePackSlot extends GuiSlot {
|
|||
* Gets the size of the current slot list.
|
||||
*/
|
||||
protected int getSize() {
|
||||
return GuiTexturePacks.func_73955_b(this.parentTexturePackGui).texturePackList.availableTexturePacks().size();
|
||||
return this.mc.texturePackList.availableTexturePacks().size();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,16 +25,10 @@ class GuiTexturePackSlot extends GuiSlot {
|
|||
* clicked or not
|
||||
*/
|
||||
protected void elementClicked(int par1, boolean par2) {
|
||||
List var3 = GuiTexturePacks.func_73958_c(this.parentTexturePackGui).texturePackList.availableTexturePacks();
|
||||
|
||||
try {
|
||||
GuiTexturePacks.func_73951_d(this.parentTexturePackGui).texturePackList.setTexturePack((ITexturePack) var3.get(par1));
|
||||
GuiTexturePacks.func_73952_e(this.parentTexturePackGui).renderEngine.refreshTextures();
|
||||
GuiTexturePacks.func_73962_f(this.parentTexturePackGui).renderGlobal.loadRenderers();
|
||||
} catch (Exception var5) {
|
||||
GuiTexturePacks.func_73959_g(this.parentTexturePackGui).texturePackList.setTexturePack((ITexturePack) var3.get(0));
|
||||
GuiTexturePacks.func_73957_h(this.parentTexturePackGui).renderEngine.refreshTextures();
|
||||
GuiTexturePacks.func_73956_i(this.parentTexturePackGui).renderGlobal.loadRenderers();
|
||||
if (par1 == 0 || !this.isSelected(par1)) {
|
||||
this.parentTexturePackGui.confirmClicked(false, par1);
|
||||
} else {
|
||||
this.mc.displayGuiScreen(new GuiYesNo(this.parentTexturePackGui, StatCollector.translateToLocal("texturePack.wannaDelete"), ((ITexturePack) this.mc.texturePackList.availableTexturePacks().get(par1)).getTexturePackFileName(), par1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,8 +36,8 @@ class GuiTexturePackSlot extends GuiSlot {
|
|||
* returns true if the element passed in is currently selected
|
||||
*/
|
||||
protected boolean isSelected(int par1) {
|
||||
List var2 = GuiTexturePacks.func_73953_j(this.parentTexturePackGui).texturePackList.availableTexturePacks();
|
||||
return GuiTexturePacks.func_73961_k(this.parentTexturePackGui).texturePackList.getSelectedTexturePack() == var2.get(par1);
|
||||
List var2 = this.mc.texturePackList.availableTexturePacks();
|
||||
return this.mc.texturePackList.getSelectedTexturePack() == var2.get(par1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,8 +52,8 @@ class GuiTexturePackSlot extends GuiSlot {
|
|||
}
|
||||
|
||||
protected void drawSlot(int par1, int par2, int par3, int par4, Tessellator par5Tessellator) {
|
||||
ITexturePack var6 = (ITexturePack) GuiTexturePacks.func_96143_l(this.parentTexturePackGui).texturePackList.availableTexturePacks().get(par1);
|
||||
var6.bindThumbnailTexture(GuiTexturePacks.func_96142_m(this.parentTexturePackGui).renderEngine);
|
||||
ITexturePack var6 = (ITexturePack) this.mc.texturePackList.availableTexturePacks().get(par1);
|
||||
var6.bindThumbnailTexture(this.mc.renderEngine);
|
||||
EaglerAdapter.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
par5Tessellator.startDrawingQuads();
|
||||
par5Tessellator.setColorOpaque_I(16777215);
|
||||
|
@ -78,8 +72,8 @@ class GuiTexturePackSlot extends GuiSlot {
|
|||
var7 = var7.substring(0, 32).trim() + "...";
|
||||
}
|
||||
|
||||
this.parentTexturePackGui.drawString(GuiTexturePacks.func_73954_n(this.parentTexturePackGui), var7, par2 + 32 + 2, par3 + 1, 16777215);
|
||||
this.parentTexturePackGui.drawString(GuiTexturePacks.func_96145_o(this.parentTexturePackGui), var6.getFirstDescriptionLine(), par2 + 32 + 2, par3 + 12, 8421504);
|
||||
this.parentTexturePackGui.drawString(GuiTexturePacks.func_96144_p(this.parentTexturePackGui), var6.getSecondDescriptionLine(), par2 + 32 + 2, par3 + 12 + 10, 8421504);
|
||||
this.parentTexturePackGui.drawString(this.mc.fontRenderer, var7, par2 + 32 + 2, par3 + 1, 16777215);
|
||||
this.parentTexturePackGui.drawString(this.mc.fontRenderer, var6.getFirstDescriptionLine(), par2 + 32 + 2, par3 + 12, 8421504);
|
||||
this.parentTexturePackGui.drawString(this.mc.fontRenderer, var6.getSecondDescriptionLine(), par2 + 32 + 2, par3 + 12 + 10, 8421504);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.adapter.SimpleStorage;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GuiTexturePacks extends GuiScreen {
|
||||
protected GuiScreen guiScreen;
|
||||
private int refreshTimer = -1;
|
||||
|
@ -9,6 +13,8 @@ public class GuiTexturePacks extends GuiScreen {
|
|||
/** the absolute location of this texture pack */
|
||||
private String fileLocation = "";
|
||||
|
||||
private boolean isSelectingPack = false;
|
||||
|
||||
/**
|
||||
* the GuiTexturePackSlot that contains all the texture packs and their
|
||||
* descriptions
|
||||
|
@ -26,9 +32,7 @@ public class GuiTexturePacks extends GuiScreen {
|
|||
*/
|
||||
public void initGui() {
|
||||
StringTranslate var1 = StringTranslate.getInstance();
|
||||
GuiSmallButton b;
|
||||
this.buttonList.add(b = new GuiSmallButton(5, this.width / 2 - 154, this.height - 48, var1.translateKey("texturePack.openFolder")));
|
||||
b.enabled = false;
|
||||
this.buttonList.add(new GuiSmallButton(5, this.width / 2 - 154, this.height - 48, var1.translateKey("texturePack.openFolder")));
|
||||
this.buttonList.add(new GuiSmallButton(6, this.width / 2 + 4, this.height - 48, var1.translateKey("gui.done")));
|
||||
this.mc.texturePackList.updateAvaliableTexturePacks();
|
||||
//this.fileLocation = (new File("texturepacks")).getAbsolutePath();
|
||||
|
@ -42,7 +46,15 @@ public class GuiTexturePacks extends GuiScreen {
|
|||
*/
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if (par1GuiButton.enabled) {
|
||||
|
||||
if (par1GuiButton.id == 5) {
|
||||
isSelectingPack = true;
|
||||
EaglerAdapter.openFileChooser("epk,.zip", null);
|
||||
} else if (par1GuiButton.id == 6) {
|
||||
// this.mc.renderEngine.refreshTextures();
|
||||
this.mc.displayGuiScreen(guiScreen);
|
||||
} else {
|
||||
this.guiTexturePackSlot.actionPerformed(par1GuiButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,69 +97,35 @@ public class GuiTexturePacks extends GuiScreen {
|
|||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
--this.refreshTimer;
|
||||
if (isSelectingPack && EaglerAdapter.getFileChooserResultAvailable()) {
|
||||
isSelectingPack = false;
|
||||
String name = EaglerAdapter.getFileChooserResultName();
|
||||
SimpleStorage.set(name.replaceAll("[^A-Za-z0-9_]", "_"), name.toLowerCase().endsWith(".zip") ? TexturePackList.zipToEpk(EaglerAdapter.getFileChooserResult()) : EaglerAdapter.getFileChooserResult());
|
||||
EaglerAdapter.clearFileChooserResult();
|
||||
this.mc.displayGuiScreen(this);
|
||||
}
|
||||
}
|
||||
|
||||
static Minecraft func_73950_a(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
@Override
|
||||
public void confirmClicked(boolean par1, int par2) {
|
||||
this.mc.displayGuiScreen(this);
|
||||
|
||||
static Minecraft func_73955_b(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
List var3 = this.mc.texturePackList.availableTexturePacks();
|
||||
|
||||
static Minecraft func_73958_c(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
|
||||
static Minecraft func_73951_d(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
|
||||
static Minecraft func_73952_e(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
|
||||
static Minecraft func_73962_f(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
|
||||
static Minecraft func_73959_g(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
|
||||
static Minecraft func_73957_h(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
|
||||
static Minecraft func_73956_i(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
|
||||
static Minecraft func_73953_j(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
|
||||
static Minecraft func_73961_k(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
|
||||
static Minecraft func_96143_l(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
|
||||
static Minecraft func_96142_m(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.mc;
|
||||
}
|
||||
|
||||
static FontRenderer func_73954_n(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.fontRenderer;
|
||||
}
|
||||
|
||||
static FontRenderer func_96145_o(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.fontRenderer;
|
||||
}
|
||||
|
||||
static FontRenderer func_96144_p(GuiTexturePacks par0GuiTexturePacks) {
|
||||
return par0GuiTexturePacks.fontRenderer;
|
||||
if (par1) {
|
||||
SimpleStorage.set(((ITexturePack) var3.get(par2)).getTexturePackFileName(), null);
|
||||
} else {
|
||||
try {
|
||||
this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(par2));
|
||||
this.mc.renderEngine.refreshTextures();
|
||||
this.mc.renderGlobal.loadRenderers();
|
||||
} catch (Exception var5) {
|
||||
var5.printStackTrace();
|
||||
this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(0));
|
||||
this.mc.renderEngine.refreshTextures();
|
||||
this.mc.renderGlobal.loadRenderers();
|
||||
SimpleStorage.set(((ITexturePack) var3.get(par2)).getTexturePackFileName(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1187,7 +1187,42 @@ public class NetClientHandler extends NetHandler {
|
|||
}
|
||||
|
||||
public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload) {
|
||||
if ("MC|TrList".equals(par1Packet250CustomPayload.channel)) {
|
||||
if ("MC|TPack".equals(par1Packet250CustomPayload.channel)) {
|
||||
String[] var2 = (new String(par1Packet250CustomPayload.data))
|
||||
.split("\u0000");
|
||||
String var3 = var2[0];
|
||||
|
||||
if (var2[1].equals("16"))
|
||||
{
|
||||
if (this.mc.texturePackList.getAcceptsTextures())
|
||||
{
|
||||
this.mc.texturePackList.requestDownloadOfTexture(var3);
|
||||
}
|
||||
else if (this.mc.texturePackList.func_77300_f())
|
||||
{
|
||||
this.mc.displayGuiScreen(new GuiYesNo(
|
||||
new GuiScreen() {
|
||||
public void confirmClicked(boolean par1, int par2) {
|
||||
mc = Minecraft.getMinecraft();
|
||||
|
||||
if (mc.getServerData() != null) {
|
||||
mc.getServerData().setAcceptsTextures(par1);
|
||||
}
|
||||
|
||||
if (par1) {
|
||||
mc.texturePackList.requestDownloadOfTexture(var3);
|
||||
}
|
||||
|
||||
mc.displayGuiScreen(null);
|
||||
}
|
||||
},
|
||||
StringTranslate.getInstance().translateKey(
|
||||
"multiplayer.texturePrompt.line1"),
|
||||
StringTranslate.getInstance().translateKey(
|
||||
"multiplayer.texturePrompt.line2"), 0));
|
||||
}
|
||||
}
|
||||
} else if ("MC|TrList".equals(par1Packet250CustomPayload.channel)) {
|
||||
DataInputStream var8 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
|
||||
|
||||
try {
|
||||
|
|
37
src/main/java/net/minecraft/src/TexturePackCustom.java
Normal file
37
src/main/java/net/minecraft/src/TexturePackCustom.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.lax1dude.eaglercraft.AssetRepository;
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.adapter.SimpleStorage;
|
||||
|
||||
public class TexturePackCustom extends TexturePackImplementation {
|
||||
public TexturePackCustom(String name, ITexturePack base) {
|
||||
super(name, name, base);
|
||||
try {
|
||||
AssetRepository.installTemp(SimpleStorage.get(name));
|
||||
this.loadThumbnailImage();
|
||||
this.loadDescription();
|
||||
AssetRepository.resetTemp();
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
public boolean func_98140_c(String par1Str) {
|
||||
return EaglerAdapter.loadResource(par1Str) != null;
|
||||
}
|
||||
|
||||
public boolean isCompatible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected InputStream func_98139_b(String par1Str) throws IOException {
|
||||
return EaglerAdapter.loadResource(par1Str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getResourceAsBytes(String par1Str) {
|
||||
return EaglerAdapter.loadResourceBytes(par1Str);
|
||||
}
|
||||
}
|
|
@ -61,7 +61,7 @@ public abstract class TexturePackImplementation implements ITexturePack {
|
|||
/**
|
||||
* Load and initialize thumbnailImage from the the /pack.png file.
|
||||
*/
|
||||
private void loadThumbnailImage() {
|
||||
protected void loadThumbnailImage() {
|
||||
//this.thumbnailImage = EaglerImage.loadImage(EaglerAdapter.loadResourceBytes("/pack.png"));
|
||||
this.thumbnailImage = EaglerAdapter.loadPNG(EaglerAdapter.loadResourceBytes("/pack.png"));
|
||||
}
|
||||
|
@ -145,8 +145,12 @@ public abstract class TexturePackImplementation implements ITexturePack {
|
|||
}
|
||||
|
||||
public boolean func_98138_b(String par1Str, boolean par2) {
|
||||
try {
|
||||
boolean var3 = this.func_98140_c(par1Str);
|
||||
return !var3 && par2 && this.field_98141_g != null ? this.field_98141_g.func_98138_b(par1Str, par2) : var3;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean func_98140_c(String var1);
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import net.lax1dude.eaglercraft.AssetRepository;
|
||||
import net.lax1dude.eaglercraft.EPK2Compiler;
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.adapter.SimpleStorage;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class TexturePackList {
|
||||
|
@ -13,7 +18,7 @@ public class TexturePackList {
|
|||
* An instance of TexturePackDefault for the always available builtin texture
|
||||
* pack.
|
||||
*/
|
||||
private static final ITexturePack defaultTexturePack = new TexturePackDefault();
|
||||
public static final ITexturePack defaultTexturePack = new TexturePackDefault();
|
||||
|
||||
/** The Minecraft instance. */
|
||||
private final Minecraft mc;
|
||||
|
@ -35,7 +40,7 @@ public class TexturePackList {
|
|||
private Map texturePackCache = new HashMap();
|
||||
|
||||
/** The TexturePack that will be used. */
|
||||
private ITexturePack selectedTexturePack;
|
||||
public ITexturePack selectedTexturePack;
|
||||
|
||||
/** True if a texture pack is downloading in the background. */
|
||||
private boolean isDownloading;
|
||||
|
@ -57,6 +62,10 @@ public class TexturePackList {
|
|||
} else {
|
||||
this.isDownloading = false;
|
||||
this.selectedTexturePack = par1ITexturePack;
|
||||
try {
|
||||
AssetRepository.reset();
|
||||
AssetRepository.install(SimpleStorage.get(this.selectedTexturePack.getTexturePackFileName()));
|
||||
} catch (IOException ignored) {}
|
||||
this.mc.gameSettings.skin = par1ITexturePack.getTexturePackFileName();
|
||||
this.mc.gameSettings.saveOptions();
|
||||
return true;
|
||||
|
@ -64,9 +73,8 @@ public class TexturePackList {
|
|||
}
|
||||
|
||||
/**
|
||||
* filename must end in .zip
|
||||
* filename must end in .zip or .epk
|
||||
*/
|
||||
/*
|
||||
public void requestDownloadOfTexture(String par1Str) {
|
||||
String var2 = par1Str.substring(par1Str.lastIndexOf("/") + 1);
|
||||
|
||||
|
@ -74,24 +82,17 @@ public class TexturePackList {
|
|||
var2 = var2.substring(0, var2.indexOf("?"));
|
||||
}
|
||||
|
||||
if (var2.endsWith(".zip")) {
|
||||
File var3 = new File(this.mpTexturePackFolder, var2);
|
||||
this.downloadTexture(par1Str, var3);
|
||||
if (var2.toLowerCase().endsWith(".zip") || var2.toLowerCase().endsWith(".epk")) {
|
||||
this.downloadTexture(par1Str, var2);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
private void downloadTexture(String par1Str, File par2File) {
|
||||
HashMap var3 = new HashMap();
|
||||
GuiProgress var4 = new GuiProgress();
|
||||
var3.put("X-Minecraft-Username", this.mc.session.username);
|
||||
var3.put("X-Minecraft-Version", "1.5.2");
|
||||
var3.put("X-Minecraft-Supported-Resolutions", "16");
|
||||
|
||||
private void downloadTexture(String par1Str, String par2File) {
|
||||
this.isDownloading = true;
|
||||
this.mc.displayGuiScreen(var4);
|
||||
HttpUtil.downloadTexturePack(par2File, par1Str, new TexturePackDownloadSuccess(this), var3, 10000000, var4);
|
||||
SimpleStorage.set(par2File.replaceAll("[^A-Za-z0-9_]", "_"), par2File.toLowerCase().endsWith(".zip") ? zipToEpk(EaglerAdapter.downloadURL(par1Str)) : EaglerAdapter.downloadURL(par1Str));
|
||||
this.onDownloadFinished();
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return true if a texture pack is downloading in the background.
|
||||
*/
|
||||
|
@ -114,30 +115,33 @@ public class TexturePackList {
|
|||
*/
|
||||
public void updateAvaliableTexturePacks() {
|
||||
ArrayList var1 = new ArrayList();
|
||||
this.selectedTexturePack = defaultTexturePack;
|
||||
var1.add(defaultTexturePack);
|
||||
/*
|
||||
Iterator var2 = this.getTexturePackDirContents().iterator();
|
||||
|
||||
while (var2.hasNext()) {
|
||||
File var3 = (File) var2.next();
|
||||
String var4 = this.generateTexturePackID(var3);
|
||||
String var3 = (String) var2.next();
|
||||
|
||||
if (var4 != null) {
|
||||
Object var5 = (ITexturePack) this.texturePackCache.get(var4);
|
||||
Object var5 = (ITexturePack) this.texturePackCache.get(var3);
|
||||
|
||||
if (var5 == null) {
|
||||
var5 = var3.isDirectory() ? new TexturePackFolder(var4, var3, defaultTexturePack) : new TexturePackCustom(var4, var3, defaultTexturePack);
|
||||
this.texturePackCache.put(var4, var5);
|
||||
try {
|
||||
var5 = new TexturePackCustom(var3, defaultTexturePack);
|
||||
this.texturePackCache.put(var3, var5);
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace(); // bad texture pack
|
||||
}
|
||||
}
|
||||
|
||||
if (((ITexturePack) var5).getTexturePackFileName().equals(this.mc.gameSettings.skin)) {
|
||||
this.selectedTexturePack = (ITexturePack) var5;
|
||||
try {
|
||||
AssetRepository.reset();
|
||||
AssetRepository.install(SimpleStorage.get(this.selectedTexturePack.getTexturePackFileName()));
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
var1.add(var5);
|
||||
}
|
||||
}
|
||||
|
||||
this.availableTexturePacks.removeAll(var1);
|
||||
var2 = this.availableTexturePacks.iterator();
|
||||
|
@ -147,7 +151,6 @@ public class TexturePackList {
|
|||
var6.deleteTexturePack(this.mc.renderEngine);
|
||||
this.texturePackCache.remove(var6.getTexturePackID());
|
||||
}
|
||||
*/
|
||||
|
||||
this.availableTexturePacks = var1;
|
||||
}
|
||||
|
@ -163,11 +166,11 @@ public class TexturePackList {
|
|||
// }
|
||||
|
||||
/**
|
||||
* Return a List<File> of file/directories in the texture pack directory.
|
||||
* Return a List<String> of file/directories in the texture pack directory.
|
||||
*/
|
||||
// private List getTexturePackDirContents() {
|
||||
// return this.texturePackDir.exists() && this.texturePackDir.isDirectory() ? Arrays.asList(this.texturePackDir.listFiles()) : Collections.emptyList();
|
||||
// }
|
||||
private List getTexturePackDirContents() {
|
||||
return SimpleStorage.isAvailable() ? Arrays.asList(SimpleStorage.list()) : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the available texture packs.
|
||||
|
@ -177,6 +180,9 @@ public class TexturePackList {
|
|||
}
|
||||
|
||||
public ITexturePack getSelectedTexturePack() {
|
||||
if (this.selectedTexturePack == null) {
|
||||
this.selectedTexturePack = defaultTexturePack;
|
||||
}
|
||||
return this.selectedTexturePack;
|
||||
}
|
||||
|
||||
|
@ -225,4 +231,28 @@ public class TexturePackList {
|
|||
static Minecraft getMinecraft(TexturePackList par0TexturePackList) {
|
||||
return par0TexturePackList.mc;
|
||||
}
|
||||
|
||||
public static final byte[] zipToEpk(byte[] in) {
|
||||
try {
|
||||
EPK2Compiler epk2Compiler = new EPK2Compiler();
|
||||
try (ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(in))) {
|
||||
ZipEntry zipEntry;
|
||||
byte[] bb = new byte[16000];
|
||||
while ((zipEntry = zis.getNextEntry()) != null) {
|
||||
if (zipEntry.isDirectory()) continue;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
int len;
|
||||
while ((len = zis.read(bb)) != -1) {
|
||||
baos.write(bb, 0, len);
|
||||
}
|
||||
baos.close();
|
||||
epk2Compiler.append(zipEntry.getName(), baos.toByteArray());
|
||||
}
|
||||
}
|
||||
return epk2Compiler.complete();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return in;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,196 @@
|
|||
package net.lax1dude.eaglercraft.adapter;
|
||||
|
||||
import org.teavm.interop.Async;
|
||||
import org.teavm.interop.AsyncCallback;
|
||||
import org.teavm.jso.core.JSString;
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||
import org.teavm.jso.typedarrays.Uint8Array;
|
||||
|
||||
import net.lax1dude.eaglercraft.adapter.teavm.IDBDatabase;
|
||||
import net.lax1dude.eaglercraft.adapter.teavm.IDBFactory;
|
||||
import net.lax1dude.eaglercraft.adapter.teavm.IDBGetRequest;
|
||||
import net.lax1dude.eaglercraft.adapter.teavm.IDBObjectStore;
|
||||
import net.lax1dude.eaglercraft.adapter.teavm.IDBOpenDBRequest;
|
||||
import net.lax1dude.eaglercraft.adapter.teavm.IDBRequest;
|
||||
|
||||
public class SimpleStorage {
|
||||
private static IDBDatabase database;
|
||||
private static boolean available;
|
||||
|
||||
public static boolean isAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
static {
|
||||
IDBOpenDBRequest request = IDBFactory.getInstance().open("eagstorage", 1);
|
||||
request.setOnUpgradeNeeded(evt -> {
|
||||
database = request.getResult();
|
||||
database.createObjectStore("store");
|
||||
});
|
||||
request.setOnSuccess(() -> {
|
||||
database = request.getResult();
|
||||
available = true;
|
||||
});
|
||||
request.setOnError(() -> {
|
||||
database = request.getResult();
|
||||
available = false;
|
||||
});
|
||||
}
|
||||
|
||||
private static IDBObjectStore getStore() {
|
||||
return database.transaction(new String[] { "store" }, "readwrite").objectStore("store");
|
||||
}
|
||||
|
||||
@Async
|
||||
public static native byte[] get(String key);
|
||||
|
||||
private static void get(String key, final AsyncCallback<byte[]> cb) {
|
||||
if (key.equals("__LIST__") || key.contains("\n")) {
|
||||
cb.complete(null);
|
||||
return;
|
||||
}
|
||||
IDBGetRequest request = getStore().get(JSString.valueOf(key));
|
||||
request.setOnSuccess(() -> {
|
||||
Uint8Array a = Uint8Array.create((ArrayBuffer) request.getResult().cast());
|
||||
byte[] b = new byte[a.getByteLength()];
|
||||
for(int i = 0; i < b.length; ++i) {
|
||||
b[i] = (byte) (a.get(i) & 0xFF);
|
||||
}
|
||||
cb.complete(b);
|
||||
});
|
||||
request.setOnError(() -> {
|
||||
cb.complete(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Async
|
||||
public static native Boolean set(String key, byte[] value);
|
||||
|
||||
private static void set(String key, byte[] value, final AsyncCallback<Boolean> cb) {
|
||||
if (key.equals("__LIST__") || key.contains("\n")) {
|
||||
cb.complete(false);
|
||||
return;
|
||||
}
|
||||
if (value == null) {
|
||||
IDBGetRequest request3 = getStore().get(JSString.valueOf("__LIST__"));
|
||||
request3.setOnSuccess(() -> {
|
||||
String listVal;
|
||||
if (JSString.isInstance(request3.getResult()) && !(listVal = ((JSString) request3.getResult().cast()).stringValue()).isEmpty()) {
|
||||
String[] list = listVal.replaceAll("[^a-zA-Z0-9_\n]", "").split("\n");
|
||||
String[] newList = new String[list.length - 1];
|
||||
int a = 0;
|
||||
for (int i = 0; i < list.length; ++i) {
|
||||
if (list[i].equals(key)) {
|
||||
--a;
|
||||
} else {
|
||||
newList[i + a] = list[i];
|
||||
}
|
||||
}
|
||||
IDBRequest request2 = getStore().put(JSString.valueOf(String.join("\n", newList)), JSString.valueOf("__LIST__"));
|
||||
request2.setOnSuccess(() -> {
|
||||
IDBRequest request = getStore().delete(JSString.valueOf(key));
|
||||
request.setOnSuccess(() -> {
|
||||
cb.complete(Boolean.TRUE);
|
||||
});
|
||||
request.setOnError(() -> {
|
||||
cb.complete(Boolean.FALSE);
|
||||
});
|
||||
});
|
||||
request2.setOnError(() -> {
|
||||
cb.complete(Boolean.FALSE);
|
||||
});
|
||||
} else {
|
||||
IDBRequest request = getStore().delete(JSString.valueOf(key));
|
||||
request.setOnSuccess(() -> {
|
||||
cb.complete(Boolean.TRUE);
|
||||
});
|
||||
request.setOnError(() -> {
|
||||
cb.complete(Boolean.FALSE);
|
||||
});
|
||||
}
|
||||
});
|
||||
request3.setOnError(() -> {
|
||||
IDBRequest request = getStore().delete(JSString.valueOf(key));
|
||||
request.setOnSuccess(() -> {
|
||||
cb.complete(Boolean.TRUE);
|
||||
});
|
||||
request.setOnError(() -> {
|
||||
cb.complete(Boolean.FALSE);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
ArrayBuffer arr = ArrayBuffer.create(value.length);
|
||||
Uint8Array.create(arr).set(value);
|
||||
IDBRequest request2 = getStore().put(arr, JSString.valueOf(key));
|
||||
request2.setOnSuccess(() -> {
|
||||
IDBGetRequest request3 = getStore().get(JSString.valueOf("__LIST__"));
|
||||
request3.setOnSuccess(() -> {
|
||||
String listVal;
|
||||
if (JSString.isInstance(request3.getResult()) && !(listVal = ((JSString) request3.getResult().cast()).stringValue()).isEmpty()) {
|
||||
String[] list = listVal.replaceAll("[^a-zA-Z0-9_\n]", "").split("\n");
|
||||
boolean alrHas = false;
|
||||
for (String s : list) {
|
||||
if (s.equals(key)) {
|
||||
alrHas = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String[] newList;
|
||||
if (alrHas) {
|
||||
newList = list;
|
||||
} else {
|
||||
newList = new String[list.length + 1];
|
||||
System.arraycopy(list, 0, newList, 0, list.length);
|
||||
newList[list.length] = key;
|
||||
}
|
||||
IDBRequest request = getStore().put(JSString.valueOf(String.join("\n", newList).replaceAll("[^a-zA-Z0-9_\n]", "")), JSString.valueOf("__LIST__"));
|
||||
request.setOnSuccess(() -> {
|
||||
cb.complete(Boolean.TRUE);
|
||||
});
|
||||
request.setOnError(() -> {
|
||||
cb.complete(Boolean.FALSE);
|
||||
});
|
||||
} else {
|
||||
IDBRequest request = getStore().put(JSString.valueOf(key), JSString.valueOf("__LIST__"));
|
||||
request.setOnSuccess(() -> {
|
||||
cb.complete(Boolean.TRUE);
|
||||
});
|
||||
request.setOnError(() -> {
|
||||
cb.complete(Boolean.FALSE);
|
||||
});
|
||||
}
|
||||
});
|
||||
request3.setOnError(() -> {
|
||||
IDBRequest request = getStore().put(JSString.valueOf(key), JSString.valueOf("__LIST__"));
|
||||
request.setOnSuccess(() -> {
|
||||
cb.complete(Boolean.TRUE);
|
||||
});
|
||||
request.setOnError(() -> {
|
||||
cb.complete(Boolean.FALSE);
|
||||
});
|
||||
});
|
||||
});
|
||||
request2.setOnError(() -> {
|
||||
cb.complete(Boolean.FALSE);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
public static native String[] list();
|
||||
|
||||
private static void list(final AsyncCallback<String[]> cb) {
|
||||
IDBGetRequest request = getStore().get(JSString.valueOf("__LIST__"));
|
||||
request.setOnSuccess(() -> {
|
||||
String listVal;
|
||||
if (JSString.isInstance(request.getResult()) && !(listVal = ((JSString) request.getResult().cast()).stringValue()).isEmpty()) {
|
||||
cb.complete(listVal.replaceAll("[^a-zA-Z0-9_\n]", "").split("\n"));
|
||||
} else {
|
||||
cb.complete(new String[0]);
|
||||
}
|
||||
});
|
||||
request.setOnError(() -> {
|
||||
cb.complete(new String[0]);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSFunctor;
|
||||
import org.teavm.jso.JSObject;
|
||||
|
||||
@JSFunctor
|
||||
public interface EventHandler extends JSObject {
|
||||
void handleEvent();
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSProperty;
|
||||
|
||||
public interface IDBCountRequest extends IDBRequest {
|
||||
@JSProperty
|
||||
int getResult();
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSMethod;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.JSProperty;
|
||||
|
||||
public interface IDBCursor extends JSObject {
|
||||
String DIRECTION_NEXT = "next";
|
||||
|
||||
String DIRECTION_NEXT_UNIQUE = "nextunique";
|
||||
|
||||
String DIRECTION_PREVIOUS = "prev";
|
||||
|
||||
String DIRECTION_PREVIOUS_UNIQUE = "prevunique";
|
||||
|
||||
@JSProperty
|
||||
IDBCursorSource getSource();
|
||||
|
||||
@JSProperty
|
||||
String getDirection();
|
||||
|
||||
@JSProperty
|
||||
JSObject getKey();
|
||||
|
||||
@JSProperty
|
||||
JSObject getValue();
|
||||
|
||||
@JSProperty
|
||||
JSObject getPrimaryKey();
|
||||
|
||||
IDBRequest update(JSObject value);
|
||||
|
||||
void advance(int count);
|
||||
|
||||
@JSMethod("continue")
|
||||
void doContinue();
|
||||
|
||||
IDBRequest delete();
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSProperty;
|
||||
|
||||
public interface IDBCursorRequest extends IDBRequest {
|
||||
@JSProperty
|
||||
IDBCursor getResult();
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSObject;
|
||||
|
||||
public interface IDBCursorSource extends JSObject {
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.dom.events.EventTarget;
|
||||
|
||||
public interface IDBDatabase extends EventTarget {
|
||||
String TRANSACTION_READONLY = "readonly";
|
||||
|
||||
String TRANSACTION_READWRITE = "readwrite";
|
||||
|
||||
String TRANSACTION_VERSIONCHANGE = "versionchange";
|
||||
|
||||
@JSProperty
|
||||
String getName();
|
||||
|
||||
@JSProperty
|
||||
int getVersion();
|
||||
|
||||
@JSProperty
|
||||
String[] getObjectStoreNames();
|
||||
|
||||
net.lax1dude.eaglercraft.adapter.teavm.IDBObjectStore createObjectStore(String name,
|
||||
IDBObjectStoreParameters optionalParameters);
|
||||
|
||||
IDBObjectStore createObjectStore(String name);
|
||||
|
||||
void deleteObjectStore(String name);
|
||||
|
||||
IDBTransaction transaction(String storeName, String transactionMode);
|
||||
|
||||
IDBTransaction transaction(String storeName);
|
||||
|
||||
IDBTransaction transaction(String[] storeNames, String transactionMode);
|
||||
|
||||
IDBTransaction transaction(String[] storeNames);
|
||||
|
||||
void close();
|
||||
|
||||
@JSProperty("onabort")
|
||||
void setOnAbort(net.lax1dude.eaglercraft.adapter.teavm.EventHandler handler);
|
||||
|
||||
@JSProperty("onerror")
|
||||
void setOnError(net.lax1dude.eaglercraft.adapter.teavm.EventHandler handler);
|
||||
|
||||
@JSProperty("onversionchange")
|
||||
void setOnVersionChange(EventHandler handler);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.JSProperty;
|
||||
|
||||
public abstract class IDBError implements JSObject {
|
||||
@JSProperty
|
||||
public abstract String getName();
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
|
||||
public abstract class IDBFactory implements JSObject {
|
||||
public static boolean isSupported() {
|
||||
return !getInstanceImpl().isUndefined();
|
||||
}
|
||||
|
||||
@JSBody(script = "return typeof this === 'undefined';")
|
||||
private native boolean isUndefined();
|
||||
|
||||
public static IDBFactory getInstance() {
|
||||
IDBFactory factory = getInstanceImpl();
|
||||
if (factory.isUndefined()) {
|
||||
throw new IllegalStateException("IndexedDB is not supported in this browser");
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
@JSBody(script = "return window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || "
|
||||
+ "window.msIndexedDB;")
|
||||
static native IDBFactory getInstanceImpl();
|
||||
|
||||
public abstract IDBOpenDBRequest open(String name, int version);
|
||||
|
||||
public abstract IDBOpenDBRequest deleteDatabase(String name);
|
||||
|
||||
public abstract int cmp(JSObject a, JSObject b);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.JSProperty;
|
||||
|
||||
public interface IDBGetRequest extends IDBRequest {
|
||||
@JSProperty
|
||||
JSObject getResult();
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.core.JSString;
|
||||
|
||||
public abstract class IDBIndex implements JSObject, IDBCursorSource {
|
||||
@JSProperty
|
||||
public abstract String getName();
|
||||
|
||||
@JSProperty("keyPath")
|
||||
abstract JSObject getKeyPathImpl();
|
||||
|
||||
public final String[] getKeyPath() {
|
||||
JSObject result = getKeyPathImpl();
|
||||
if (JSString.isInstance(result)) {
|
||||
return new String[] { result.<JSString>cast().stringValue() };
|
||||
} else {
|
||||
return unwrapStringArray(result);
|
||||
}
|
||||
}
|
||||
|
||||
@JSBody(script = "return this;")
|
||||
private native String[] unwrapStringArray(JSObject obj);
|
||||
|
||||
@JSProperty
|
||||
public abstract boolean isMultiEntry();
|
||||
|
||||
@JSProperty
|
||||
public abstract boolean isUnique();
|
||||
|
||||
public abstract IDBCursorRequest openCursor();
|
||||
|
||||
public abstract IDBCursorRequest openCursor(IDBKeyRange range);
|
||||
|
||||
public abstract IDBCursorRequest openKeyCursor();
|
||||
|
||||
public abstract IDBGetRequest get(JSObject key);
|
||||
|
||||
public abstract IDBGetRequest getKey(JSObject key);
|
||||
|
||||
public abstract IDBCountRequest count(JSObject key);
|
||||
|
||||
public abstract IDBCountRequest count();
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.JSProperty;
|
||||
|
||||
public abstract class IDBKeyRange implements JSObject {
|
||||
@JSProperty
|
||||
public abstract JSObject getLower();
|
||||
|
||||
@JSProperty
|
||||
public abstract JSObject getUpper();
|
||||
|
||||
@JSProperty
|
||||
public abstract boolean isLowerOpen();
|
||||
|
||||
@JSProperty
|
||||
public abstract boolean isUpperOpen();
|
||||
|
||||
@JSBody(params = "value", script = "return IDBKeyRange.only(value);")
|
||||
public static native IDBKeyRange only(JSObject value);
|
||||
|
||||
@JSBody(params = { "lower", "open" }, script = "return IDBKeyRange.lowerBound(lower, open);")
|
||||
public static native IDBKeyRange lowerBound(JSObject lower, boolean open);
|
||||
|
||||
public static IDBKeyRange lowerBound(JSObject lower) {
|
||||
return lowerBound(lower, false);
|
||||
}
|
||||
|
||||
@JSBody(params = { "upper", "open" }, script = "return IDBKeyRange.upperBound(upper, open);")
|
||||
public static native IDBKeyRange upperBound(JSObject upper, boolean open);
|
||||
|
||||
public static IDBKeyRange upperBound(JSObject upper) {
|
||||
return upperBound(upper, false);
|
||||
}
|
||||
|
||||
@JSBody(params = { "lower", "upper", "lowerOpen",
|
||||
"upperOpen" }, script = "return IDBKeyRange.bound(lower, upper, lowerOpen, upperOpen);")
|
||||
public static native IDBKeyRange bound(JSObject lower, JSObject upper, boolean lowerOpen, boolean upperOpen);
|
||||
|
||||
public static IDBKeyRange bound(JSObject lower, JSObject upper) {
|
||||
return bound(lower, upper, false, false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.core.JSString;
|
||||
|
||||
public abstract class IDBObjectStore implements JSObject, IDBCursorSource {
|
||||
@JSProperty
|
||||
public abstract String getName();
|
||||
|
||||
@JSProperty("keyPath")
|
||||
abstract JSObject getKeyPathImpl();
|
||||
|
||||
public final String[] getKeyPath() {
|
||||
JSObject result = getKeyPathImpl();
|
||||
if (JSString.isInstance(result)) {
|
||||
return new String[] { result.<JSString>cast().stringValue() };
|
||||
} else {
|
||||
return unwrapStringArray(result);
|
||||
}
|
||||
}
|
||||
|
||||
@JSBody(params = { "arr" }, script = "return arr;")
|
||||
private native String[] unwrapStringArray(JSObject obj);
|
||||
|
||||
@JSProperty
|
||||
public abstract String[] getIndexNames();
|
||||
|
||||
@JSProperty
|
||||
public abstract boolean isAutoIncrement();
|
||||
|
||||
public abstract IDBRequest put(JSObject value, JSObject key);
|
||||
|
||||
public abstract IDBRequest put(JSObject value);
|
||||
|
||||
public abstract IDBRequest add(JSObject value, JSObject key);
|
||||
|
||||
public abstract IDBRequest add(JSObject value);
|
||||
|
||||
public abstract IDBRequest delete(JSObject key);
|
||||
|
||||
public abstract IDBGetRequest get(JSObject key);
|
||||
|
||||
public abstract IDBRequest clear();
|
||||
|
||||
public abstract IDBCursorRequest openCursor();
|
||||
|
||||
public abstract IDBCursorRequest openCursor(IDBKeyRange range);
|
||||
|
||||
public abstract net.lax1dude.eaglercraft.adapter.teavm.IDBIndex createIndex(String name, String key);
|
||||
|
||||
public abstract net.lax1dude.eaglercraft.adapter.teavm.IDBIndex createIndex(String name,
|
||||
String[] keys);
|
||||
|
||||
public abstract IDBIndex index(String name);
|
||||
|
||||
public abstract void deleteIndex(String name);
|
||||
|
||||
public abstract IDBCountRequest count();
|
||||
|
||||
public abstract IDBCountRequest count(JSObject key);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.JSProperty;
|
||||
|
||||
public abstract class IDBObjectStoreParameters implements JSObject {
|
||||
@JSBody(script = "return {};")
|
||||
public static native IDBObjectStoreParameters create();
|
||||
|
||||
public final IDBObjectStoreParameters keyPath(String... keys) {
|
||||
setKeyPath(keys);
|
||||
return this;
|
||||
}
|
||||
|
||||
public final IDBObjectStoreParameters autoIncrement(boolean autoIncrement) {
|
||||
setAutoIncrement(autoIncrement);
|
||||
return this;
|
||||
}
|
||||
|
||||
@JSProperty
|
||||
abstract void setKeyPath(String[] keys);
|
||||
|
||||
@JSProperty
|
||||
abstract void setAutoIncrement(boolean autoIncrement);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.dom.events.EventListener;
|
||||
|
||||
public interface IDBOpenDBRequest extends IDBRequest {
|
||||
@JSProperty
|
||||
IDBDatabase getResult();
|
||||
|
||||
@JSProperty
|
||||
void setOnBlocked(EventHandler handler);
|
||||
|
||||
@JSProperty("onupgradeneeded")
|
||||
void setOnUpgradeNeeded(EventListener<IDBVersionChangeEvent> listener);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.dom.events.EventTarget;
|
||||
|
||||
public interface IDBRequest extends EventTarget {
|
||||
String STATE_PENDING = "pending";
|
||||
String STATE_DONE = "done";
|
||||
|
||||
@JSProperty
|
||||
IDBError getError();
|
||||
|
||||
@JSProperty
|
||||
IDBRequestSource getSource();
|
||||
|
||||
@JSProperty
|
||||
IDBTransaction getTransaction();
|
||||
|
||||
@JSProperty
|
||||
String getReadyState();
|
||||
|
||||
@JSProperty("onerror")
|
||||
void setOnError(net.lax1dude.eaglercraft.adapter.teavm.EventHandler handler);
|
||||
|
||||
@JSProperty("onsuccess")
|
||||
void setOnSuccess(EventHandler handler);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSObject;
|
||||
|
||||
public interface IDBRequestSource extends JSObject {
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.dom.events.EventTarget;
|
||||
|
||||
public interface IDBTransaction extends JSObject, EventTarget {
|
||||
@JSProperty
|
||||
String getMode();
|
||||
|
||||
@JSProperty
|
||||
IDBDatabase getDb();
|
||||
|
||||
@JSProperty
|
||||
IDBError getError();
|
||||
|
||||
IDBObjectStore objectStore(String name);
|
||||
|
||||
void abort();
|
||||
|
||||
@JSProperty("onabort")
|
||||
void setOnAbort(net.lax1dude.eaglercraft.adapter.teavm.EventHandler handler);
|
||||
|
||||
@JSProperty("oncomplete")
|
||||
void setOnComplete(net.lax1dude.eaglercraft.adapter.teavm.EventHandler handler);
|
||||
|
||||
@JSProperty("onerror")
|
||||
void setOnError(EventHandler handler);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.dom.events.Event;
|
||||
|
||||
public interface IDBVersionChangeEvent extends Event {
|
||||
@JSProperty
|
||||
int getOldVersion();
|
||||
|
||||
@JSProperty
|
||||
int getNewVersion();
|
||||
}
|
Loading…
Reference in New Issue
Block a user