}
class SharedListener implements SharedMapListenerCli {
public void propertyChanged(SharedMapEventCli event) {
SharedMapCli map = event.getMap();
if(map.getName().equals("state")) {
//handle change in state here.
// logger.warning("ACTIVE SKYBOX CHANGED TO: "+event.getNewValue().toString());
} else if(map.getName().equals("lights")) {
String key = event.getPropertyName();
SharedDirectionLight light = (SharedDirectionLight)event.getNewValue();
//CASE 1: edited light already exists in global lights
if(globalLights.containsKey(key)) {
LightNode oldLightNode = globalLights.get(key);
LightNode freshLightNode = buildLightFromState(light);
getRenderer().updateLight(oldLightNode, freshLightNode);
LOGGER.fine("UPDATING LIGHT: "+key);
//CASE 2: edited light does not exist in global lights
} else {
LOGGER.fine("ADDING LIGHT: "+key);
LightNode freshLight = buildLightFromState(light);
globalLights.put(key, freshLight);
getRenderer().addLight(key, freshLight);
//needs to be added anew.
}
//CASE 3: there are global lights that don't exist in shared map
//hint #1: is the global lights length greater than the shared map?
if(globalLights.size() > sharedLightMap.size()) {
String lightToAdd = findALightToAdd();
if(lightToAdd != null) {
LightNode node = globalLights.get(lightToAdd);
LOGGER.fine("SHARING LIGHT: "+key);
sharedLightMap.put(lightToAdd,buildStateFromLight(node));
}
}
// getRenderer().addLight(key, buildLightFromState(light));
} else if(map.getName().equals("skyboxes")) {
LOGGER.fine("Skybox sync request!");
handleSkyboxes(stateMap.getString("active"),map);
}
}