Commit ad878059 authored by Valérie Maquil's avatar Valérie Maquil
Browse files

added drawing priority to scenes

parent 89b46722
Pipeline #575 skipped
<?xml version="1.0" encoding="UTF-8"?>
<scenario>
<scenes>
<scene>
<name>Background</name>
<image>assets/correct.png</image>
<triggerCondition>true</triggerCondition>
<drawPriority>1</drawPriority>
</scene>
<scene>
<name>Background</name>
<image>assets/checkered_tablecloth.jpg</image>
<triggerCondition>true</triggerCondition>
<drawPriority>1</drawPriority>
</scene>
</scenes>
<objects>
......
......@@ -9,8 +9,8 @@ logger.event.configuration = logger.xml
# Properties for calibrating the interface
frameTitle = NUI Application
windowWidth = 1920
windowHeight = 1080
windowWidth = 1280
windowHeight = 800
fullScreen = false
font = Arial
fontSize = 13
......@@ -27,10 +27,10 @@ cursor.id.remapping.constant = 1024
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
# The location and name of the root bootstrapping file.
bootstrapping.root = power_scenario.xml
bootstrapping.root = food_scenario.xml
# Properties for the equation system
scriptEngine.executable = C:/Octave/Octave-3.8.2/bin/octave.exe
scriptEngine.workingDir = model
equation.system = power_scenario.xml
scenario.description = power_scenario.xml
\ No newline at end of file
equation.system = food_scenario.xml
scenario.description = food_scenario.xml
\ No newline at end of file
......@@ -36,9 +36,9 @@ import lu.list.itis.dkd.tui.widget.BaseWidget;
import lu.list.itis.dkd.tui.widget.ValueWidget;
import com.google.common.base.Preconditions;
import com.google.common.collect.Multimap;
import java.io.File;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
......@@ -51,7 +51,7 @@ import java.util.concurrent.ConcurrentHashMap;
*/
@NonNullByDefault
public class Scenario {
private Map<String, Scene> scenes;
private Multimap<Integer, Scene> scenes;
private static ConcurrentHashMap<String, Variable> inputs;
private static ConcurrentHashMap<String, Variable> outputs;
......
......@@ -72,6 +72,12 @@ public class Scene extends Content {
public Scene(Element element) throws BuildException {
super(element.getChildText(Externalization.NAME_NODE));
try {
drawPriority = Integer.parseInt(element.getChildText(Externalization.DRAW_PRIORITY_NODE));
} catch (final NumberFormatException e) {
}
final String triggerCondition = element.getChildText(Externalization.TRIGGER_CONDITION_NODE);
for (final String _name : Splitter.on(Externalization.SPACE).trimResults().omitEmptyStrings().split(triggerCondition)) {
......@@ -125,4 +131,7 @@ public class Scene extends Content {
public void initialise() {
// Nothing to do here!
}
}
\ No newline at end of file
......@@ -25,9 +25,10 @@ import lu.list.itis.dkd.tui.TangibleContentManager;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.event.ContentEvent;
import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.stream.Collectors;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
......@@ -40,7 +41,7 @@ import javax.script.ScriptEngineManager;
@NonNullByDefault
public class StageManager extends TangibleContentManager {
private static final StageManager INSTANCE = new StageManager();
private static Map<String, Scene> scenes;
private static Multimap<Integer, Scene> scenes;
private static ScriptEngine scriptEngine;
private StageManager() {
......@@ -59,10 +60,11 @@ public class StageManager extends TangibleContentManager {
/**
* @param _scenes
*/
public static void setScenes(Map<String, Scene> _scenes) {
public static void setScenes(Multimap<Integer, Scene> _scenes) {
scenes = _scenes;
scenes.values().forEach(scene -> scene.getTrigger().setScriptEngine(scriptEngine));
}
/** {@inheritDoc} */
......@@ -76,6 +78,15 @@ public class StageManager extends TangibleContentManager {
/** {@inheritDoc} */
@Override
public Collection<Content> getDrawableContents() {
return scenes.values().stream().filter(scene -> scene.evaluateTrigger()).collect(Collectors.toList());
final ArrayList<Content> drawableContents = new ArrayList<>();
for (final Integer key : scenes.keySet()) {
for (final Scene scene : scenes.get(key)) {
if (scene.evaluateTrigger()) {
drawableContents.add(scene);
}
}
}
return drawableContents;
}
}
\ No newline at end of file
......@@ -25,6 +25,9 @@ import lu.list.itis.dkd.tui.scenario.Scene;
import lu.list.itis.dkd.tui.scenario.utility.Externalization;
import lu.list.itis.dkd.tui.utility.PropertiesFetcher;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
......@@ -32,8 +35,6 @@ import org.jdom2.input.SAXBuilder;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -48,7 +49,7 @@ public class SceneBootstrapper {
private static final Logger logger = Logger.getLogger(SceneBootstrapper.class.getSimpleName());
private static Map<String, Scene> scenes = new HashMap<>();
private static Multimap<Integer, Scene> scenes = TreeMultimap.create();
private static Document scenarioDescription;
/**
......@@ -75,7 +76,7 @@ public class SceneBootstrapper {
* @throws BuildException
* Thrown when the scenario description document could not be build.
*/
public static Map<String, Scene> getScenes() throws BuildException {
public static Multimap<Integer, Scene> getScenes() throws BuildException {
final SAXBuilder builder = new SAXBuilder();
final File xmlFile = new File(PropertiesFetcher.fetchProperties().getProperty(Externalization.SCENARIO_DESCRIPTION_PROPERTY));
......@@ -101,7 +102,7 @@ public class SceneBootstrapper {
private static void buildScene(Element element) {
try {
final Scene scene = new Scene(element);
scenes.put(scene.getIdentifier(), scene);
scenes.put(scene.getDrawPriority(), scene);
} catch (final BuildException e) {
Logger.getLogger(SceneBootstrapper.class.getSimpleName()).log(Level.SEVERE, "Could not build scene!", e); //$NON-NLS-1$
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment