com.badlogic.gdx.backends.lwjgl.LwjglFiles Java Examples

The following examples show how to use com.badlogic.gdx.backends.lwjgl.LwjglFiles. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TiledObjectTemplateTest.java    From mini2Dx with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void loadMap() throws TiledException {
	Gdx.files = new LwjglFiles();
	Mdx.files = new LibgdxFiles();
	Mdx.graphics = new LibgdxGraphicsUtils();
	Mdx.platformUtils = new LibgdxPlatformUtils() {
		@Override
		public boolean isGameThread() {
			return false;
		}
	};

	FileHandle file = Mdx.files.internal(Thread.currentThread().getContextClassLoader()
			.getResource("orthogonal_tsx.tmx").getFile().replaceAll("%20", " "));
	tiledMap = new TiledMap(file, false);
}
 
Example #2
Source File: TiledMapTest.java    From mini2Dx with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void loadMap() throws TiledException {
	Gdx.files = new LwjglFiles();
	Mdx.files = new LibgdxFiles();
	Mdx.graphics = new LibgdxGraphicsUtils();
	Mdx.platformUtils = new LibgdxPlatformUtils() {
		@Override
		public boolean isGameThread() {
			return false;
		}
	};

	FileHandle file = Mdx.files.internal(Thread.currentThread().getContextClassLoader()
			.getResource("orthogonal.tmx").getFile().replaceAll("%20", " "));
	tiledMap = new TiledMap(file, false);
}
 
Example #3
Source File: TiledCollisionMapperTest.java    From mini2Dx with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void loadMap() throws TiledException {
	Gdx.files = new LwjglFiles();
	Mdx.files = new LibgdxFiles();
	Mdx.graphics = new LibgdxGraphicsUtils();
	Mdx.locks = new JvmLocks();
	Mdx.platformUtils = new LibgdxPlatformUtils() {
		@Override
		public boolean isGameThread() {
			return false;
		}
	};

	FileHandle file = Mdx.files.internal(Thread.currentThread().getContextClassLoader()
			.getResource("orthogonal.tmx").getFile().replaceAll("%20", " "));
	tiledMap = new TiledMap(file, false);
}
 
Example #4
Source File: UiThemeWriter.java    From mini2Dx with Apache License 2.0 6 votes vote down vote up
public static void main(String [] args) {
	Gdx.files = new LwjglFiles();
	Mdx.reflect = new JvmReflection();
	Mdx.files = new LibgdxFiles();
	
	UiTheme theme = new UiTheme();
	theme.setId(UiTheme.DEFAULT_STYLE_ID);
	theme.putFont("default", "example.ttf");
	
	ButtonStyleRuleset buttonRuleset = new ButtonStyleRuleset();
	ButtonStyleRule styleRule = new ButtonStyleRule();
	styleRule.setActionBackground("");
	styleRule.setDisabledBackground("");
	styleRule.setHoverBackground("");
	styleRule.setBackground("");
	
	buttonRuleset.putStyleRule(ScreenSize.XS, styleRule);
	theme.putButtonStyleRuleset(UiTheme.DEFAULT_STYLE_ID, buttonRuleset);
	
	try {
		Mdx.json.toJson(Mdx.files.external("/tmp/theme.json"), theme);
	} catch (SerializationException e) {
		e.printStackTrace();
	}
}
 
Example #5
Source File: Generator.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
private static void renamePrefixes(String path, String prefix, String newPrefix) {
    Files files = new LwjglFiles();
    for (FileHandle fileHandle : files.local(path).list()) {
        if (fileHandle.name().startsWith(prefix)) {
            String newName = newPrefix + fileHandle.name().substring(prefix.length());
            println(fileHandle.name() + " -> " + newName);
            fileHandle.sibling(newName).write(fileHandle.read(), false);
            fileHandle.delete();
        }
    }
}
 
