Esempio n. 1
0
  private String newScope(GameModel gameModel, VariableDescriptor vd) {
    StringBuilder sb = new StringBuilder();
    try {
      descriptorFacade.detach(vd);
      String name = vd.getName();
      String parentName = vd.getParentList().getName();

      GameModelScope scope = new GameModelScope();
      scope.setBroadcastScope("GameScope");
      vd.setScope(scope);
      String json = vd.toJson(Views.Export.class);
      logger.error("JSON for " + parentName + "/" + name + " variable: " + json);

      descriptorFacade.remove(vd.getId());
      descriptorFacade.flush();

      logger.error("REMOVED");

      sb.append("NAME: ")
          .append(name)
          .append(" -> ")
          .append(this.addVariable(gameModel, json, name, parentName));

    } catch (IOException ex) {
      java.util.logging.Logger.getLogger(UpdateController.class.getName())
          .log(Level.SEVERE, null, ex);
    }
    return sb.toString();
  }
Esempio n. 2
0
  private String rtsUpdateScope(GameModel gameModel) {
    List<VariableDescriptor> variableDescriptors = gameModel.getVariableDescriptors();
    StringBuilder sb = new StringBuilder();
    sb.append("[");

    for (VariableDescriptor vd : variableDescriptors) {

      if ("question".equals(vd.getLabel().toLowerCase())) {
        this.updateScope(vd);
      } else if ("toolbar".equals(vd.getLabel().toLowerCase())
          || "moves".equals(vd.getLabel().toLowerCase())
          || "dialogues".equals(vd.getLabel().toLowerCase())) {
        if (vd instanceof ListDescriptor) {
          ListDescriptor list = (ListDescriptor) vd;
          for (VariableDescriptor child : list.getItems()) {
            if (child instanceof StringDescriptor) {
              this.updateScope(child);
            }
          }
        }
      }
    }
    sb.append("]");

    return sb.toString();
  }
Esempio n. 3
0
  /**
   * @param gameModelId
   * @return static "Finished" string...
   */
  @GET
  @Path("UpdateScript/{gameModelId : ([1-9][0-9]*)}")
  public String script(@PathParam("gameModelId") Long gameModelId) {
    List<VariableDescriptor> findAll = descriptorFacade.findAll(gameModelId);
    List<String> keys = new ArrayList<>();
    List<String> values = new ArrayList<>();
    for (VariableDescriptor vd : findAll) {
      keys.add("VariableDescriptorFacade\\.find\\(" + vd.getId() + "\\)");
      values.add("VariableDescriptorFacade.find(gameModel, \"" + vd.getName() + "\")");
    }

    for (VariableDescriptor vd : findAll) {
      if (vd instanceof ChoiceDescriptor) {
        ChoiceDescriptor choice = (ChoiceDescriptor) vd;
        for (Result r : choice.getResults()) {
          replaceAll(r.getImpact(), keys, values);
        }
      } else if (vd instanceof StateMachineDescriptor) {
        StateMachineDescriptor fsm = (StateMachineDescriptor) vd;
        for (Map.Entry<Long, State> s : fsm.getStates().entrySet()) {
          replaceAll(s.getValue().getOnEnterEvent(), keys, values);
          for (Transition t : s.getValue().getTransitions()) {
            replaceAll(t.getPreStateImpact(), keys, values);
            replaceAll(t.getTriggerCondition(), keys, values);
          }
        }
      }
    }
    return "Finished";
  }
Esempio n. 4
0
 /**
  * Retrieve
  *
  * @param gameModelId
  * @return static "Finished" string...
  */
 @GET
 @Path("Encode/{gameModelId : ([1-9][0-9]*)}")
 public String encode(@PathParam("gameModelId") Long gameModelId) {
   List<VariableDescriptor> findAll = descriptorFacade.findByGameModelId(gameModelId);
   for (VariableDescriptor vd : findAll) {
     List<String> findDistinctNames = descriptorFacade.findDistinctNames(vd.getGameModel());
     List<String> findDistinctLabels = descriptorFacade.findDistinctLabels(vd.getGameModel());
     findDistinctNames.remove(vd.getName());
     findDistinctLabels.remove(vd.getLabel());
     Helper.setUniqueName(vd, findDistinctNames);
     Helper.setUniqueLabel(vd, findDistinctLabels);
     descriptorFacade.flush();
   }
   return "Finished";
 }
Esempio n. 5
0
  private void updateScope(VariableDescriptor vd) {
    if (!(vd.getScope() instanceof GameModelScope)) {
      EntityManager em = this.getEntityManager();

      Collection<VariableInstance> values = vd.getScope().getVariableInstancesByKeyId().values();
      for (VariableInstance vi : values) {
        em.remove(vi);
      }
      GameModelScope scope = new GameModelScope();
      scope.setBroadcastScope("GameScope");
      scope.setVariableDescscriptor(vd);
      vd.setScope(scope);
      em.persist(vd);
      vd.propagateDefaultInstance(null, true);
    }
  }
Esempio n. 6
0
  private String rtsNewScope(GameModel gameModel) {
    List<VariableDescriptor> variableDescriptors = gameModel.getVariableDescriptors();
    StringBuilder sb = new StringBuilder();
    sb.append("[");

    for (Iterator<VariableDescriptor> it = variableDescriptors.iterator(); it.hasNext(); ) {
      VariableDescriptor vd = it.next();
      if ("question".equals(vd.getLabel().toLowerCase())) {
        if (!(vd.getScope() instanceof GameModelScope)) {
          sb.append(this.newScope(gameModel, vd));
        }
      } else if ("toolbar".equals(vd.getLabel().toLowerCase())
          || "moves".equals(vd.getLabel().toLowerCase())
          || "dialogues".equals(vd.getLabel().toLowerCase())) {
        if (vd instanceof ListDescriptor) {
          ListDescriptor list = (ListDescriptor) vd;
          for (VariableDescriptor child : list.getItems()) {
            if (child instanceof StringDescriptor) {
              sb.append(this.newScope(gameModel, child));
            }
          }
        }
      }
    }
    sb.append("]");

    return sb.toString();
  }