mirror of
https://github.com/correl/mage.git
synced 2025-04-11 01:01:05 -09:00
Refactor resource paths and constants:
- delete duplicate consts; - correct paths and it uses; - fix loading icons from user defined dir;
This commit is contained in:
parent
5cda60270c
commit
f400cd5231
7 changed files with 42 additions and 47 deletions
Mage.Client/src/main/java
mage/client
org/mage/plugins/card
constants
images
properties
utils
|
@ -27,6 +27,7 @@
|
||||||
*/
|
*/
|
||||||
package mage.client.constants;
|
package mage.client.constants;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
|
@ -72,18 +73,40 @@ public final class Constants {
|
||||||
|
|
||||||
public static final double SCALE_FACTOR = 0.5;
|
public static final double SCALE_FACTOR = 0.5;
|
||||||
|
|
||||||
public static final String PLUGINS_DIRECTORY = "plugins/";
|
// cards render
|
||||||
|
public static final Rectangle CARD_SIZE_FULL = new Rectangle(101, 149);
|
||||||
|
public static final Rectangle THUMBNAIL_SIZE_FULL = new Rectangle(102, 146);
|
||||||
|
|
||||||
public static final String RESOURCE_PATH_MANA_LARGE = IO.imageBaseDir + "symbols" + File.separator + "large";
|
// resources - symbols
|
||||||
public static final String RESOURCE_PATH_MANA_MEDIUM = IO.imageBaseDir + "symbols" + File.separator + "medium";
|
public static final String RESOURCE_PATH_SYMBOLS = File.separator + "symbols";
|
||||||
public static final String RESOURCE_PATH_SET = IO.imageBaseDir + "sets" + File.separator;
|
public static final String RESOURCE_SYMBOL_FOLDER_SMALL = "small";
|
||||||
public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small" + File.separator;
|
public static final String RESOURCE_SYMBOL_FOLDER_MEDIUM = "medium";
|
||||||
public static final String BASE_SOUND_PATH = "sounds" + File.separator;
|
public static final String RESOURCE_SYMBOL_FOLDER_LARGE = "large";
|
||||||
|
public static final String RESOURCE_SYMBOL_FOLDER_SVG = "svg";
|
||||||
|
public enum ResourceSymbolSize {
|
||||||
|
SMALL,
|
||||||
|
MEDIUM,
|
||||||
|
LARGE,
|
||||||
|
SVG
|
||||||
|
}
|
||||||
|
|
||||||
|
// resources - sets
|
||||||
|
public static final String RESOURCE_PATH_SETS = File.separator + "sets";
|
||||||
|
public static final String RESOURCE_SET_FOLDER_SMALL = "small";
|
||||||
|
public static final String RESOURCE_SET_FOLDER_MEDIUM = ""; // empty, medium images laydown in "sets" folder
|
||||||
|
public static final String RESOURCE_SET_FOLDER_SVG = "svg";
|
||||||
|
public enum ResourceSetSize {
|
||||||
|
SMALL,
|
||||||
|
MEDIUM,
|
||||||
|
SVG
|
||||||
|
}
|
||||||
|
|
||||||
|
// sound
|
||||||
|
public static final String BASE_SOUND_PATH = "sounds" + File.separator; // TODO: check path with File.separator
|
||||||
public static final String BASE_MUSICS_PATH = "music" + File.separator;
|
public static final String BASE_MUSICS_PATH = "music" + File.separator;
|
||||||
|
|
||||||
public interface IO {
|
public interface IO {
|
||||||
|
String DEFAULT_IMAGES_DIR = "plugins" + File.separator + "images" + File.separator;
|
||||||
String imageBaseDir = "plugins" + File.separator + "images" + File.separator;
|
|
||||||
String IMAGE_PROPERTIES_FILE = "image.url.properties";
|
String IMAGE_PROPERTIES_FILE = "image.url.properties";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.mage.plugins.theme.ThemePluginImpl;
|
||||||
|
|
||||||
public enum Plugins implements MagePlugins {
|
public enum Plugins implements MagePlugins {
|
||||||
instance;
|
instance;
|
||||||
public static final String PLUGINS_DIRECTORY = "plugins/";
|
public static final String PLUGINS_DIRECTORY = File.separator + "plugins";
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(Plugins.class);
|
private static final Logger LOGGER = Logger.getLogger(Plugins.class);
|
||||||
private static PluginManager pm;
|
private static PluginManager pm;
|
||||||
|
@ -50,7 +50,7 @@ public enum Plugins implements MagePlugins {
|
||||||
public void loadPlugins() {
|
public void loadPlugins() {
|
||||||
LOGGER.info("Loading plugins...");
|
LOGGER.info("Loading plugins...");
|
||||||
pm = PluginManagerFactory.createPluginManager();
|
pm = PluginManagerFactory.createPluginManager();
|
||||||
pm.addPluginsFrom(new File(PLUGINS_DIRECTORY).toURI());
|
pm.addPluginsFrom(new File(PLUGINS_DIRECTORY + File.separator).toURI());
|
||||||
this.cardPlugin = new CardPluginImpl();
|
this.cardPlugin = new CardPluginImpl();
|
||||||
this.counterPlugin = pm.getPlugin(CounterPlugin.class);
|
this.counterPlugin = pm.getPlugin(CounterPlugin.class);
|
||||||
this.themePlugin = new ThemePluginImpl();
|
this.themePlugin = new ThemePluginImpl();
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package org.mage.plugins.card.constants;
|
|
||||||
|
|
||||||
import java.awt.Rectangle;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public final class Constants {
|
|
||||||
|
|
||||||
public static final String RESOURCE_PATH_MANA_SMALL = File.separator + "symbols" + File.separator + "small";
|
|
||||||
public static final String RESOURCE_PATH_MANA_LARGE = File.separator + "symbols" + File.separator + "large";
|
|
||||||
public static final String RESOURCE_PATH_MANA_MEDIUM = File.separator + "symbols" + File.separator + "medium";
|
|
||||||
public static final String RESOURCE_PATH_MANA_SVG = File.separator + "symbols" + File.separator + "svg";
|
|
||||||
|
|
||||||
public static final String RESOURCE_PATH_SET = File.separator + "sets";
|
|
||||||
public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small";
|
|
||||||
|
|
||||||
public static final Rectangle CARD_SIZE_FULL = new Rectangle(101, 149);
|
|
||||||
public static final Rectangle THUMBNAIL_SIZE_FULL = new Rectangle(102, 146);
|
|
||||||
|
|
||||||
public interface IO {
|
|
||||||
String imageBaseDir = "plugins" + File.separator + "images";
|
|
||||||
String IMAGE_PROPERTIES_FILE = "image.url.properties";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String CARD_IMAGE_PATH_TEMPLATE = '.' + File.separator + "plugins" + File.separator + "images/{set}/{name}.{collector}.full.jpg";
|
|
||||||
}
|
|
|
@ -31,9 +31,6 @@ import mage.client.constants.Constants;
|
||||||
import mage.client.dialog.PreferencesDialog;
|
import mage.client.dialog.PreferencesDialog;
|
||||||
import mage.client.util.sets.ConstructedFormats;
|
import mage.client.util.sets.ConstructedFormats;
|
||||||
import mage.remote.Connection;
|
import mage.remote.Connection;
|
||||||
import static mage.remote.Connection.ProxyType.HTTP;
|
|
||||||
import static mage.remote.Connection.ProxyType.NONE;
|
|
||||||
import static mage.remote.Connection.ProxyType.SOCKS;
|
|
||||||
import net.java.truevfs.access.TFile;
|
import net.java.truevfs.access.TFile;
|
||||||
import net.java.truevfs.access.TFileOutputStream;
|
import net.java.truevfs.access.TFileOutputStream;
|
||||||
import net.java.truevfs.access.TVFS;
|
import net.java.truevfs.access.TVFS;
|
||||||
|
@ -544,7 +541,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
public void run() {
|
public void run() {
|
||||||
this.cardIndex = 0;
|
this.cardIndex = 0;
|
||||||
|
|
||||||
File base = new File(Constants.IO.imageBaseDir);
|
File base = new File(Constants.IO.DEFAULT_IMAGES_DIR);
|
||||||
if (!base.exists()) {
|
if (!base.exists()) {
|
||||||
base.mkdir();
|
base.mkdir();
|
||||||
}
|
}
|
||||||
|
@ -682,7 +679,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
File temporaryFile = null;
|
File temporaryFile = null;
|
||||||
TFile outputFile = null;
|
TFile outputFile = null;
|
||||||
try {
|
try {
|
||||||
filePath.append(Constants.IO.imageBaseDir);
|
filePath.append(Constants.IO.DEFAULT_IMAGES_DIR);
|
||||||
if (!useSpecifiedPaths && card != null) {
|
if (!useSpecifiedPaths && card != null) {
|
||||||
filePath.append(card.hashCode()).append('.').append(card.getName().replace(":", "").replace("//", "-")).append(".jpg");
|
filePath.append(card.hashCode()).append('.').append(card.getName().replace(":", "").replace("//", "-")).append(".jpg");
|
||||||
temporaryFile = new File(filePath.toString());
|
temporaryFile = new File(filePath.toString());
|
||||||
|
@ -694,7 +691,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
} else if (card != null) {
|
} else if (card != null) {
|
||||||
imagePath = CardImageUtils.getImageBasePath() + actualFilename;
|
imagePath = CardImageUtils.getImageBasePath() + actualFilename;
|
||||||
} else {
|
} else {
|
||||||
imagePath = Constants.IO.imageBaseDir;
|
imagePath = Constants.IO.DEFAULT_IMAGES_DIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
String tmpFile = filePath + "temporary" + actualFilename;
|
String tmpFile = filePath + "temporary" + actualFilename;
|
||||||
|
@ -823,7 +820,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||||
iwp.setCompressionQuality(0.96f);
|
iwp.setCompressionQuality(0.96f);
|
||||||
|
|
||||||
File tempFile = new File(Constants.IO.imageBaseDir + File.separator + image.hashCode() + file.getName());
|
File tempFile = new File(Constants.IO.DEFAULT_IMAGES_DIR + File.separator + image.hashCode() + file.getName());
|
||||||
FileImageOutputStream output = new FileImageOutputStream(tempFile);
|
FileImageOutputStream output = new FileImageOutputStream(tempFile);
|
||||||
writer.setOutput(output);
|
writer.setOutput(output);
|
||||||
IIOImage image2 = new IIOImage(image, null, null);
|
IIOImage image2 = new IIOImage(image, null, null);
|
||||||
|
|
|
@ -20,9 +20,9 @@ import net.java.truevfs.access.TFile;
|
||||||
import net.java.truevfs.access.TFileInputStream;
|
import net.java.truevfs.access.TFileInputStream;
|
||||||
import net.java.truevfs.access.TFileOutputStream;
|
import net.java.truevfs.access.TFileOutputStream;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.mage.plugins.card.constants.Constants;
|
|
||||||
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
|
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
|
||||||
import org.mage.plugins.card.utils.CardImageUtils;
|
import org.mage.plugins.card.utils.CardImageUtils;
|
||||||
|
import mage.client.constants.Constants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class stores ALL card images in a cache with soft values. this means
|
* This class stores ALL card images in a cache with soft values. this means
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import org.mage.plugins.card.constants.Constants;
|
import mage.client.constants.Constants;
|
||||||
|
|
||||||
public class SettingsManager {
|
public class SettingsManager {
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ public final class CardImageUtils {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String set = updateSet(card.getSet(), false).toUpperCase();
|
String set = updateSet(card.getSet(), false).toUpperCase();
|
||||||
String imagesDir = (imagesPath != null ? imagesPath : Constants.IO.imageBaseDir);
|
String imagesDir = (imagesPath != null ? imagesPath : Constants.IO.DEFAULT_IMAGES_DIR);
|
||||||
if (card.isToken()) {
|
if (card.isToken()) {
|
||||||
return buildTokenPath(imagesDir, set);
|
return buildTokenPath(imagesDir, set);
|
||||||
} else {
|
} else {
|
||||||
|
@ -136,7 +136,7 @@ public final class CardImageUtils {
|
||||||
|
|
||||||
public static String getImageBasePath() {
|
public static String getImageBasePath() {
|
||||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||||
String imagesPath = Objects.equals(useDefault, "true") ? Constants.IO.imageBaseDir : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
String imagesPath = Objects.equals(useDefault, "true") ? Constants.IO.DEFAULT_IMAGES_DIR : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||||
|
|
||||||
if (imagesPath != null && !imagesPath.endsWith(TFile.separator)) {
|
if (imagesPath != null && !imagesPath.endsWith(TFile.separator)) {
|
||||||
imagesPath += TFile.separator;
|
imagesPath += TFile.separator;
|
||||||
|
@ -206,7 +206,7 @@ public final class CardImageUtils {
|
||||||
|
|
||||||
public static String generateFaceImagePath(String cardname, String set) {
|
public static String generateFaceImagePath(String cardname, String set) {
|
||||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||||
String imagesPath = Objects.equals(useDefault, "true") ? Constants.IO.imageBaseDir : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
String imagesPath = Objects.equals(useDefault, "true") ? Constants.IO.DEFAULT_IMAGES_DIR : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||||
String imageDir = imagesPath;
|
String imageDir = imagesPath;
|
||||||
String imageName = set + TFile.separator + cardname + ".jpg";
|
String imageName = set + TFile.separator + cardname + ".jpg";
|
||||||
return imageDir + TFile.separator + "FACE" + TFile.separator + imageName;
|
return imageDir + TFile.separator + "FACE" + TFile.separator + imageName;
|
||||||
|
|
Loading…
Add table
Reference in a new issue