The story of making a game launcher with automatic loading function [Java]

1.First of all

I belong to a club that makes games at university. Since the number of people who know the specifications of the game launcher (hereinafter, the game launcher is sometimes called the launcher) that has been used for exhibiting games at school festivals for many years has decreased, I tried to recreate it from scratch. It was. There are various things that I couldn't make in time, but I would like to talk about them because they have taken shape.   This article doesn't really touch on the design side of the launcher. ** I will mainly talk about how to automatically load, the folder structure of data, and the difficult points. ** I wish I could explain it in an easy-to-understand manner even if the language I am trying to create is not Java.

スクリーンショット 2019-11-11 22.01.36.png スクリーンショット 2019-11-11 22.01.44.png ~~ A nice header was pasted in the blank part on the day, but for some reason I will hide it ;; ~~

2. Things to consider and prepare before you start making a launcher

・ For Java

-IDEs such as Eclipse -Java runtime environment In Java, a Jar file is created when a Jar executable file for application is generated. The latest execution environment (jdk or jre) must be set in order to start the Jar file. It is troublesome because the setting is required even on the computer that launches the launcher. Also, use the framework to keep your design clean! Please refer to: https://www.sejuku.net/blog/60411

・ For other languages

It's basically the same as Java. Integrated development environment IDE and execution environment for its language. And you have to check in advance whether it works on a computer that works properly when it becomes a launcher. Also, you will need to check from the program whether the exe file etc. works properly. Search for "OOO GUI" etc. to see if you can create the design you want.

3. To make a good launcher

Let's think about the necessary functions in advance. For example, in the case of my launcher ・ Like function ・ Fixed phrase function ・ A function to preferentially display works that have not been played much yet ・ Automatic loading function for games, etc. (Actually, it also supports videos, etc.) Especially for the last part, I thought it would be nice if not only I could update the launcher but everyone could update it by looking at the specifications.

4. Folder structure & read preparation

I will introduce the folder structure of my launcher. Let's think about it properly because it is a launcher of the automatic loading function.

project  ├src  ├data │ └ images (images used for launcher, etc.) │ └ logs (folder for saving the number of likes and play time of works)  └ExhibitionDatas    └Games │ └ Game data    └Graphics └ Video data, etc.

スクリーンショット 2019-11-16 8.24.35.png

In my launcher, I used a file called launcher_config.ini (property file in java) to explain the work on the launcher and how to operate it. Specifically, it looks like the following.

スクリーンショット 2019-11-16 8.21.44.png スクリーンショット 2019-11-14 4.42.59.png

The ini file is basically in text format, "Name" = value It's like writing it like a text file. With this, you can manipulate the output on the launcher by tweaking this text without having to mess with the contents of the launcher. If you ask someone who wants to put a game in the launcher to create this ini file, you will be able to play the game on the launcher!

スクリーンショット 2019-11-14 4.58.52.png

5. Flow until the launcher can execute the game

First of all, the prepared class ・ Game data class (class that saves the contents of the ini file almost as it is) ・ Game data manager class (class that manages all game data classes) Required functions etc. ・ Function to read ini file Reference: https://qiita.com/motoki1990/items/2b643ea854624b09712c ・ File search function is.

qiita.java


private ArrayList<String> fileSearch(String path, String fileName){
        File dir = new File(path);
        File files[] = dir.listFiles();
        for(int i=0; i<files.length; i++){
            if(files[i].isDirectory()){  //Recursion for directories
                fileSearch(path+"/"+files[i].getName(), fileName);
            }else{
                if(file_name.equals(fileName)){  //Output if the specified file is found
                	resultPaths.add(dir.getAbsolutePath()+"/");
                }
            }
        }
        return resultPaths;
    }

First, pass the folder determined by the file search function (ExhibitionData because we want to read the game data this time) and the name of the ini file (launcher_config.ini in my case) to the file search function. ↓ The path to the ini file will be returned, and the game data manager class will use it. Put the data of the obtained path file in all game data classes. At this time, use the function that reads the ini file ↓ Launcher launched ↓ If the action to start the game is taken, the game data manager will Read and execute the path to the executable file of the game data class of the game to be started ↓ Launcher does not process while the game is running

