eclipse plugin: implementing open scenario in game
This commit is contained in:
parent
33408ae953
commit
5769466a79
3 changed files with 86 additions and 3 deletions
|
@ -1,11 +1,20 @@
|
|||
package wesnoth_eclipse_plugin.action;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IObjectActionDelegate;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
|
||||
import wesnoth_eclipse_plugin.builder.ExternalToolInvoker;
|
||||
import wesnoth_eclipse_plugin.preferences.PreferenceConstants;
|
||||
import wesnoth_eclipse_plugin.preferences.PreferenceInitializer;
|
||||
import wesnoth_eclipse_plugin.utils.GUIUtils;
|
||||
import wesnoth_eclipse_plugin.utils.ProjectUtils;
|
||||
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
|
||||
|
||||
public class OpenScenarioInGame implements IObjectActionDelegate
|
||||
|
@ -21,9 +30,55 @@ public class OpenScenarioInGame implements IObjectActionDelegate
|
|||
@Override
|
||||
public void run(IAction action)
|
||||
{
|
||||
IFile selectedFile = WorkspaceUtils.getSelectedFile(WorkspaceUtils.getWorkbenchWindow());
|
||||
//TODO: optimize this by checking if file really is a scenario (PersistentProperties)
|
||||
if (WorkspaceUtils.getSelectedProject() == null &&
|
||||
WorkspaceUtils.getSelectedFile() == null &&
|
||||
WorkspaceUtils.getSelectedFolder() == null)
|
||||
{
|
||||
GUIUtils.showMessageBox(WorkspaceUtils.getWorkbenchWindow(),
|
||||
"Please select a campaign or a resource inside the campaign project before.");
|
||||
return;
|
||||
}
|
||||
|
||||
IFile selectedFile = WorkspaceUtils.getSelectedFile(WorkspaceUtils.getWorkbenchWindow());
|
||||
if (selectedFile == null)
|
||||
return;
|
||||
|
||||
//TODO: optimize this by checking if file really is a scenario (PersistentProperties?)
|
||||
if (!ProjectUtils.isScenarioFile(WorkspaceUtils.getPathRelativeToUserDir(selectedFile)))
|
||||
{
|
||||
GUIUtils.showMessageBox(WorkspaceUtils.getWorkbenchWindow(), "This is not a scenario file.");
|
||||
return;
|
||||
}
|
||||
|
||||
try{
|
||||
String campaignId = ProjectUtils.getCampaignID();
|
||||
String scenarioId = ProjectUtils.getScenarioID(WorkspaceUtils.getPathRelativeToUserDir(selectedFile));
|
||||
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add("-c");
|
||||
args.add(campaignId);
|
||||
args.add(scenarioId);
|
||||
|
||||
String wesnothExec = PreferenceInitializer.getString(PreferenceConstants.P_WESNOTH_EXEC_PATH);
|
||||
if (wesnothExec.isEmpty())
|
||||
{
|
||||
GUIUtils.showMessageBox(WorkspaceUtils.getWorkbenchWindow(), "Please set the wesnoth's executable path first.");
|
||||
return;
|
||||
}
|
||||
|
||||
String workingDir = PreferenceInitializer.getString(PreferenceConstants.P_WESNOTH_WORKING_DIR);
|
||||
|
||||
if (workingDir.isEmpty())
|
||||
workingDir = wesnothExec.substring(0,wesnothExec.lastIndexOf(new File(wesnothExec).getName()));
|
||||
|
||||
// we need to add the working dir (backward compatibility)
|
||||
args.add(workingDir);
|
||||
System.out.printf("Launching args: %s \n", args);
|
||||
ExternalToolInvoker.launchTool(wesnothExec, args, true, false,true, WorkspaceUtils.getWorkbenchWindow());
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
*/
|
||||
package wesnoth_eclipse_plugin.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class FileUtils
|
||||
|
@ -34,4 +36,30 @@ public class FileUtils
|
|||
in.close();
|
||||
out.close();
|
||||
}
|
||||
|
||||
public static String getFileContents(File file)
|
||||
{
|
||||
String contentsString = "";
|
||||
BufferedReader reader = null;
|
||||
try
|
||||
{
|
||||
String line = "";
|
||||
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
|
||||
while((line = reader.readLine()) != null)
|
||||
contentsString += (line + "\n");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
try{
|
||||
reader.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return contentsString;
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@ public class WMLTools
|
|||
List<String> arguments = new ArrayList<String>();
|
||||
|
||||
arguments.add(wmllintFile.getAbsolutePath());
|
||||
arguments.add("--dryrun");
|
||||
if (dryrun) arguments.add("--dryrun");
|
||||
arguments.add("--verbose");
|
||||
arguments.add("--nospellcheck");
|
||||
arguments.add(filePath);
|
||||
|
|
Loading…
Add table
Reference in a new issue