Example #6
Source File: LoggerUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public static File setupExternalFileOutput() {
    try {
        Date currentDate = new Date();
        long currentTime = currentDate.getTime();
        String fileName = new SimpleDateFormat("yyMMddhhmm").format(currentDate) + ".log";
        File logFile = new File(LwjglFiles.externalPath + AppConstants.LOGS_DIR + File.separator + fileName);
        logFile.getParentFile().mkdirs();
        for (File oldLogFile : logFile.getParentFile().listFiles((FileFilter)new SuffixFileFilter(LOG_FILE_EXTENSION))) {
            long lastModified = oldLogFile.lastModified();
            if (currentTime - lastModified > EXPIRATION_THRESHOLD) {
                try { oldLogFile.delete(); } catch (SecurityException ignored) { }
            }
        }
        FileOutputStream logFileOutputStream = new FileOutputStream(logFile);
        System.setOut(new PrintStream(new OutputStreamMultiplexer(
                new FileOutputStream(FileDescriptor.out),
                logFileOutputStream
        )));
        System.setErr(new PrintStream(new OutputStreamMultiplexer(
                new FileOutputStream(FileDescriptor.err),
                logFileOutputStream
        )));
        System.out.println("Version: " + AppConstants.version);
        System.out.println("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch"));
        System.out.println("JRE: " + System.getProperty("java.version") + " " + System.getProperty("java.vendor"));
        System.out.println("External log file: " + logFile.getAbsolutePath());
        return logFile;
    } catch (FileNotFoundException e) {
        System.err.println("Can't setup logging to external file.");
        e.printStackTrace();
        return null;
    }
}
 
Example #7
Source File: WindowParamsPersistingApplicationWrapper.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
private void loadWindowParams(LwjglApplicationConfiguration configuration) {
    FileHandle file = new FileHandle(LwjglFiles.externalPath + configuration.preferencesDirectory + "/window_params.xml");
    if (!file.exists()) return;

    DisplayMode displayMode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode();
    int screenWidth = displayMode.getWidth();
    int screenHeight = displayMode.getHeight();

    Preferences prefs = new LwjglPreferences(file);
    configuration.width = MathUtils.clamp(prefs.getInteger("width", configuration.width), 320, screenWidth);
    configuration.height = MathUtils.clamp(prefs.getInteger("height", configuration.height), 320, screenHeight);
    configuration.x = MathUtils.clamp(prefs.getInteger("x", configuration.x), 0, screenWidth - configuration.width);
    configuration.y = MathUtils.clamp(prefs.getInteger("y", configuration.y), 0, screenHeight - configuration.height);
}
 
Example #8
Source File: DesktopComponentScannerTest.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	Gdx.files = new LwjglFiles();
	Mdx.files = new LibgdxFiles();
	Mdx.reflect = new JvmReflection();
	Mdx.platform = GameWrapper.getPlatform();
	componentScanner = new DesktopComponentScanner();
}
 
Example #9
Source File: DesktopDependencyInjectionTest.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	Gdx.files = new LwjglFiles();
	Mdx.files = new LibgdxFiles();
	Mdx.reflect = new JvmReflection();
	Mdx.platform = GameWrapper.getPlatform();
	Mdx.di = new DependencyInjection(new DesktopComponentScanner());
	Mdx.locks = new JvmLocks();
	Mdx.executor = new LibgdxTaskExecutor(2);
}
 
Example #10
Source File: DesktopPlayerDataTest.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@Before
  public void setUp() {
      Gdx.files = new LwjglFiles();
Mdx.files = new LibgdxFiles();
      Mdx.reflect = new JvmReflection();
      Mdx.platform = GameWrapper.getPlatform();
      Mdx.di = new DependencyInjection(new DesktopComponentScanner());
      desktopData = new DesktopPlayerData(TEST_IDENTIFIER);
      
      createTestObjects();
  }
 
