@Override public Mode chooseMode(Modes modes, Ability source, Game game) { Iterator<Mode> it = modes.values().iterator(); Mode mode = it.next(); if (modes.size() == 1) return mode; int modeNum = rnd.nextInt(modes.values().size()); for (int i = 0; i < modeNum; i++) { mode = it.next(); } return mode; }
/** * Loads a content from a file. * * @param file File path to load. * @throws java.io.FileNotFoundException thrown if file could not be found. * @throws java.io.IOException thrown if file could no be read. */ public void openFile(File file) throws FileNotFoundException, IOException { mFilePath = file; setText(FileUtils.readFileToString(file)); setMode(Modes.getModeFromFile(file.getName())); // getUndoManager().reset(); undoButton.setDisable(true); redoButton.setDisable(true); }
/** * Inform the SourceViewerConfiguration of the filename of the editor. This information is needed * so the receiver can setup it's mode. * * @param filename */ public void setFilename(String filename) { setMode(Modes.getModeFor(filename)); }
/** * Currently enabled language mode. * * @see EditSession.getMode() * @return the current mode. */ public ModeData getMode() { return Modes.getModeByAlias(getSession().getMode()); }
/** * Change or set new save location and saves the file. * * @param file new location to save. * @throws java.io.IOException thrown if file could no be read. */ public void saveAs(File file) throws IOException, NullPointerException { mFilePath = file; saveFile(); setMode(Modes.getModeFromFile(file.getName())); }
protected String getMessageText(Game game) { StringBuilder sb = threadLocalBuilder.get(); MageObject object = game.getObject(this.sourceId); if (object != null) { if (object instanceof StackAbility) { Card card = game.getCard(((StackAbility) object).getSourceId()); if (card != null) { sb.append(GameLog.getColoredObjectIdName(card)); } else { sb.append(GameLog.getColoredObjectIdName(object)); } } else if (object instanceof Spell) { Spell spell = (Spell) object; String castText = spell.getSpellCastText(game); sb.append((castText.startsWith("Cast ") ? castText.substring(5) : castText)); if (spell.getFromZone() == Zone.GRAVEYARD) { sb.append(" from graveyard"); } sb.append(getOptionalTextSuffix(game, spell)); } else { sb.append(GameLog.getColoredObjectIdName(object)); } } else { sb.append("unknown"); } if (object instanceof Spell && ((Spell) object).getSpellAbilities().size() > 1) { if (((Spell) object) .getSpellAbility() .getSpellAbilityType() .equals(SpellAbilityType.SPLIT_FUSED)) { Spell spell = (Spell) object; int i = 0; for (SpellAbility spellAbility : spell.getSpellAbilities()) { i++; String half; if (i == 1) { half = " left"; } else { half = " right"; } if (spellAbility.getTargets().size() > 0) { sb.append(half).append(" half targeting "); for (Target target : spellAbility.getTargets()) { sb.append(target.getTargetedName(game)); } } } } else { Spell spell = (Spell) object; int i = 0; for (SpellAbility spellAbility : spell.getSpellAbilities()) { i++; if (i > 1) { sb.append(" splicing "); if (spellAbility.name.length() > 5 && spellAbility.name.startsWith("Cast ")) { sb.append(spellAbility.name.substring(5)); } else { sb.append(spellAbility.name); } } sb.append(getTargetDescriptionForLog(spellAbility.getTargets(), game)); } } } else if (object instanceof Spell && ((Spell) object).getSpellAbility().getModes().size() > 1) { Modes spellModes = ((Spell) object).getSpellAbility().getModes(); for (Mode selectedMode : spellModes.getSelectedModes()) { int item = 0; for (Mode mode : spellModes.values()) { item++; if (mode.getId().equals(selectedMode.getId())) { sb.append(" (mode ").append(item).append(")"); sb.append(getTargetDescriptionForLog(selectedMode.getTargets(), game)); break; } } } } else { sb.append(getTargetDescriptionForLog(getTargets(), game)); } return sb.toString(); }