Skip to content
This repository has been archived by the owner on Nov 13, 2022. It is now read-only.

Commit

Permalink
-- Groovy 4 update, fix some commands for flatpak
Browse files Browse the repository at this point in the history
  • Loading branch information
Torbuntu committed Oct 2, 2020
1 parent d8d0df8 commit 5dbe2fc
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 37 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ allprojects {
//Version = 1.0.0-SNAPSHOT //(silly versioning)
appName = 'Leikr'
mini2DxVersion = '2.0.0-alpha.32'
groovyVersion = '3.0.5'
groovyVersion = '4.0.0-alpha-1'
gdxVersion = '1.9.12-SNAPSHOT'
gdxControllersVersion = '2.0.0-SNAPSHOT'
lwjglNatives32 = 'natives-linux-arm32'
Expand All @@ -26,6 +26,7 @@ allprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url "https://jitpack.io" }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
Expand All @@ -50,7 +51,7 @@ project(":core") {

implementation "org.mini2Dx:mini2Dx-core:$mini2DxVersion"
implementation "org.mini2Dx:mini2Dx-tiled:$mini2DxVersion"
implementation "org.codehaus.groovy:groovy:$groovyVersion"
implementation "org.apache.groovy:groovy:$groovyVersion"

// lwjgl3natives:
implementation "org.lwjgl:lwjgl:$lwjglVersion"
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/leikr/GameRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ public boolean checkDirectLaunch() {
}

public String getGamePath() {
return "Programs/" + getGameName();
return programsPath + getGameName();
}

public String getToolPath() {
return "Data/Tools/" + getGameName();
return dataPath + "/Tools/" + getGameName();
}

public String getGameName() {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/leikr/commands/CompileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public String execute(String[] args) {
if (args.length == 1) {
return "[E] Missing - required program name.";
}
if (!Mdx.files.local(runtime.getProgramsPath() + args[1]).exists()) {
if (!Mdx.files.external(runtime.getProgramsPath() + args[1]).exists()) {
return "[E] Program name [" + args[1] + "] not in [Programs] directory.";
}
runtime.setGameName(args[1]);
engineLoader.reset(runtime.getProgramsPath() + args[1]);
// Assumes the Programs/GameTitle/ root directory, so Code is all we need to set the compiler class path
engineLoader.compile("Code", "/Code/Compiled");
return "Compiled project [" + args[1] + "]";
return "[I] Compiled project [" + args[1] + "]";
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/leikr/commands/ExportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ExportCommand(ExportTool exportTool) {
@Override
public String execute(String[] command) {
if (command.length <= 1) {
return "Missing - required name argument.";
return "[E] Missing - required name argument.";
}
if (command[1].equalsIgnoreCase("all")) {
return exportTool.exportAll();
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/leikr/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public String execute(String[] command) {
return "[E] Missing - required program name.";
}
if (!containsName(command[1])) {
return "Program [" + command[1] + "] does not exist in Programs directory.";
return "[E] Program [" + command[1] + "] does not exist in Programs directory.";
}
try {
File f = new File(runtime.getProgramsPath() + command[1]);
Desktop.getDesktop().open(f);
return f.getAbsolutePath();
} catch (IOException ex) {
Logger.getLogger(FindCommand.class.getName()).log(Level.SEVERE, null, ex);
return "Could not find program directory for [" + command[1] + "].";
return "[E] Could not find program directory for [" + command[1] + "].";
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/leikr/commands/InstallCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public InstallCommand(GameRuntime runtime, ExportTool exportTool) {
@Override
public String execute(String[] command) {
if (command.length <= 1) {
return "Missing - required name argument.";
return "[E] Missing - required name argument.";
}
if (command.length == 3) {
return exportTool.importProject(command[1], command[2]);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/leikr/commands/NewProgramCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String execute(String[] command) {
return message;
} catch (IOException ex) {
Logger.getLogger(NewProgramCommand.class.getName()).log(Level.SEVERE, null, ex);
return "New program with name [" + command[1] + "] failed to generate.";
return "[E] New program with name [" + command[1] + "] failed to generate.";
}
}
terminalManager.setNewProgramRunning();
Expand Down
17 changes: 8 additions & 9 deletions core/src/main/java/leikr/commands/PackageCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ public String execute(String[] args) {
try {
Mdx.files.external(runtime.getDeployPath() + programName + "/Programs/").mkdirs();
Mdx.files.external(runtime.getProgramsPath() + programName).copyTo(Mdx.files.external(runtime.getDeployPath() + programName + "/Programs/"));
Mdx.files.external(runtime.getDataPath()).copyTo(Mdx.files.external(runtime.getDeployPath() + programName));
Mdx.files.external(runtime.getBasePath() + "Sys").copyTo(Mdx.files.external(runtime.getDeployPath() + programName));
Mdx.files.external(runtime.getBasePath() + "Leikr").copyTo(Mdx.files.external(runtime.getDeployPath()+ programName));
Mdx.files.external(runtime.getBasePath() + "Leikr.bat").copyTo(Mdx.files.external(runtime.getDeployPath() + programName));
Mdx.files.external(runtime.getBasePath() + "gamecontrollerdb.txt").copyTo(Mdx.files.external(runtime.getDeployPath() + programName));
Mdx.files.external(runtime.getBasePath() + "Leikr.jar").copyTo(Mdx.files.external(runtime.getDeployPath()+ programName));
Mdx.files.local("Data").copyTo(Mdx.files.external(runtime.getDeployPath() + programName));
Mdx.files.local("Sys").copyTo(Mdx.files.external(runtime.getDeployPath() + programName));
Mdx.files.local("Leikr").copyTo(Mdx.files.external(runtime.getDeployPath()+ programName));
Mdx.files.local("Leikr.bat").copyTo(Mdx.files.external(runtime.getDeployPath() + programName));
Mdx.files.local("Leikr.jar").copyTo(Mdx.files.external(runtime.getDeployPath()+ programName));
} catch (Exception ex) {
Logger.getLogger(PackageCommand.class.getName()).log(Level.SEVERE, null, ex);
return "Failed to package and deploy project [" + programName + "]";
return "[E] Failed to package and deploy project [" + programName + "]";
}
Properties outProp = new Properties();
outProp.setProperty("launch_title", programName);
Expand All @@ -83,11 +82,11 @@ public String execute(String[] args) {
outProp.store(stream, "Packaged from Leikr.");
} catch (Exception ex) {
Logger.getLogger(PackageCommand.class.getName()).log(Level.SEVERE, null, ex);
return "Failed to package and deploy project [" + programName + "]";
return "[E] Failed to package and deploy project [" + programName + "]";
}

exportTool.deployPackage(programName);
return "Successfully packaged [" + programName + "]. Check the Deploy directory.";
return "[I] Successfully packaged [" + programName + "]. Check the Deploy directory.";
}

@Override
Expand Down
60 changes: 60 additions & 0 deletions core/src/main/java/leikr/commands/PrintCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2020 tor.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package leikr.commands;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import leikr.GameRuntime;
import org.mini2Dx.core.Mdx;

/**
*
* @author tor
*/
public class PrintCommand extends Command {

private final GameRuntime runtime;

public PrintCommand(GameRuntime runtime) {
super.name = "cat";
this.runtime = runtime;
}

@Override
public String execute(String[] command) {
String adjustedPath = runtime.getProgramsPath() + command[1];
if (command.length <= 1) {
return "[E] Missing - required name argument.";
}
if(!Mdx.files.external(adjustedPath).exists()){
return "[E] File [" + command[1] + "] not found.";
}
try {
return Mdx.files.external(adjustedPath).readString();
} catch (IOException ex) {
Logger.getLogger(PrintCommand.class.getName()).log(Level.SEVERE, null, ex);
return "[E] Failed to print contents of file [" + command[1] + "]";
}

}

@Override
public String help() {
return ">cat [file] \nPrints the contents of a file to the terminal.\nTerminal does not currently scroll contents.";
}

}
4 changes: 2 additions & 2 deletions core/src/main/java/leikr/commands/PrintDirectoryCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private String runLsPrograms() {
out = "";
List<String> titles = new ArrayList<>();

Arrays.asList(Mdx.files.external(runtime.getProgramsPath()).list()).forEach(e -> titles.add(e.nameWithoutExtension()));
Arrays.asList(Mdx.files.external(runtime.getProgramsPath()).list()).forEach(e -> titles.add(e.name()));

titles.stream().sorted().forEach(e -> {
if (Mdx.files.external(runtime.getProgramsPath() + e + "/Code/Compiled").exists()) {
Expand All @@ -77,7 +77,7 @@ private String runLs(String dir) {
try {
out = "";
List<String> titles = new ArrayList<>();
Arrays.asList(Mdx.files.external(dir).list()).forEach(e -> titles.add(e.nameWithoutExtension()));
Arrays.asList(Mdx.files.external(runtime.getProgramsPath() + dir).list()).forEach(e -> titles.add(e.name()));

titles.stream().sorted().forEach(e -> out += e + "\n");
return out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String execute(String[] args) {
return f.getAbsolutePath();
} catch (IOException ex) {
Logger.getLogger(PrintWorkspaceCommand.class.getName()).log(Level.SEVERE, null, ex);
return "Could not find workspace directory.";
return "[E] Could not find workspace directory.";
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/leikr/commands/RemoveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public RemoveCommand(GameRuntime runtime) {
@Override
public String execute(String[] command) {
if (command.length <= 1) {
return "Missing - required program name.";
return "[E] Missing - required program name.";
}
if (!containsName(command[1])) {
return "Program [" + command[1] + "] does not exist in Programs directory.";
return "[E] Program [" + command[1] + "] does not exist in Programs directory.";
}
try {
Mdx.files.external(runtime.getProgramsPath() + command[1]).deleteDirectory();
return "Program [" + command[1] + "] has been uninstalled.";
return "[I] Program [" + command[1] + "] has been uninstalled.";
} catch (IOException ex) {
Logger.getLogger(RemoveCommand.class.getName()).log(Level.SEVERE, null, ex);
return "Could not uninstall [" + command[1] + "]";
return "[E] Could not uninstall [" + command[1] + "]";
}

}
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/leikr/commands/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ public RunCommand(GameRuntime runtime, TerminalManager terminalManager, EngineLo
@Override
public String execute(String[] command) {
if (command.length == 1) {
return "Missing - required program title.";
return "[E] Missing - required program title.";
}
try {
System.out.println(runtime.getProgramsPath());
ArrayList<String> names = new ArrayList<>();
Arrays.asList(Mdx.files.external(runtime.getProgramsPath()).list()).stream().forEach(e -> names.add(e.nameWithoutExtension()));
if (!names.contains(command[1])) {
return "Program [" + command[1] + "] does not exist in Programs directory.";
return "[E] Program [" + command[1] + "] does not exist in Programs directory.";
}
runtime.setGameName(command[1]);
if (command.length > 2) {
String[] args = Arrays.copyOfRange(command, 2, command.length);
engineLoader.setEngineArgs(args);
}
terminalManager.setProgramRunning();
return "Loading...";
return "[I] Loading...";
} catch (IOException ex) {
Logger.getLogger(RunCommand.class.getName()).log(Level.WARNING, null, ex);
return "Failed to run program with name [ " + command[1] + " ]";
return "[E] Failed to run program with name [ " + command[1] + " ]";
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/leikr/commands/ToolCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ public String execute(String[] command) {
return out;
} catch (IOException ex) {
Logger.getLogger(ToolCommand.class.getName()).log(Level.WARNING, null, ex);
return "Failed to list tools.";
return "[E] Failed to list tools.";
}
} else {
try {
if (!containsName(command[1])) {
return "Tool [" + command[1] + "] does not exist in Data/Tools/ directory.";
return "[E] Tool [" + command[1] + "] does not exist in Data/Tools/ directory.";
}
runtime.setGameName(command[1]);
terminalManager.setToolRunning();
return "Running tool [" + command[1] + "].";
return "[I] Running tool [" + command[1] + "].";
} catch (Exception ex) {
Logger.getLogger(ToolCommand.class.getName()).log(Level.WARNING, null, ex);
return "Failed to run tool with name [ " + command[1] + " ]";
return "[E] Failed to run tool with name [ " + command[1] + " ]";
}

}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/leikr/commands/WikiCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public String execute(String[] command) {
Desktop.getDesktop().browse(new URI(wiki));
} catch (IOException | URISyntaxException ex) {
Logger.getLogger(WikiCommand.class.getName()).log(Level.WARNING, null, ex);
return "Host browser unaccessible.";
return "[E] Host browser unaccessible.";
}
return "Opening [" + wiki + "] in host browser.";
return "[I] Opening [" + wiki + "] in host browser.";
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/leikr/managers/TerminalManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import leikr.commands.InstallCommand;
import leikr.commands.NewProgramCommand;
import leikr.commands.PackageCommand;
import leikr.commands.PrintCommand;
import leikr.commands.PrintDirectoryCommand;
import leikr.commands.PrintWorkspaceCommand;
import leikr.commands.RemoveCommand;
Expand Down Expand Up @@ -102,6 +103,7 @@ public TerminalManager(GameRuntime runtime, EngineLoader engineLoader) {
Logger.getLogger(TerminalManager.class.getName()).log(Level.SEVERE, null, ex);
}
commandList.put("about", new AboutCommand(runtime));
commandList.put("cat", new PrintCommand(runtime));
commandList.put("ls", new PrintDirectoryCommand(runtime));
commandList.put("new", new NewProgramCommand(runtime, this));
commandList.put("exit", new ExitCommand());
Expand Down

0 comments on commit 5dbe2fc

Please sign in to comment.