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

Commit

Permalink
Issue #48 Generate Command Card Overlay
Browse files Browse the repository at this point in the history
Added ability to generate the command card overlay
separate from the deployment card overlay.  Future additions
could be to allow for the marking of discarded command cards
so we know what has been played and what hasn't.  This does
require the broadcaster to have some way to know what has
been played and what hasn't.
  • Loading branch information
kingargyle committed Nov 2, 2017
1 parent cea1d90 commit f6e0491
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<#--
This generates an Army overlay for Imperial Assault. The text will
be left aligned.
-->
<#import "common/common_utils.ftl" as fun>
<html>
<head>
<#include "common/css_leftaligned_command.ftl">
<#if obs_refresh>
<#include "common/js_refresh.ftl">
</#if>
</head>
<body>
<#include "leftaligned_command_detail.ftl"/>
</body>

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

.commandCardsContainer {
padding: 10px;
height: 100%;
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5));
}

.commandCards {
padding: 2px;
font-style: bold;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<style>
body {
margin: 5px;
color: #FFFFFF;
text-shadow: 4px 1px #000000;
text-align: left;
font-size: 100%;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-style: normal;
}
<#include "css_command_common.ftl"/>
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,3 @@
</#if>
</#list>
<hr />
<#list iaspec.commandCards as command>
<div id="commandCards">
<div class="cardName">${command.commandCard.name} : ${command.commandCard.cost}</div>
</div>
</#list>
<hr />
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="commandCardsContainer">
<hr />
<#list iaspec.commandCards as command>
<div class="commandCards">
<div class="cardName">${command.commandCard.name} (${command.commandCard.cost})</div>
</div>
</#list>
<hr />
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import us.nineworlds.xstreamer.ia.core.Activator;
import us.nineworlds.xstreamer.ia.events.GenerateArmyEvent;
import us.nineworlds.xstreamer.ia.jobs.GenerateArmyJob;
import us.nineworlds.xstreamer.ia.jobs.GenerateCommandJob;
import us.nineworlds.xstreamer.ia.listeners.ArmySelectionChangeListener;
import us.nineworlds.xstreamer.ia.lookup.CommandCardLookup;
import us.nineworlds.xstreamer.ia.lookup.DeploymentsLookup;
Expand Down Expand Up @@ -254,6 +255,10 @@ public void widgetDefaultSelected(SelectionEvent e) {
abstract String playerFileName();

abstract String armyTemplate();

abstract String commandTemplate();

abstract String commandFileName();

abstract void resetPlayerModel(IASpec model);

Expand All @@ -265,5 +270,8 @@ public void refreshTree() {
public void updateJob(GenerateArmyEvent event) {
GenerateArmyJob job = new GenerateArmyJob("generateArmy", getPlayerModel(), playerFileName(), armyTemplate());
job.schedule();

GenerateCommandJob commandJob = new GenerateCommandJob("generateCommands", getPlayerModel(), commandFileName(), commandTemplate());
commandJob.schedule();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,15 @@ public String armyTemplate() {
void resetPlayerModel(IASpec model) {
us.nineworlds.xstreamer.ia.core.Activator.getDefault().setPlayer1Model(model);
}

@Override
String commandTemplate() {
return "command_left_aligned.ftl";
}

@Override
String commandFileName() {
return "ia_player1_command.html";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,15 @@ public String armyTemplate() {
void resetPlayerModel(IASpec model) {
us.nineworlds.xstreamer.ia.core.Activator.getDefault().setPlayer2Model(model);
}

@Override
String commandTemplate() {
return "command_left_aligned.ftl";
}

@Override
String commandFileName() {
return "ia_player2_command.html";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package us.nineworlds.xstreamer.ia.jobs;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.preference.IPreferenceStore;
import org.osgi.framework.Bundle;

import freemarker.template.Configuration;
import freemarker.template.Template;
import us.nineworlds.iadata.IASpec;
import us.nineworlds.xstreamer.ia.core.Activator;

public class GenerateCommandJob extends Job {

IASpec iaspec;
String commandFilename;
String templateFilename;

public GenerateCommandJob(String name, IASpec model, String prefernceCommandFileName, String templateFileName) {
super(name);
iaspec = model;
commandFilename = prefernceCommandFileName;
this.templateFilename = templateFileName;
}

@Override
protected IStatus run(IProgressMonitor monitor) {
IPreferenceStore iaPreferenceStore = us.nineworlds.xstreamer.ia.Activator.getDefault().getPreferenceStore();
boolean obsRefreshFlag = iaPreferenceStore.getBoolean(us.nineworlds.xstreamer.ia.preferences.PreferenceConstants.OBS_REFRESH_SCRIPT);

String templateInputDirectory = templateInputDirectory();
String templateOutputDirectory = iaPreferenceStore.getString(us.nineworlds.xstreamer.ia.preferences.PreferenceConstants.TEMPLATE_XSTREAMER_IA_OUTPUT_DIRECTORY);

if (StringUtils.isEmpty(templateOutputDirectory) || StringUtils.isEmpty(commandFilename) ||
StringUtils.isEmpty(templateFilename) || StringUtils.isEmpty(templateInputDirectory)) {
return Status.CANCEL_STATUS;
}

return writeCommandCards(obsRefreshFlag, templateInputDirectory, templateOutputDirectory);
}

private IStatus writeCommandCards(boolean obsRefreshFlag, String templateInputDirectory, String templateOutputDirectory) {
Writer playerArmyFile = null;
try {
Configuration config = us.nineworlds.xstreamer.core.Activator.getDefault().getFreemarkerConfig();
config.setDirectoryForTemplateLoading(new File(templateInputDirectory));

java.nio.file.Path jpath = java.nio.file.Paths.get(templateFilename);
Template armyTemplate = config.getTemplate(jpath.getFileName().toString());
playerArmyFile = new FileWriter(new File(templateOutputDirectory + File.separator + commandFilename));

Map<String, Object> input = new HashMap<>();

input.put("iaspec", iaspec);
input.put("allDeployments", Activator.getDefault().getDeploymentsLookup().getDeployments());
input.put("allCommandCards", Activator.getDefault().getCommandCardLookup().getCommandCards());
input.put("obs_refresh", obsRefreshFlag);

armyTemplate.process(input, playerArmyFile);
} catch (Exception e) {
e.printStackTrace();
return Status.CANCEL_STATUS;
} finally {
IOUtils.closeQuietly(playerArmyFile);
}
return Status.OK_STATUS;
}

private String templateInputDirectory() {
Bundle templateBundle = Platform.getBundle("us.nineworlds.xstreamer.ia.data");
Path path = new Path("templates");
URL url = FileLocator.find(templateBundle, path, null);
URL realUrl = null;
String templateInputDirectory = null;
try {
realUrl = FileLocator.toFileURL(url);
File templateDirectory = FileUtils.toFile(realUrl);
templateInputDirectory = templateDirectory.getCanonicalPath().toString() + File.separator + "army" + File.separator + "html";
} catch (Exception ex) {

}
return templateInputDirectory;
}

}

0 comments on commit f6e0491

Please sign in to comment.