Example #11
Source File: SharedParserTiledMapTest.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@Test
public void testSharedParser() throws TiledException {
	Gdx.files = new LwjglFiles();
	Mdx.files = new LibgdxFiles();
	Mdx.graphics = new LibgdxGraphicsUtils();
	Mdx.platformUtils = new LibgdxPlatformUtils() {
		@Override
		public boolean isGameThread() {
			return false;
		}
	};

	TiledParser parser = new TiledParser();

	FileHandle orthogonalFile = Mdx.files.internal(Thread.currentThread().getContextClassLoader()
			.getResource("orthogonal.tmx").getFile().replaceAll("%20", " "));
	FileHandle orthogonalTsxFile = Mdx.files.internal(Thread.currentThread().getContextClassLoader()
			.getResource("orthogonal_tsx.tmx").getFile().replaceAll("%20", " "));
	FileHandle isometricFile = Mdx.files.internal(Thread.currentThread().getContextClassLoader()
			.getResource("isometric.tmx").getFile().replaceAll("%20", " "));

	TiledMap orthogonalTiledMap = new TiledMap(parser, orthogonalFile, false);
	TiledMap orthogonalTsxTiledMap = new TiledMap(parser, orthogonalTsxFile, false);
	TiledMap isometricTiledMap = new TiledMap(parser, isometricFile, false);

	Assert.assertEquals(Orientation.ORTHOGONAL, orthogonalTiledMap.getOrientation());
	Assert.assertEquals(Orientation.ISOMETRIC, isometricTiledMap.getOrientation());

	Assert.assertEquals(Orientation.ORTHOGONAL, orthogonalTsxTiledMap.getOrientation());
	Assert.assertEquals(1, orthogonalTsxTiledMap.getTilesets().size);
}
 
Example #12
Source File: AotWriter.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
public static void main(String [] args) throws IOException {
	Mdx.reflect = new JvmReflection();
	Gdx.files = new LwjglFiles();
	Mdx.files = new LibgdxFiles();

	AotSerializationData.registerClass(UiTheme.class);
	AotSerializationData.registerClass(AnimatedImage.class);
	AotSerializationData.registerClass(Button.class);
	AotSerializationData.registerClass(Checkbox.class);
	AotSerializationData.registerClass(Container.class);
	AotSerializationData.registerClass(CustomUiElement.class);
	AotSerializationData.registerClass(Div.class);
	AotSerializationData.registerClass(FlexRow.class);
	AotSerializationData.registerClass(Image.class);
	AotSerializationData.registerClass(ImageButton.class);
	AotSerializationData.registerClass(Label.class);
	AotSerializationData.registerClass(ParentUiElement.class);
	AotSerializationData.registerClass(ProgressBar.class);
	AotSerializationData.registerClass(RadioButton.class);
	AotSerializationData.registerClass(ScrollBox.class);
	AotSerializationData.registerClass(Select.class);
	AotSerializationData.registerClass(Slider.class);
	AotSerializationData.registerClass(Tab.class);
	AotSerializationData.registerClass(TabButton.class);
	AotSerializationData.registerClass(TabView.class);
	AotSerializationData.registerClass(TextBox.class);
	AotSerializationData.registerClass(TextButton.class);
	AotSerializationData.registerClass(UiElement.class);

	File file = new File("aot-data.txt");
	FileWriter writer = new FileWriter(file);
	AotSerializationData.saveTo(writer);
	writer.close();

	System.out.println("Wrote to " + file.getAbsolutePath());
}
 
Example #13
Source File: PrototypeBeanTest.java    From mini2Dx with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	executorService = Executors.newFixedThreadPool(1);

	Gdx.files = new LwjglFiles();
	Mdx.files = new LibgdxFiles();
	Mdx.reflect = new JvmReflection();
	Mdx.platform = GameWrapper.getPlatform();
	Mdx.di = new DependencyInjection(new DesktopComponentScanner());
	Mdx.executor = new TaskExecutor() {
		@Override
		public void dispose() {

		}

		@Override
		public void update(float delta) {

		}

		@Override
		public void execute(Runnable runnable) {
			executorService.submit(runnable);
		}

		@Override
		public AsyncFuture submit(Runnable runnable) {
			executorService.submit(runnable);
			return null;
		}

		@Override
		public <T> AsyncResult<T> submit(Callable<T> callable) {
			executorService.submit(callable);
			return null;
		}

		@Override
		public void submit(FrameSpreadTask task) {

		}

		@Override
		public void setMaxFrameTasksPerFrame(int max) {

		}
	};


	prototype = new TestPrototypeBean();
	prototype.setIntField(100);

	bean = new PrototypeBean(prototype);
	executorService.submit(bean);
}