Established some basics of the new A2Pack plugin.

This commit is contained in:
Martin Haye 2016-07-03 15:31:13 -07:00
parent f15dc1a648
commit cb124995f4
5 changed files with 194 additions and 1 deletions

3
.gitignore vendored
View File

@ -45,4 +45,5 @@ mg
# Packer sometimes produces an error text file.
error_stack.txt
/OutlawEditor/OutlawPluginExample/target/
/OutlawEditor/OutlawPluginExample/target/
/Platform/Apple/tools/A2Pack/target/

View File

@ -481,6 +481,10 @@ public class UIAction {
ft.setOnFinished(callback);
ft.play();
}
public static File getCurrentSaveFile() {
return currentSaveFile;
}
private UIAction() {
}

View File

@ -0,0 +1,71 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.badvision</groupId>
<artifactId>A2Pack</artifactId>
<version>0.1</version>
<packaging>bundle</packaging>
<name>A2Pack</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.0.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>org.badvision.outlaw.plugin.a2pack</Export-Package>
<Bundle-Activator>org.badvision.outlaw.plugin.a2pack.Activator</Bundle-Activator>
<Export-Service>*</Export-Service>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.22.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
<configuration>
<properties>
<service.vendor>8-Bit Bunch</service.vendor>
</properties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.badvision</groupId>
<artifactId>OutlawEditor</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>5.4.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,76 @@
package org.badvision.outlaw.plugin.a2pack;
import java.io.File;
import javafx.event.ActionEvent;
import javax.xml.bind.JAXB;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.api.MenuAction;
import org.badvision.outlaweditor.ui.UIAction;
import org.osgi.framework.BundleContext;
/**
* This registers a plugin which creates Apple II disk images.
* @author mhaye
*/
@Component(immediate = true)
@Service(MenuAction.class)
public class A2PackPlugin implements MenuAction {
// Note: Because ApplicationState is already a defined service, this will automatically be bound.
// Hence, it is not necessary to worry about passing it it.
@Reference
ApplicationState app;
// This is called when our plugin is starting
@Activate
public void activate() throws Exception {
System.out.println("Hello, menu!");
checkReferences();
}
// This is called when our plugin is stopping
@Deactivate
public void stop(BundleContext bc) throws Exception {
System.out.println("Goodbye, menu!");
}
// This identifies the menu item label
@Override
public String getName() {
return "Build Apple II disk";
}
// This method is called when the user selects the menu item
@Override
public void handle(ActionEvent event)
{
File currentSaveFile = UIAction.getCurrentSaveFile();
if (currentSaveFile == null || !currentSaveFile.exists()) {
UIAction.alert("You must open a world file\nbefore building a disk.");
return;
}
System.out.println("Clicked X!");
JAXB.marshal(ApplicationState.getInstance().getGameData(), System.out);
checkReferences();
UIAction.alert("A2_4evr!");
}
private void checkReferences() {
// app = ApplicationState.getInstance();
if (app == null) {
System.out.println("App is null?!?!");
} else {
if (app.getCurrentPlatform() == null) {
System.out.println("Current platform is null?");
} else {
System.out.println("Current platform is "+app.getCurrentPlatform());
}
}
}
}

View File

@ -0,0 +1,41 @@
package org.badvision.outlaw.plugin.a2pack;
import org.badvision.outlaweditor.api.ApplicationState;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
/**
* This is the activator for the A2Pack plugin, in charge of starting and stopping.
*
* @author mhaye
*/
public class Activator implements BundleActivator {
@Override
public void start(BundleContext bc) throws Exception {
System.out.println("Hello, Apple II packer!");
checkReferences();
}
@Override
public void stop(BundleContext bc) throws Exception {
System.out.println("Goodbye, Apple II packer!");
}
private void checkReferences() {
// Note that our activator is not a component, so we can't use the @Reference
// annotation to inject app automatically. ApplicationState has a convenience
// method to get around this in just such events, but it's a hack.
// Ultimately it's not a good idea to rely on this too much as it follows
// some bad practices behind the scene that leave unclosed references, etc.
// I'll have to come up with a safer way to inject dependencies without
// causing housekeeping issues for OSGi.
ApplicationState app = ApplicationState.getInstance();
if (app == null) {
System.out.println("App is null?!?!");
} else if (app.getCurrentPlatform() == null) {
System.out.println("Current platform is null?");
} else {
System.out.println("Current platform is " + app.getCurrentPlatform());
}
}
}