This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #48 Generate Command Card Overlay
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
1 parent
cea1d90
commit f6e0491
Showing
10 changed files
with
177 additions
and
6 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
bundles/us.nineworlds.xstreamer.ia.data/templates/army/html/command_left_aligned.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
11 changes: 11 additions & 0 deletions
11
bundles/us.nineworlds.xstreamer.ia.data/templates/army/html/common/css_command_common.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
13 changes: 13 additions & 0 deletions
13
...es/us.nineworlds.xstreamer.ia.data/templates/army/html/common/css_leftaligned_command.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
bundles/us.nineworlds.xstreamer.ia.data/templates/army/html/leftaligned_command_detail.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...es/us.nineworlds.xstreamer.ia/src/us/nineworlds/xstreamer/ia/jobs/GenerateCommandJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |