v0.8.0: improved build files and moved various files to better locations

This commit is contained in:
Evan Debenham
2019-10-26 13:21:05 -04:00
parent 4aa6b1788c
commit 8117d4ea2f
159 changed files with 15 additions and 57 deletions
@@ -0,0 +1,81 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.desktop;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.watabou.noosa.Game;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.swing.JOptionPane;
public class DesktopLauncher {
public static void main (String[] arg) {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
pw.flush();
JOptionPane.showMessageDialog(null, "Shattered Pixel Dungeon has crashed, sorry about that!\n\n" +
"If you could, please email this error message to me and I'll get it fixed (Evan@ShatteredPixel.com):\n\n" +
sw.toString(), "Game Crash!", JOptionPane.ERROR_MESSAGE);
Gdx.app.exit();
}
});
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.width = 1920;
config.height = 1080;
//uncapped (but vsynced) framerate when focused, paused when not focused
config.foregroundFPS = 0;
config.backgroundFPS = -1;
//TODO rather than hardcoding these values when running debug
// it would be nice to be able to fetch them from gradle in some way
config.title = DesktopLauncher.class.getPackage().getSpecificationTitle();
if (config.title == null) {
config.title = "ShatteredPD INDEV";
}
Game.version = DesktopLauncher.class.getPackage().getSpecificationVersion();
if (Game.version == null) {
Game.version = "0.7.5e-INDEV";
}
try {
Game.versionCode = Integer.parseInt(DesktopLauncher.class.getPackage().getImplementationVersion());
} catch (NumberFormatException e) {
Game.versionCode = 382;
}
new LwjglApplication(new ShatteredPixelDungeon(new DesktopPlatformSupport()), config);
}
}
@@ -0,0 +1,199 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.desktop;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.PixmapPacker;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.watabou.noosa.Game;
import com.watabou.utils.PlatformSupport;
import java.util.HashMap;
import java.util.regex.Pattern;
public class DesktopPlatformSupport extends PlatformSupport {
@Override
public void updateDisplaySize() {
}
@Override
public void updateSystemUI() {
}
@Override
public void promptTextInput(String title, String hintText, int maxLen, boolean multiLine, String posTxt, String negTxt, TextCallback callback) {
}
private int pageSize;
private PixmapPacker packer;
private boolean systemfont;
//custom pixel font, for use with Latin and Cyrillic languages
private static FreeTypeFontGenerator basicFontGenerator;
private static HashMap<Integer, BitmapFont> basicFonts = new HashMap<>();
//droid sans fallback, for asian fonts
private static FreeTypeFontGenerator asianFontGenerator;
private static HashMap<Integer, BitmapFont> asianFonts = new HashMap<>();
private static HashMap<FreeTypeFontGenerator, HashMap<Integer, BitmapFont>> fonts;
@Override
public void setupFontGenerators(int pageSize, boolean systemfont) {
//don't bother doing anything if nothing has changed
if (fonts != null && this.pageSize == pageSize && this.systemfont == systemfont){
return;
}
this.pageSize = pageSize;
this.systemfont = systemfont;
if (fonts != null){
for (FreeTypeFontGenerator generator : fonts.keySet()){
for (BitmapFont f : fonts.get(generator).values()){
f.dispose();
}
fonts.get(generator).clear();
generator.dispose();
}
fonts.clear();
if (packer != null){
for (PixmapPacker.Page p : packer.getPages()){
p.getTexture().dispose();
}
packer.dispose();
}
}
fonts = new HashMap<>();
basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("pixel_font.ttf"));
asianFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("DroidSansFallback.ttf"));
fonts.put(basicFontGenerator, basicFonts);
fonts.put(asianFontGenerator, asianFonts);
packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA8888, 1, false);
}
@Override
public void resetGenerators() {
for (FreeTypeFontGenerator generator : fonts.keySet()){
for (BitmapFont f : fonts.get(generator).values()){
f.dispose();
}
fonts.get(generator).clear();
generator.dispose();
}
fonts.clear();
if (packer != null){
for (PixmapPacker.Page p : packer.getPages()){
p.getTexture().dispose();
}
packer.dispose();
}
fonts = null;
setupFontGenerators(pageSize, systemfont);
}
private static Pattern asianMatcher = Pattern.compile("\\p{InHangul_Syllables}|" +
"\\p{InCJK_Unified_Ideographs}|\\p{InCJK_Symbols_and_Punctuation}|\\p{InHalfwidth_and_Fullwidth_Forms}|" +
"\\p{InHiragana}|\\p{InKatakana}");
private static FreeTypeFontGenerator getGeneratorForString( String input ){
if (asianMatcher.matcher(input).find()){
return asianFontGenerator;
} else {
return basicFontGenerator;
}
}
@Override
public BitmapFont getFont(int size, String text) {
FreeTypeFontGenerator generator = getGeneratorForString(text);
if (generator == null){
return null;
}
if (!fonts.get(generator).containsKey(size)) {
FreeTypeFontGenerator.FreeTypeFontParameter parameters = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameters.size = size;
parameters.flip = true;
parameters.borderWidth = parameters.size / 10f;
parameters.renderCount = 3;
parameters.hinting = FreeTypeFontGenerator.Hinting.None;
parameters.spaceX = -(int) parameters.borderWidth;
parameters.incremental = true;
if (generator == basicFontGenerator){
//if we're using latin/cyrillic, we can safely pre-generate some common letters
//(we define common as >4% frequency in english)
parameters.characters = "etaoinshrdl";
} else {
parameters.characters = "";
}
parameters.packer = packer;
try {
BitmapFont font = generator.generateFont(parameters);
font.getData().missingGlyph = font.getData().getGlyph('');
fonts.get(generator).put(size, font);
} catch ( Exception e ){
Game.reportException(e);
return null;
}
}
return fonts.get(generator).get(size);
}
//splits on newlines, underscores, and chinese/japaneses characters
private Pattern regularsplitter = Pattern.compile(
"(?<=\n)|(?=\n)|(?<=_)|(?=_)|" +
"(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" +
"(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" +
"(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" +
"(?<=\\p{InCJK_Symbols_and_Punctuation})|(?=\\p{InCJK_Symbols_and_Punctuation})");
//additionally splits on words, so that each word can be arranged individually
private Pattern regularsplitterMultiline = Pattern.compile(
"(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|" +
"(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" +
"(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" +
"(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" +
"(?<=\\p{InCJK_Symbols_and_Punctuation})|(?=\\p{InCJK_Symbols_and_Punctuation})");
@Override
public String[] splitforTextBlock(String text, boolean multiline) {
if (multiline) {
return regularsplitterMultiline.split(text);
} else {
return regularsplitter.split(text);
}
}
}