Skip to content

Commit

Permalink
Reorganize code
Browse files Browse the repository at this point in the history
* Resources are now in src/main/resources
  * Instead of agolf/picture the directory is now picture/agolf
* Code is now in src/main/java
* Rewrite ImageManager
  * Update to load from new resouce directories
  * Cleanup of the class, rename a few arguments and methods
  • Loading branch information
pehala committed Sep 3, 2020
1 parent cbc9421 commit 8951b3a
Show file tree
Hide file tree
Showing 308 changed files with 37 additions and 230 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void createImages() {
public void connectToServer() {
this.gameContainer.connection = new Conn(this.gameContainer);
if (!this.gameContainer.connection.method1158()) {
this.setEndState(AApplet.END_ERROR_CONNECTION);
this.setEndState(END_ERROR_CONNECTION);
}

}
Expand Down Expand Up @@ -265,7 +265,7 @@ public void gameFinished(boolean var1) {
}

public void quit(String from) {
this.setEndState(AApplet.END_QUIT);
this.setEndState(END_QUIT);
this.gameContainer.connection.writeData((from != null ? from + "\t" : "") + "quit");
this.setGameState(5);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.Optional;

public abstract class AApplet extends Applet implements Runnable, ActionListener, QuickTimerListener {

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,107 +5,79 @@

import java.applet.Applet;
import java.awt.*;
import java.awt.image.ImageObserver;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;

public final class ImageManager {

private Applet applet;
private URL codebaseURL;
private String[][] imageAliases;
private Hashtable aHashtable1357;
private Hashtable imagesTable;
private Hashtable<String, String> imageAliases;
private boolean validImageDir;
private boolean isDebug;
private ImageTracker imageTracker;
private final boolean isDebug;
private final ImageTracker imageTracker;


public ImageManager(Applet var1) {
this(var1, "picture/", true);
public ImageManager(Applet applet) {
this(applet, "src/main/resources/picture/", true);
}

public ImageManager(Applet var1, boolean var2) {
this(var1, "picture/", var2);
public ImageManager(Applet applet, boolean isDebug) {
this(applet, "src/main/resources/picture/", isDebug);
}

public ImageManager(Applet var1, String var2) {
this(var1, var2, true);
public ImageManager(Applet applet, String imageDir) {
this(applet, imageDir, true);
}

public ImageManager(Applet applet, String imageDir, boolean isDebug) {
this.applet = applet;
this.isDebug = isDebug;

// TODO: Remove this code if it doesn't cause any problems in a few releases, I rewritten the functionality
this.validImageDir = true;
if (imageDir != null && imageDir.length() > 0) {
this.validImageDir = false;
}

String host = applet.getCodeBase().getHost();
String URL = applet.getCodeBase().toString().replace("http://" + host, "res"); // todo: Load from res folder in classpath
try {
this.codebaseURL = new File(URL).toURI().toURL();
} catch (Exception e) {
e.printStackTrace();
}


if (!this.validImageDir) {
try {
this.codebaseURL = new URL(this.codebaseURL, imageDir);
} catch (MalformedURLException var5) {
;
}
}
this.aHashtable1357 = new Hashtable();
this.imagesTable = new Hashtable();
this.imageAliases = new Hashtable<>();
this.imageTracker = new ImageTracker(applet, isDebug);
}

public void setImageAliases(String[][] var1) {
this.imageAliases = var1;
public void setImageAliases(String[][] imageAliases) {
if (imageAliases != null) {
for (String[] aliases : imageAliases) {
this.imageAliases.put(aliases[0], aliases[1]);
}
}
}

public String defineImage(String var1) {
return this.defineImage(this.method1596(var1), var1);
return this.defineImage(this.removeExtension(var1), var1);
}

public String defineImage(String imageAlias, String imageFileName) {
if (this.isDebug) {
System.out.println("ImageManager.defineImage(\"" + imageAlias + "\",\"" + imageFileName + "\")");
}

/*
URL url = codebaseURL;
try {
url = new URL(codebaseURL, method1597(imageFileName));
} catch (Exception ex) {
}
Image var3 = Toolkit.getDefaultToolkit().createImage(url);
*/


//Image var3 = Toolkit.getDefaultToolkit().getImage("AGolf/picture/"+getClass().getResource(method1597(imageFileName)));
Image var3 = Toolkit.getDefaultToolkit().createImage(this.getClass().getResource("/AGolf/picture/"+method1597(imageFileName)));
Image var3 = Toolkit.getDefaultToolkit().createImage(this.getClass().getResource("/picture/agolf/" +getAlias(imageFileName)));
this.imageTracker.registerImage(imageAlias, var3);
return imageAlias;
}

public String defineSharedImage(String var1) {
return defineSharedImage(method1596(var1), var1);
return defineSharedImage(removeExtension(var1), var1);
}

public String defineSharedImage(String imageAlias, String imageFileName) {
if (this.isDebug) {
System.out.println("ImageManager.defineSharedImage(\"" + imageAlias + "\",\"" + imageFileName + "\")");
}

Image var3 = Toolkit.getDefaultToolkit().createImage(this.getClass().getResource("/Shared/picture/"+method1597(imageFileName)));
Image var3 = Toolkit.getDefaultToolkit().createImage(this.getClass().getResource("/picture/shared/" +getAlias(imageFileName)));
this.imageTracker.method1624(imageAlias, var3);
return imageAlias;
}
Expand All @@ -114,14 +86,6 @@ public void unDefineImage(String var1) {
this.imageTracker.method1636(var1);
}

public void defineAlias(String var1, String var2) {
if (this.isDebug) {
System.out.println("ImageManager.defineAlias(\"" + var1 + "\",\"" + var2 + "\")");
}

this.aHashtable1357.put(var1, var2);
}

public void startLoadingImages() {
this.imageTracker.method1626();
}
Expand Down Expand Up @@ -177,7 +141,7 @@ public Image getShared(String var1) {
}

public Image getShared(String var1, boolean var2) {
String var3 = this.method1596(var1);
String var3 = this.removeExtension(var1);
Image var4 = this.imageTracker.method1631(var3);
if (var4 != null) {
return var4;
Expand Down Expand Up @@ -241,17 +205,17 @@ public int[] getPixels(Image var1, int var2, int var3, int var4, int var5) {
}

public Image createImage(int[] var1, int var2, int var3) {
return this.createImage(var1, var2, var3, (Component) null);
return this.createImage(var1, var2, var3, null);
}

public Image createImage(int[] var1, int var2, int var3, Component var4) {
if (var4 == null) {
var4 = this.applet;
}

Image var5 = ((Component) var4).createImage(new MemoryImageSource(var2, var3, var1, 0, var2));
Image var5 = var4.createImage(new MemoryImageSource(var2, var3, var1, 0, var2));

while (!((Component) var4).prepareImage(var5, (ImageObserver) var4)) {
while (!var4.prepareImage(var5, var4)) {
Tools.sleep(20L);
}

Expand Down Expand Up @@ -296,97 +260,6 @@ public Image[][] separateImages(Image var1, int var2, int var3) {
return var10;
}

public Image[][] separateImages(String var1, int var2, int var3) {
String var4 = var1 + ":" + var2 + "*" + var3;
Hashtable var6 = this.imagesTable;
synchronized (this.imagesTable) {
Image[][] var5 = (Image[][]) ((Image[][]) this.imagesTable.get(var4));
if (var5 == null) {
Image var7 = this.getImage(var1);
this.unDefineImage(var1);
var5 = this.separateImages(var7, var2, var3);
this.imagesTable.put(var4, var5);
}

return var5;
}
}

public Image[] separateImages(String var1, int var2) {
String var3 = var1 + ":" + var2;
Hashtable var5 = this.imagesTable;
synchronized (this.imagesTable) {
Image[] var4 = (Image[]) ((Image[]) this.imagesTable.get(var3));
if (var4 == null) {
Image var6 = this.getImage(var1);
this.unDefineImage(var1);
var4 = this.separateImages(var6, var2, 1)[0];
this.imagesTable.put(var3, var4);
}

return var4;
}
}

public Image setBrightness(Image var1, double var2) {
if (var2 == 0.0D) {
return var1;
} else {
int var4 = this.getWidth(var1);
int var5 = this.getHeight(var1);
int[] var6 = this.getPixels(var1, var4, var5);
return this.createImage(this.setBrightness(var6, var2), var4, var5);
}
}

public int[] setBrightness(int[] var1, double var2) {
int var4 = var1.length;
int[] var8 = new int[var4];

for (int var9 = 0; var9 < var4; ++var9) {
int var5 = (var1[var9] & 16711680) >> 16;
int var6 = (var1[var9] & '\uff00') >> 8;
int var7 = var1[var9] & 255;
if (var2 > 0.0D) {
var5 = (int) ((double) var5 + (255.0D - (double) var5) * var2 + 0.5D);
var6 = (int) ((double) var6 + (255.0D - (double) var6) * var2 + 0.5D);
var7 = (int) ((double) var7 + (255.0D - (double) var7) * var2 + 0.5D);
} else {
var5 = (int) ((double) var5 + (double) var5 * var2 + 0.5D);
var6 = (int) ((double) var6 + (double) var6 * var2 + 0.5D);
var7 = (int) ((double) var7 + (double) var7 * var2 + 0.5D);
}

var8[var9] = (int) (((long) var1[var9] & 4278190080L) + (long) (var5 << 16) + (long) (var6 << 8) + (long) var7);
}

return var8;
}

public Image setTransparency(Image var1, double var2) {
int var4 = this.getWidth(var1);
int var5 = this.getHeight(var1);
int[] var6 = this.getPixels(var1, var4, var5);
return this.createImage(this.setTransparency(var6, var2), var4, var5);
}

public int[] setTransparency(int[] var1, double var2) {
int var4 = var1.length;
int[] var5 = new int[var4];

for (int var9 = 0; var9 < var4; ++var9) {
long var6 = ((long) var1[var9] & 4278190080L) >> 24;
if (var6 == 0L) {
var5[var9] = var1[var9];
} else {
int var8 = (int) ((double) var6 * var2 + 0.5D);
var5[var9] = (int) ((long) (var8 << 24) + ((long) var1[var9] & 16777215L));
}
}

return var5;
}

public Image getAlphaMultipliedImage(Image var1, double var2) {
int var4 = this.getWidth(var1);
int var5 = this.getHeight(var1);
Expand Down Expand Up @@ -415,40 +288,8 @@ public int[] multiplyAlpha(int[] var1, double var2) {

public void destroy() {
this.imageTracker.removeAllImageResources();
Enumeration var1 = this.imagesTable.elements();

while (var1.hasMoreElements()) {
try {
Object var2 = var1.nextElement();
int var4;
if (var2 instanceof Image[]) {
Image[] var7 = (Image[]) ((Image[]) var2);

for (var4 = 0; var4 < var7.length; ++var4) {
var7[var4].flush();
var7[var4] = null;
}
} else if (var2 instanceof Image[][]) {
Image[][] var3 = (Image[][]) ((Image[][]) var2);

for (var4 = 0; var4 < var3.length; ++var4) {
for (int var5 = 0; var5 < var3[var4].length; ++var5) {
var3[var4][var5].flush();
var3[var4][var5] = null;
}
}
}
} catch (Exception var6) {
;
}
}

this.imagesTable.clear();
this.imagesTable = null;
this.aHashtable1357.clear();
this.aHashtable1357 = null;
this.imageAliases = (String[][]) null;
this.codebaseURL = null;
this.imageAliases.clear();
this.imageAliases = null;
this.applet = null;
}

Expand Down Expand Up @@ -476,36 +317,11 @@ protected Image method1595(String var1) {
return this.imageTracker.method1632(var1);
}

private String method1596(String var1) {
int var2 = var1.lastIndexOf(46);
if (var2 == -1) {
var2 = var1.length();
}

if (this.validImageDir) {
return var1.substring(0, var2);
} else {
int var3 = var1.lastIndexOf(47);
return var1.substring(var3 + 1, var2);
}
}

private String method1597(String var1) {
if (this.imageAliases != null) {
int var2 = this.imageAliases.length;

for (int var3 = 0; var3 < var2; ++var3) {
if (var1.equals(this.imageAliases[var3][0])) {
return this.imageAliases[var3][1];
}
}
}

return var1;
private String removeExtension(String fileName) {
return fileName.substring(0, fileName.lastIndexOf('.'));
}

private String getAlias(String var1) {
String var2 = (String) ((String) this.aHashtable1357.get(var1));
return var2 != null ? var2 : var1;
return this.imageAliases.getOrDefault(var1, var1);
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SoundManager(Applet var1, boolean var2, boolean var3) {
this.anURL1486 = var1.getCodeBase();

try {
this.anURL1486 = new URL(this.anURL1486, "sound/");
this.anURL1486 = new URL(this.anURL1486, "src/main/resources/sound/");
} catch (MalformedURLException var5) {
;
}
Expand Down Expand Up @@ -214,7 +214,7 @@ private void method1688() {

try {
if (FileUtil.isFileUrl(var1)) {
var1 = new URL(var1, FileUtil.RESOURCE_DIR + "sound/");
var1 = new URL(var1, FileUtil.RESOURCE_DIR + "src/main/resources/sound/");
} else {
var1 = new URL(var1, "../Shared/sound/");
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8951b3a

Please sign in to comment.