Is the main flow. You may be able to execute the executable in various ways in java In the case of I, I used a standard Java library called ProcessingBuilder. In a nutshell, you will be able to do what you can with cmd. Therefore, you can execute it by using this and passing the path of the game executable file as an argument. Since ProcessingBuilder always manages whether it is running or not, you can set the launcher not to work during that time (convenient!)

6. Where it gets stuck

At first, there were some that could be done using Processing Builder and some that could not. I did not know the cause, but if you just type the path to the executable file, you can execute it with cmd In processingBuilder, if you first move to the file where the executable file exists and then enter the name of the executable file It seems that it can be executed. In particular $ asdf / test / hogehoge / game.exe (← Processing Builder bugs) ↓ $ cd asdf/test/hogehoge $ game.exe It's like that. If anyone has the same content, please try it.

7. Finally

that's all, It was the first post. From the next time, I will do my best to write it a little more concisely. If you have any questions, please do.

Sites that have been very helpful: https://qiita.com/massoumen/items/66d26b08333aeae1c0ea

Recommended Posts

The story of making a game launcher with automatic loading function [Java]
The story of making a reverse proxy with ProxyServlet
The story of making dto, dao-like with java, sqlite
Story of making a task management application with swing, java
A story about hitting the League Of Legends API with JAVA
The story of making a communication type Othello game using Scala.
The story of making ordinary Othello in Java
A story packed with the basics of Spring Boot (solved)
[Java version] The story of serialization
The story of building a Java version of Minecraft server with GCP (and also set a whitelist)
The basics of the process of making a call with an Android app
The story of the first Rails app refactored with a self-made helper
A story that struggled with the introduction of Web Apple Pay
[Illustration] Finding the sum of coins with a recursive function [Ruby]
The story of writing Java in Emacs
The story of forgetting to close a file in Java and failing
Let's express the result of analyzing Java bytecode with a class diagram
The story of making it possible to build a project that was built by Maven with Ant
A story that I was addicted to twice with the automatic startup setting of Tomcat 8 on CentOS 8
A story that I wanted to write a process equivalent to a while statement with the Stream API of Java8
The story of low-level string comparison in Java
A story about the JDK in the Java 11 era
The story of learning Java in the first programming
The story of making the existing Dockerfile GPU compatible
Measure the size of a folder in Java
The story of making an electronic New Year's card app with Vue.js + Rails
The story of tuning android apps with libGDX
A story about making a Builder that inherits the Builder
Calculate the similarity score of strings with JAVA
A story confirming the implementation of the SendGrid Java library when mail delivery fails
Validate the identity token of a user authenticated with AWS Cognito in Java
[Jackson] A story about converting the return value of BigDecimal type with a custom serializer.
Write a test by implementing the story of Mr. Nabeats in the world with ruby
Let's implement a function to limit the number of access to the API with SpringBoot + Redis
[Java] Cut out a part of the character string with Matcher and regular expression
[Java] The problem that true was returned as a result of comparing Integer with ==
CI the architecture of Java / Kotlin applications with ArchUnit
[Beginner] Create a competitive game with basic Java knowledge
Monitor the internal state of Java programs with Kubernetes
Check the behavior of Java Intrinsic Locks with bpftrace
[Java] When writing the source ... A memorandum of understanding ①
A story about developing ROS called rosjava with java
The story of making Dr. Oakid using LINE BOT
A survey of the Kubernetes native Java framework Quarkus
A story about making catkin_make of rosjava compatible offline
Replace only part of the URL host with java
The story of pushing a Docker container to GitHub Package Registry and Docker Hub with GitHub Actions
A quick explanation of the five types of static in Java
[Beginner] Try to make a simple RPG game with Java ①
20190803_Java & k8s on Azure The story of going to the festival
Check the operation of two roles with a chat application
I want to make a function with kotlin and java!
A note about the seed function of Ruby on Rails
[Java] Simplify the implementation of data history management with Reladomo
Implementation of a math parser with recursive descent parsing (Java)
A story addicted to toString () of Interface proxied with JdkDynamicAopProxy
Explain the benefits of the State pattern with a movie rating
About the behavior when doing a file map with java
The story of pushing Java to Heroku using the BitBucket pipeline
Be sure to compare the result of Java compareTo with 0
[Automatic trading of Bitcoin] A story about operating with Docker on AWS, with 1 TAP ON / OFF & Line notification from Apple Watch on the go