From: <chr...@us...> - 2006-10-03 12:56:50
|
Revision: 462 http://svn.sourceforge.net/gridarta/?rev=462&view=rev Author: christianhujer Date: 2006-10-03 05:56:09 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Some naming unification regarding MainControl and ArchetypeSet. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CArchPanelPan.java trunk/crossfire/src/cfeditor/CAttribDialog.java trunk/crossfire/src/cfeditor/CFJavaEditor.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainStatusbar.java trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/CScriptController.java trunk/crossfire/src/cfeditor/ReplaceDialog.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/gui/ArchComboBox.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/parameter/ArchParameter.java trunk/daimonin/src/daieditor/CArchPanelPan.java trunk/daimonin/src/daieditor/CAttribDialog.java trunk/daimonin/src/daieditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainStatusbar.java trunk/daimonin/src/daieditor/CMapTileList.java trunk/daimonin/src/daieditor/ReplaceDialog.java trunk/daimonin/src/daieditor/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java trunk/src/app/net/sf/gridarta/MainControl.java Modified: trunk/crossfire/src/cfeditor/CArchPanelPan.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-10-03 12:56:09 UTC (rev 462) @@ -125,7 +125,7 @@ if (index != -1) { final String archname = theList.getSelectedValue().toString(); - arch = mainControl.getArchObjectStack().getArch(archname); + arch = mainControl.getArchetypeSet().getArch(archname); } return arch; } @@ -136,7 +136,7 @@ if (index != -1) { try { final String archname = theList.getSelectedValue().toString(); - arch = mainControl.getArchObjectStack().getArch(archname); + arch = mainControl.getArchetypeSet().getArch(archname); } catch (final NullPointerException e) { /* log.info("NullPointerException in showArchListObject()!", e); @@ -270,7 +270,7 @@ /* We additionally set the JLabels icon property here. */ - final GameObject arch = mainControl.getArchObjectStack().getArch(value.toString()); + final GameObject arch = mainControl.getArchetypeSet().getArch(value.toString()); if (isSelected) { archPanel.setPanelArch(value.toString()); mainControl.setStatusText(" " + value + " "); Modified: trunk/crossfire/src/cfeditor/CAttribDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-10-03 12:56:09 UTC (rev 462) @@ -454,7 +454,7 @@ final JPanel layout1 = new JPanel(new BorderLayout()); // face, name & type - imagePanel = new JLabel(mainControl.getArchObjectStack().getFace(gameObject.getFaceNr())); + imagePanel = new JLabel(mainControl.getArchetypeSet().getFace(gameObject.getFaceNr())); imagePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); layout1.add(imagePanel, BorderLayout.WEST); Modified: trunk/crossfire/src/cfeditor/CFJavaEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/CFJavaEditor.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/CFJavaEditor.java 2006-10-03 12:56:09 UTC (rev 462) @@ -107,7 +107,7 @@ // Initialise the application mainControl.init(doShow); mainControl.refreshMenusAndToolbars(); - mainControl.getArchObjectStack().loadArchetypes(); + mainControl.getArchetypeSet().loadArchetypes(); System.gc(); // process commandline parameters: Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-03 12:56:09 UTC (rev 462) @@ -31,7 +31,6 @@ import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; import cfeditor.map.MapModel; -import java.awt.Font; import java.awt.Point; import java.awt.Rectangle; import java.awt.Toolkit; @@ -45,7 +44,6 @@ import java.util.Random; import java.util.Vector; import javax.swing.ImageIcon; -import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -142,7 +140,7 @@ private ImageIcon noarchTileIconX; - private final ArchetypeSet archList; // the one and only arch list + private final ArchetypeSet archetypeSet; // the one and only arch list /** All open maps. */ private final Vector<MapControl> levels = new Vector<MapControl>(1, 2); @@ -199,7 +197,7 @@ /** Constructs the main controller and its model and view. */ public CMainControl() { - archList = new ArchetypeSet(this); + archetypeSet = new ArchetypeSet(this); mainView = new CMainView(this); instance = this; @@ -266,11 +264,11 @@ /** * Loading the joinList from file and attaching all to 'joinlist'. * (This method must not be called before all arches are loaded - * into the ArchetypeSet 'archList'!) + * into the ArchetypeSet 'archetypeSet'!) */ public void loadJoinlist() { joinList = new AutojoinList(); - if (!joinList.loadList(archList)) { + if (!joinList.loadList(archetypeSet)) { joinList = null; } } @@ -291,7 +289,7 @@ return; } - archList.collectArchetypes(); + archetypeSet.collectArchetypes(); } /** @@ -366,23 +364,23 @@ // access to ArchNodeList // remark: i use before some weird access to it, use this instead when you find it public void addArchToList(final GameObject data) { - archList.addArchToList(data); + archetypeSet.addArchToList(data); } public void incArchObjCount() { - archList.incArchObjCount(); + archetypeSet.incArchObjCount(); } public int getArchObjCount() { - return archList.getArchObjCount(); + return archetypeSet.getArchObjCount(); } public int getArchCount() { - return archList.getArchCount(); + return archetypeSet.getArchCount(); } public GameObject getArch(final String archname) { - return archList.getArch(archname); + return archetypeSet.getArch(archname); } public CopyBuffer getCopyBuffer() { @@ -567,23 +565,20 @@ } public ImageIcon getFace(final int i) { - return archList.getFace(i); + return archetypeSet.getFace(i); } public String getFaceName(final int i) { - return archList.getFaceName(i); + return archetypeSet.getFaceName(i); } public void setStatusText(final String string) { mainView.setStatusText(string); } - /** - * Get the ArchetypeSet. - * @return ArchetypeSet - */ - public ArchetypeSet getArchObjectStack() { - return archList; + /** {@inheritDoc} */ + public ArchetypeSet getArchetypeSet() { + return archetypeSet; } /** @@ -973,7 +968,7 @@ // first: attach our map sucker to a default arch we have loaded for (final Iterator<GameObject> it = objects.iterator(); it.hasNext();) { final GameObject arch = it.next(); - final GameObject defarch = archList.getArch(arch.getArchetypeName()); + final GameObject defarch = archetypeSet.getArch(arch.getArchetypeName()); if (defarch == null) { // we had an unknown arch here!! // showMessage("Error Loading Map File "+file.getName(), "\n Found Unknown Arch < "+arch.getArchetypeName()+" >"); @@ -1802,8 +1797,4 @@ return null; } - public GameObject[] getArchList() { - return archList.getArchList(); - } - } // class CMainControl Modified: trunk/crossfire/src/cfeditor/CMainStatusbar.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainStatusbar.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/CMainStatusbar.java 2006-10-03 12:56:09 UTC (rev 462) @@ -123,9 +123,9 @@ final long totMem = runtime.totalMemory(); final long usedMem = totMem - freeMem; - memory.setText(" ( " + mainControl.getArchObjectStack().getArchObjCount() - + "/" + mainControl.getArchObjectStack().getArchCount() - + "/" + mainControl.getArchObjectStack().getFaceCount() + memory.setText(" ( " + mainControl.getArchetypeSet().getArchObjCount() + + "/" + mainControl.getArchetypeSet().getArchCount() + + "/" + mainControl.getArchetypeSet().getFaceCount() + " ) Memory Use:" + getMemoryString(usedMem) + "/" + getMemoryString(totMem)); repaint(); } Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-10-03 12:56:09 UTC (rev 462) @@ -758,8 +758,8 @@ // black: the attributes from the default archetype // that don't exist among the "special" ones StyleConstants.setForeground(currentAttributes, Color.black); - if (arch.getObjectText() != null && mainControl.getArchObjectStack().getArch(arch.getArchetypeName()) != null) { - doc.insertString(doc.getLength(), arch.diffArchText(mainControl.getArchObjectStack().getArch(arch.getArchetypeName()).getObjectText(), true), currentAttributes); + if (arch.getObjectText() != null && mainControl.getArchetypeSet().getArch(arch.getArchetypeName()) != null) { + doc.insertString(doc.getLength(), arch.diffArchText(mainControl.getArchetypeSet().getArch(arch.getArchetypeName()).getObjectText(), true), currentAttributes); } } catch (final BadLocationException e) { // TODO Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-10-03 12:56:09 UTC (rev 462) @@ -705,7 +705,7 @@ * "screenshot"-image, false for normal drawing */ public void paintComponent(final Graphics2D grfx, final boolean isSnapshot) { - final ArchetypeSet archlist = mainControl.getArchObjectStack(); + final ArchetypeSet archlist = mainControl.getArchetypeSet(); if (isPickmap) { // draw greenisch background for pickmaps @@ -818,7 +818,7 @@ } else { grfx = backBuffer.getGraphics(); } - final ArchetypeSet archlist = mainControl.getArchObjectStack(); // arch stack + final ArchetypeSet archlist = mainControl.getArchetypeSet(); // arch stack // ---------- draw tile for rectangular view (non-iso) -------------- final CFilterControl filter = mainControl.getFilterControl(); Modified: trunk/crossfire/src/cfeditor/CScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/CScriptController.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/CScriptController.java 2006-10-03 12:56:09 UTC (rev 462) @@ -201,7 +201,7 @@ private void setInterpreterValues(final Interpreter i, final String mode) throws EvalError { i.set("mainControl", mainControl); i.set("mainView", mainControl.getMainView()); - i.set("archList", mainControl.getArchObjectStack()); + i.set("archList", mainControl.getArchetypeSet()); i.set("runMode", mode); } Modified: trunk/crossfire/src/cfeditor/ReplaceDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-10-03 12:56:09 UTC (rev 462) @@ -182,7 +182,7 @@ iconLabel = new JLabel(); if (replaceArch != null) { colonLabel = new JLabel(":"); - iconLabel.setIcon(mainControl.getArchObjectStack().getFace(replaceArch.getFaceNr())); + iconLabel.setIcon(mainControl.getArchetypeSet().getFace(replaceArch.getFaceNr())); rfArchName = new JLabel(" " + replaceArch.getBestName()); } else { colonLabel = new JLabel(""); @@ -231,7 +231,7 @@ colonLabel.setText(""); } else { replaceWithBox.setSelectedIndex(0); - iconLabel.setIcon(mainControl.getArchObjectStack().getFace(replaceArch.getFaceNr())); + iconLabel.setIcon(mainControl.getArchetypeSet().getFace(replaceArch.getFaceNr())); rfArchName.setText(" " + replaceArch.getBestName()); colonLabel.setText(":"); } @@ -261,7 +261,7 @@ if (newArch != null) { final Icon oldIcon = iconLabel.getIcon(); - iconLabel.setIcon(mainControl.getArchObjectStack().getFace(newArch.getFaceNr())); + iconLabel.setIcon(mainControl.getArchetypeSet().getFace(newArch.getFaceNr())); rfArchName.setText(" " + newArch.getBestName()); colonLabel.setText(":"); Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 12:56:09 UTC (rev 462) @@ -607,7 +607,7 @@ CMainStatusbar.getInstance().setText("Collect Archfile: write archetypes"); // open the process bar - final CollectProgressBar pbar = new CollectProgressBar(mainControl.getArchObjectStack().getArchCount(), + final CollectProgressBar pbar = new CollectProgressBar(mainControl.getArchetypeSet().getArchCount(), "Collecting Archetypes..."); File dfile; Modified: trunk/crossfire/src/cfeditor/gui/ArchComboBox.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ArchComboBox.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/gui/ArchComboBox.java 2006-10-03 12:56:09 UTC (rev 462) @@ -308,7 +308,7 @@ private static final long serialVersionUID = 1L; public ArchComboBoxModel() { - archList = mainControl.getArchList(); + archList = mainControl.getArchetypeSet().getArchList(); Arrays.sort(archList, new Comparator<GameObject>() { public int compare(final GameObject o1, final GameObject o2) { return o1.getArchetypeName().toLowerCase().compareTo(o2.getArchetypeName().toLowerCase()); Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-10-03 12:56:09 UTC (rev 462) @@ -1190,7 +1190,7 @@ * <code>archName</code>, or <code>null</code> if it does not exist */ private GameObject getDefaultArch(final String archName) { - return mainControl.getArchObjectStack().getArch(archName); + return mainControl.getArchetypeSet().getArch(archName); } } // class DefaultMapModel Modified: trunk/crossfire/src/cfeditor/parameter/ArchParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/ArchParameter.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/crossfire/src/cfeditor/parameter/ArchParameter.java 2006-10-03 12:56:09 UTC (rev 462) @@ -31,7 +31,7 @@ } @Nullable private GameObject locateArch(final String name) { - final ArchetypeSet stack = CMainControl.getInstance().getArchObjectStack(); + final ArchetypeSet stack = CMainControl.getInstance().getArchetypeSet(); if (ArchetypeSet.getLoadStatus() != ArchetypeSet.IS_COMPLETE) { return null; } Modified: trunk/daimonin/src/daieditor/CArchPanelPan.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-10-03 12:56:09 UTC (rev 462) @@ -168,7 +168,7 @@ @Nullable private GameObject getArchListObject(final int index) { if (index != -1) { try { - return mainControl.getArchObjectStack().getArch((String) theList.getSelectedValue()); + return mainControl.getArchetypeSet().getArch((String) theList.getSelectedValue()); } catch (final NullPointerException e) { /* ignore */ } @@ -269,7 +269,7 @@ public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - final ArchetypeSet archetypeSet = mainControl.getArchObjectStack(); + final ArchetypeSet archetypeSet = mainControl.getArchetypeSet(); final String archname = (String) value; final GameObject arch = archetypeSet.getArch(archname); if (isSelected) { // XXX it is not a good idea to query the selection information at this place. Modified: trunk/daimonin/src/daieditor/CAttribDialog.java =================================================================== --- trunk/daimonin/src/daieditor/CAttribDialog.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/daimonin/src/daieditor/CAttribDialog.java 2006-10-03 12:56:09 UTC (rev 462) @@ -428,7 +428,7 @@ gbc.weightx = 0.0; gbc.weighty = 3.0; gbc.gridheight = 3; - imagePanel = new JLabel(mainControl.getArchObjectStack().getFace(gameObject.getFaceObjName())); + imagePanel = new JLabel(mainControl.getArchetypeSet().getFace(gameObject.getFaceObjName())); imagePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); header.add(imagePanel, gbc); gbc.gridheight = 1; @@ -1245,7 +1245,7 @@ // now lets assign the visible face - perhaps we have still a anim gameObject.setObjectFace(); - imagePanel.setIcon(mainControl.getArchObjectStack().getFace(gameObject.getFaceObjName())); + imagePanel.setIcon(mainControl.getArchetypeSet().getFace(gameObject.getFaceObjName())); if (newMsg != null) { // set new msg text only when it is not equal to default gameObject Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-10-03 12:56:09 UTC (rev 462) @@ -943,10 +943,10 @@ } } else if (content.getType() != TreasureObj.FOLDER) { // normal arch: display the face icon - final GameObject arch = CMainControl.getInstance().getArchObjectStack().getArch(content.getName()); + final GameObject arch = CMainControl.getInstance().getArchetypeSet().getArch(content.getName()); if (arch != null) { if (!arch.hasFaceObject()) { - setIcon(CMainControl.getInstance().getArchObjectStack().getFace(arch.getFaceObjName())); + setIcon(CMainControl.getInstance().getArchetypeSet().getFace(arch.getFaceObjName())); } else { setIcon(noface); } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-10-03 12:56:09 UTC (rev 462) @@ -842,11 +842,8 @@ mainView.setStatusText(string); } - /** - * Get the ArchetypeSet. - * @return ArchetypeSet - */ - public ArchetypeSet getArchObjectStack() { + /** {@inheritDoc} */ + public ArchetypeSet getArchetypeSet() { return archetypeSet; } Modified: trunk/daimonin/src/daieditor/CMainStatusbar.java =================================================================== --- trunk/daimonin/src/daieditor/CMainStatusbar.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/daimonin/src/daieditor/CMainStatusbar.java 2006-10-03 12:56:09 UTC (rev 462) @@ -132,8 +132,8 @@ final long usedMem = totMem - freeMem; memory.setText(ACTION_FACTORY.format("memory", - mainControl.getArchObjectStack().getArchObjCount(), - mainControl.getArchObjectStack().getArchCount(), + mainControl.getArchetypeSet().getArchObjCount(), + mainControl.getArchetypeSet().getArchCount(), mainControl.getFaceObjects().size(), getMemoryString(usedMem), getMemoryString(freeMem), getMemoryString(totMem) )); Modified: trunk/daimonin/src/daieditor/CMapTileList.java =================================================================== --- trunk/daimonin/src/daieditor/CMapTileList.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/daimonin/src/daieditor/CMapTileList.java 2006-10-03 12:56:09 UTC (rev 462) @@ -440,7 +440,7 @@ setIcon(CMainControl.nofaceTileIcon); } else { final String faceObjName = arch.getFaceObjName(); - final ImageIcon icon = faceObjName != null ? mainControl.getArchObjectStack().getFace(faceObjName) : null; + final ImageIcon icon = faceObjName != null ? mainControl.getArchetypeSet().getFace(faceObjName) : null; setIcon(icon != null ? icon : CMainControl.unknownTileIcon); } Modified: trunk/daimonin/src/daieditor/ReplaceDialog.java =================================================================== --- trunk/daimonin/src/daieditor/ReplaceDialog.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/daimonin/src/daieditor/ReplaceDialog.java 2006-10-03 12:56:09 UTC (rev 462) @@ -196,7 +196,7 @@ iconLabel = new JLabel(); if (replaceArch != null) { colonLabel = new JLabel(":"); - iconLabel.setIcon(mainControl.getArchObjectStack().getFace(replaceArch.getFaceObjName())); + iconLabel.setIcon(mainControl.getArchetypeSet().getFace(replaceArch.getFaceObjName())); rfArchName = new JLabel(" " + replaceArch.getBestName()); } else { colonLabel = new JLabel(""); @@ -231,7 +231,7 @@ colonLabel.setText(""); } else { replaceWithBox.setSelectedIndex(0); - iconLabel.setIcon(mainControl.getArchObjectStack().getFace(replaceArch.getFaceObjName())); + iconLabel.setIcon(mainControl.getArchetypeSet().getFace(replaceArch.getFaceObjName())); rfArchName.setText(" " + replaceArch.getBestName()); colonLabel.setText(":"); } @@ -261,7 +261,7 @@ if (newArch != null) { final Icon oldIcon = iconLabel.getIcon(); - iconLabel.setIcon(mainControl.getArchObjectStack().getFace(newArch.getFaceObjName())); + iconLabel.setIcon(mainControl.getArchetypeSet().getFace(newArch.getFaceObjName())); rfArchName.setText(" " + newArch.getBestName()); colonLabel.setText(":"); Modified: trunk/daimonin/src/daieditor/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/ScriptArchData.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/daimonin/src/daieditor/ScriptArchData.java 2006-10-03 12:56:09 UTC (rev 462) @@ -590,7 +590,7 @@ event = new GameObject(); // FIXME: This arch has no default arch event.setArchTypNr(118); event.setArchetypeName("event_obj"); - event.setArchetype(CMainControl.getInstance().getArchObjectStack().getArch("event_obj")); + event.setArchetype(CMainControl.getInstance().getArchetypeSet().getArch("event_obj")); event.setObjectFace(); setEventData(eventType, pluginName, filePath, options); } Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 12:56:09 UTC (rev 462) @@ -537,7 +537,7 @@ private final Runnable archCollector = new Runnable() { /** {@inheritDoc} */ public void run() { - final Progress pbar = new ProgressDisplay(mainControl.getMainView(), ""/*FIXME*/, mainControl.getArchObjectStack().getArchCount(), ACTION_FACTORY.getString("archCollectArches")); + final Progress pbar = new ProgressDisplay(mainControl.getMainView(), ""/*FIXME*/, mainControl.getArchetypeSet().getArchCount(), ACTION_FACTORY.getString("archCollectArches")); collectDaimoninArchesArches(pbar); collectDaimoninArchesAnimations(pbar); collectDaimoninArchesAnimationTree(pbar); Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-03 12:56:09 UTC (rev 462) @@ -1013,8 +1013,8 @@ normalFace = CMainControl.nofaceTileIcon; transFace = normalFace; } else { - normalFace = CMainControl.getInstance().getArchObjectStack().getFace(faceObjName); - transFace = CMainControl.getInstance().getArchObjectStack().getTrans(faceObjName); + normalFace = CMainControl.getInstance().getArchetypeSet().getFace(faceObjName); + transFace = CMainControl.getInstance().getArchetypeSet().getTrans(faceObjName); } } Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-10-03 12:56:09 UTC (rev 462) @@ -632,7 +632,7 @@ * <code>archName</code>, or <code>null</code> if it does not exist */ private GameObject getDefaultArch(final String archName) { - return mainControl.getArchObjectStack().getArch(archName); + return mainControl.getArchetypeSet().getArch(archName); } } // class DefaultMapModel Modified: trunk/src/app/net/sf/gridarta/MainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/MainControl.java 2006-10-03 12:38:53 UTC (rev 461) +++ trunk/src/app/net/sf/gridarta/MainControl.java 2006-10-03 12:56:09 UTC (rev 462) @@ -36,4 +36,10 @@ */ String getScriptSuffix(); + /** + * Get the ArchetypeSet for the available Archetypes. + * @return ArchetypeSet + */ + Object getArchetypeSet(); + } // interface MainControl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-03 14:22:24
|
Revision: 464 http://svn.sourceforge.net/gridarta/?rev=464&view=rev Author: christianhujer Date: 2006-10-03 07:21:46 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Major rework of ArchetypeSet: * Improved method naming. * Unified method naming. * Extracted common interface. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinList.java trunk/crossfire/src/cfeditor/CArchPanelPan.java trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainMenu.java trunk/crossfire/src/cfeditor/CMainStatusbar.java trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/crossfire/src/cfeditor/CNewMapDialog.java trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/parameter/ArchParameter.java trunk/daimonin/src/daieditor/CArchPanelPan.java trunk/daimonin/src/daieditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainStatusbar.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java Modified: trunk/crossfire/src/cfeditor/AutojoinList.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinList.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/AutojoinList.java 2006-10-03 14:21:46 UTC (rev 464) @@ -123,9 +123,9 @@ jlist.archnames = new String[16]; // array to store the archetype names for (int i = 0; i < 16; i++) { jlist.archnames[i] = nbuf[i]; // store archetype name in the list - archstack.getArch(nbuf[i]).setJoinList(jlist); // set the link in the def. arch + archstack.getArchetype(nbuf[i]).setJoinList(jlist); // set the link in the def. arch if (log.isDebugEnabled()) { - log.debug("(" + i + ") arch: '" + archstack.getArch(nbuf[i]).getArchetypeName() + "' -> (" + nbuf[i] + ")"); + log.debug("(" + i + ") arch: '" + archstack.getArchetype(nbuf[i]).getArchetypeName() + "' -> (" + nbuf[i] + ")"); } } @@ -139,7 +139,7 @@ } else if (count < 16) { // add a new archid to the buffer - final GameObject arch = archstack.getArch(line); + final GameObject arch = archstack.getArchetype(line); if (arch != null) { nbuf[count] = line; @@ -313,7 +313,7 @@ GameObject tmpArch = map.getTopArchObject(x, y); // we look through the arches at the given location (top to bottom): for (; tmpArch != null; tmpArch = tmpArch.getPrev()) { - if (stack.getArch(tmpArch.getArchetypeName()).getJoinList() == this) { + if (stack.getArchetype(tmpArch.getArchetypeName()).getJoinList() == this) { return tmpArch; // we found an arch } } @@ -326,7 +326,7 @@ * by changing archtype and face. */ private void connectArch(final GameObject arch, final String archname) { - final GameObject defarch = stack.getArch(archname); // new default arch + final GameObject defarch = stack.getArchetype(archname); // new default arch if (!arch.getArchetypeName().equals(archname)) { // set new archtype Modified: trunk/crossfire/src/cfeditor/CArchPanelPan.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-10-03 14:21:46 UTC (rev 464) @@ -125,7 +125,7 @@ if (index != -1) { final String archname = theList.getSelectedValue().toString(); - arch = mainControl.getArchetypeSet().getArch(archname); + arch = mainControl.getArchetypeSet().getArchetype(archname); } return arch; } @@ -136,7 +136,7 @@ if (index != -1) { try { final String archname = theList.getSelectedValue().toString(); - arch = mainControl.getArchetypeSet().getArch(archname); + arch = mainControl.getArchetypeSet().getArchetype(archname); } catch (final NullPointerException e) { /* log.info("NullPointerException in showArchListObject()!", e); @@ -270,7 +270,7 @@ /* We additionally set the JLabels icon property here. */ - final GameObject arch = mainControl.getArchetypeSet().getArch(value.toString()); + final GameObject arch = mainControl.getArchetypeSet().getArchetype(value.toString()); if (isSelected) { archPanel.setPanelArch(value.toString()); mainControl.setStatusText(" " + value + " "); Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-10-03 14:21:46 UTC (rev 464) @@ -954,7 +954,7 @@ } } else if (content.getType() != TreasureObj.FOLDER) { // normal arch: display the face icon - if (ArchetypeSet.getLoadStatus() == ArchetypeSet.IS_COMPLETE) { + if (CMainControl.getInstance().getArchetypeSet().getLoadStatus() == ArchetypeSet.LoadStatus.COMPLETE) { final String archname = content.getName(); final GameObject arch = CMainControl.getInstance().getArch(archname); if (arch != null) { Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-03 14:21:46 UTC (rev 464) @@ -283,7 +283,7 @@ /** collect CF arches */ public void collectCFArches() { - if (ArchetypeSet.getLoadStatus() != ArchetypeSet.IS_COMPLETE) { + if (archetypeSet.getLoadStatus() != ArchetypeSet.LoadStatus.COMPLETE) { // must not collect arches while arch stack not complete showMessage("Arches still Loading", "You have to wait for all arches to be loaded\nbefore you can collect them."); return; @@ -364,23 +364,19 @@ // access to ArchNodeList // remark: i use before some weird access to it, use this instead when you find it public void addArchToList(final GameObject data) { - archetypeSet.addArchToList(data); + archetypeSet.addArchetype(data); } public void incArchObjCount() { - archetypeSet.incArchObjCount(); + archetypeSet.incArchetypeCount(); } - public int getArchObjCount() { - return archetypeSet.getArchObjCount(); - } - public int getArchCount() { return archetypeSet.getArchCount(); } public GameObject getArch(final String archname) { - return archetypeSet.getArch(archname); + return archetypeSet.getArchetype(archname); } public CopyBuffer getCopyBuffer() { @@ -824,7 +820,7 @@ final int returnVal = fileChooser.showOpenDialog(mainView); if (returnVal == JFileChooser.APPROVE_OPTION) { - if (ArchetypeSet.getLoadStatus() == ArchetypeSet.IS_LOADING) { + if (archetypeSet.getLoadStatus() == ArchetypeSet.LoadStatus.LOADING) { // ArchStack still loading -> abort! showMessage("Cannot open Map", "Are you nuts?! :-)\n" + "All arches have to be loaded before you can open a map.\n" + @@ -832,7 +828,7 @@ return; } - if (ArchetypeSet.getLoadStatus() == ArchetypeSet.IS_EMPTY) { + if (archetypeSet.getLoadStatus() == ArchetypeSet.LoadStatus.EMPTY) { // ArchStack is empty -> abort! showMessage("Cannot open Map", "There are currently no arches avaliable!\n" + "You need to have arches loaded before opening a map.\n" + @@ -968,7 +964,7 @@ // first: attach our map sucker to a default arch we have loaded for (final Iterator<GameObject> it = objects.iterator(); it.hasNext();) { final GameObject arch = it.next(); - final GameObject defarch = archetypeSet.getArch(arch.getArchetypeName()); + final GameObject defarch = archetypeSet.getArchetype(arch.getArchetypeName()); if (defarch == null) { // we had an unknown arch here!! // showMessage("Error Loading Map File "+file.getName(), "\n Found Unknown Arch < "+arch.getArchetypeName()+" >"); Modified: trunk/crossfire/src/cfeditor/CMainMenu.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainMenu.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/CMainMenu.java 2006-10-03 14:21:46 UTC (rev 464) @@ -801,7 +801,7 @@ mainControl.setPickmapsLocked(m_lockPickmaps.isChecked()); m_newPickmap.setEnabled(!m_lockPickmaps.isChecked()); - final boolean isArchLoadComplete = ArchetypeSet.getLoadStatus() == ArchetypeSet.IS_COMPLETE; + final boolean isArchLoadComplete = mainControl.getArchetypeSet().getLoadStatus() == ArchetypeSet.LoadStatus.COMPLETE; if (isArchLoadComplete) { m_deletePickmap.setEnabled(!m_lockPickmaps.isChecked()); m_loadPickmap.setEnabled(!m_lockPickmaps.isChecked()); @@ -1197,7 +1197,7 @@ /** Refreshes the state of items in this toolbar. */ public void refresh() { - final boolean isArchLoadComplete = ArchetypeSet.getLoadStatus() == ArchetypeSet.IS_COMPLETE; + final boolean isArchLoadComplete = mainControl.getArchetypeSet().getLoadStatus() == ArchetypeSet.LoadStatus.COMPLETE; m_spellC.setEnabled(true); //m_scriptMenu.setEnabled(false); @@ -1209,7 +1209,7 @@ m_autojoin.setEnabled(mainControl.getJoinlist() != null); // collect arches is only allowed if we run from individual archfiles - m_collectArch.setEnabled(isArchLoadComplete && !ArchetypeSet.isLoadedFromArchive()); + m_collectArch.setEnabled(isArchLoadComplete && !mainControl.getArchetypeSet().isLoadedFromArchive()); if (isArchLoadComplete) { m_viewTreasure.setEnabled(true); Modified: trunk/crossfire/src/cfeditor/CMainStatusbar.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainStatusbar.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/CMainStatusbar.java 2006-10-03 14:21:46 UTC (rev 464) @@ -123,7 +123,7 @@ final long totMem = runtime.totalMemory(); final long usedMem = totMem - freeMem; - memory.setText(" ( " + mainControl.getArchetypeSet().getArchObjCount() + memory.setText(" ( " + mainControl.getArchetypeSet().getArchetypeCount() + "/" + mainControl.getArchetypeSet().getArchCount() + "/" + mainControl.getArchetypeSet().getFaceCount() + " ) Memory Use:" + getMemoryString(usedMem) + "/" + getMemoryString(totMem)); Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-10-03 14:21:46 UTC (rev 464) @@ -758,8 +758,8 @@ // black: the attributes from the default archetype // that don't exist among the "special" ones StyleConstants.setForeground(currentAttributes, Color.black); - if (arch.getObjectText() != null && mainControl.getArchetypeSet().getArch(arch.getArchetypeName()) != null) { - doc.insertString(doc.getLength(), arch.diffArchText(mainControl.getArchetypeSet().getArch(arch.getArchetypeName()).getObjectText(), true), currentAttributes); + if (arch.getObjectText() != null && mainControl.getArchetypeSet().getArchetype(arch.getArchetypeName()) != null) { + doc.insertString(doc.getLength(), arch.diffArchText(mainControl.getArchetypeSet().getArchetype(arch.getArchetypeName()).getObjectText(), true), currentAttributes); } } catch (final BadLocationException e) { // TODO Modified: trunk/crossfire/src/cfeditor/CNewMapDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-10-03 14:21:46 UTC (rev 464) @@ -238,7 +238,7 @@ } // arches must be loaded to create a new map - if (ArchetypeSet.getLoadStatus() != ArchetypeSet.IS_COMPLETE) { + if (mainControl.getArchetypeSet().getLoadStatus() != ArchetypeSet.LoadStatus.COMPLETE) { mainControl.showMessage("Cannot Create Map", "All arches have to be loaded before you can open a map.\n" + "Just be patient and wait a few seconds..."); Modified: trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-03 14:21:46 UTC (rev 464) @@ -293,7 +293,7 @@ // add arch to the archpanel - only if it is not the map arch if (!arch.getArchetypeName().equals(STARTARCH_NAME)) { - if (!ArchetypeSet.isLoadedFromArchive() || archName != null) { + if (!mainControl.getArchetypeSet().isLoadedFromArchive() || archName != null) { // loading from individual files, so we simply add it to list // ArchetypeSet.loadArchFromFiles() takes care of the panels mainControl.addArchPanelArch(arch.getArchetypeName(), index); Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 14:21:46 UTC (rev 464) @@ -60,33 +60,29 @@ import net.sf.gridarta.io.CFileReader; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; /** * The <code>ArchetypeSet</code> contains all the Archetypes. * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public final class ArchetypeSet { +public final class ArchetypeSet implements net.sf.gridarta.gameobject.ArchetypeSet<GameObject> { private static final Logger log = Logger.getLogger(ArchetypeSet.class); - // load status: is the ArchetypeSet fully loaded? - public static final int IS_EMPTY = 0; + /** The load status of this ArchetypeSet. */ + private LoadStatus loadStatus = LoadStatus.EMPTY; - public static final int IS_LOADING = 1; - - public static final int IS_COMPLETE = 2; - - private static int loadStatus = IS_EMPTY; - /** - * true when Archetypes were loaded from the big collected archive files, - * false when Archetypes were loaded from individual .arc-files + * Whether Archetypes were loaded form an archive. + * @val <code>true</code> when Archetypes were loaded from the big collected archive files, + * @val <code>false<7code> when Archetypes were loaded from individual .arc-files */ - private static boolean loadedFromArchive = false; + private boolean loadedFromArchive = false; - /** The defined default arches. */ - private final TreeMap<String, GameObject> arches = new TreeMap<String, GameObject>(); + /** The defined Archetypes. */ + private final Map<String, GameObject> archetypeMap = new TreeMap<String, GameObject>(); private final FaceObject[] faceObjects = new FaceObject[10000]; @@ -114,23 +110,23 @@ GameObject.setArchetypeSet(this); // add static reference to GameObject } - public void incArchObjCount() { + /** {@inheritDoc} */ + public void incArchetypeCount() { archObjCount++; } - /** - * Gets the number of loaded arch objects (only default arches). - * @return number of loaded arch objects (default arches) - */ - public int getArchObjCount() { + /** {@inheritDoc} */ + public int getArchetypeCount() { return archObjCount; } - public static int getLoadStatus() { + /** {@inheritDoc} */ + public LoadStatus getLoadStatus() { return loadStatus; } - public static boolean isLoadedFromArchive() { + /** {@inheritDoc} */ + public boolean isLoadedFromArchive() { return loadedFromArchive; } @@ -159,49 +155,38 @@ return null; } + /** {@inheritDoc} */ public int getArchCount() { - return arches.size(); + return archetypeMap.size(); } public int getFaceCount() { return faceListCount; } - /** - * Get a default GameObject by its archetype name. - * - * @param archname name of default archetype GameObject to get - * - * @return default GameObject for <var>archname</var> or <code>null</code> - * if no such GameObject exists - * - * @see GameObject#createArch() for a similar method that instantiates. - */ - @Nullable public GameObject getArch(final String archname) { - return arches.get(archname); + /** {@inheritDoc} */ + @Nullable public GameObject getArchetype(@NotNull final String archetypeName) { + return archetypeMap.get(archetypeName); } - /** - * Adds an GameObject to the stack. - * Only invoke this method if the GameObject is an Archetype. - * Do not invoke this method on map arches. - * @param data GameObject with DefaultArch to add - * @todo check whether the GameObject is a default arch and reject no default arches with an exception - */ - public void addArchToList(final GameObject data) { - if (arches.containsKey(data.getArchetypeName())) { - log.warn("addArchToList: duplicate archetype '" + data.getArchetypeName() + "'"); + /** {@inheritDoc} */ + public void addArchetype(final GameObject archetype) { + if (!archetype.isArchetype()) { + throw new IllegalArgumentException("Supplied GameObject " + archetype + " is not an Archetype."); + } + if (archetypeMap.containsKey(archetype.getArchetypeName())) { + log.warn("addArchToList: duplicate archetype '" + archetype.getArchetypeName() + "'"); } else { - arches.put(data.getArchetypeName(), data); + archetypeMap.put(archetype.getArchetypeName(), archetype); } } /** load the arches */ public void loadArchetypes() { final Date timeStart = new Date(); // get starting time - loadStatus = IS_LOADING; // status: loading - log.info("Start to collect arches..."); - CMainStatusbar.getInstance().setText(" Loading Arches... "); + loadStatus = LoadStatus.LOADING; // status: loading + log.info("Start to collect archetypes..."); + CMainStatusbar.getInstance().setText(" Loading Archetypes... "); // browse arch archive // load object from a arch file you found @@ -230,13 +215,13 @@ // print message if no arches were found if (getArchCount() == 0) { - loadStatus = IS_EMPTY; // status: stack is empty + loadStatus = LoadStatus.EMPTY; // status: stack is empty mainControl.showMessage("No Archfiles", "No archfiles could be found. If you have no archfiles\n" + "yet, you need to download them. If you do, make sure\n" + "the path is correct under menu 'File->Options'.\n"); } else { // display the time it took to collect arches: - loadStatus = IS_COMPLETE; // status: stack completed + loadStatus = LoadStatus.COMPLETE; // status: stack completed final Date timeFinish = new Date(); // get finishing time final long diff = timeFinish.getTime() - timeStart.getTime(); if (log.isInfoEnabled()) { @@ -575,9 +560,9 @@ faceListCount++; } - public void connectFaces() { + private void connectFaces() { // run through arches - for (final GameObject arch : arches.values()) { + for (final GameObject arch : archetypeMap.values()) { final String faceName = arch.getFaceName(); if (faceName != null) { final Integer num = (Integer) faceMap.get(faceName); @@ -589,10 +574,7 @@ } } - /** - * Wrapper method for arch collecting. Either Crossfire or Daimonin method - * for collecting arches is chosen here. - */ + /** {@inheritDoc} */ public void collectArchetypes() { collectCrossfireArchetypes(); } @@ -904,7 +886,7 @@ } public GameObject[] getArchList() { - return arches.values().toArray(new GameObject[arches.size()]); + return archetypeMap.values().toArray(new GameObject[archetypeMap.size()]); } /** Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-03 14:21:46 UTC (rev 464) @@ -1429,11 +1429,7 @@ } } - /** - * Create a new GameObject from this Archetype. - * If this GameObject is not an Archetype, this method recursively forwards to its Archetype. - * @return new GameObject - */ + /** {@inheritDoc} */ public GameObject createArch() { if (!isArchetype()) { return archetype.createArch(); Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-10-03 14:21:46 UTC (rev 464) @@ -1190,7 +1190,7 @@ * <code>archName</code>, or <code>null</code> if it does not exist */ private GameObject getDefaultArch(final String archName) { - return mainControl.getArchetypeSet().getArch(archName); + return mainControl.getArchetypeSet().getArchetype(archName); } } // class DefaultMapModel Modified: trunk/crossfire/src/cfeditor/parameter/ArchParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/ArchParameter.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/crossfire/src/cfeditor/parameter/ArchParameter.java 2006-10-03 14:21:46 UTC (rev 464) @@ -32,16 +32,16 @@ @Nullable private GameObject locateArch(final String name) { final ArchetypeSet stack = CMainControl.getInstance().getArchetypeSet(); - if (ArchetypeSet.getLoadStatus() != ArchetypeSet.IS_COMPLETE) { + if (CMainControl.getInstance().getArchetypeSet().getLoadStatus() != ArchetypeSet.LoadStatus.COMPLETE) { return null; } - return stack.getArch(name); + return stack.getArchetype(name); } @Override public void fromXML(final Element e) { super.fromXML(e); valueString = e.getChildTextTrim("value"); - if (ArchetypeSet.getLoadStatus() == ArchetypeSet.IS_COMPLETE) { + if (CMainControl.getInstance().getArchetypeSet().getLoadStatus() == ArchetypeSet.LoadStatus.COMPLETE) { setValue(locateArch(valueString)); } } Modified: trunk/daimonin/src/daieditor/CArchPanelPan.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-10-03 14:21:46 UTC (rev 464) @@ -168,7 +168,7 @@ @Nullable private GameObject getArchListObject(final int index) { if (index != -1) { try { - return mainControl.getArchetypeSet().getArch((String) theList.getSelectedValue()); + return mainControl.getArchetypeSet().getArchetype((String) theList.getSelectedValue()); } catch (final NullPointerException e) { /* ignore */ } @@ -271,7 +271,7 @@ final ArchetypeSet archetypeSet = mainControl.getArchetypeSet(); final String archname = (String) value; - final GameObject arch = archetypeSet.getArch(archname); + final GameObject arch = archetypeSet.getArchetype(archname); if (isSelected) { // XXX it is not a good idea to query the selection information at this place. archPanel.setSelectedArch(archname); mainControl.setStatusText(' ' + value.toString() + ' '); Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-10-03 14:21:46 UTC (rev 464) @@ -943,7 +943,7 @@ } } else if (content.getType() != TreasureObj.FOLDER) { // normal arch: display the face icon - final GameObject arch = CMainControl.getInstance().getArchetypeSet().getArch(content.getName()); + final GameObject arch = CMainControl.getInstance().getArchetypeSet().getArchetype(content.getName()); if (arch != null) { if (!arch.hasFaceObject()) { setIcon(CMainControl.getInstance().getArchetypeSet().getFace(arch.getFaceObjName())); Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-10-03 14:21:46 UTC (rev 464) @@ -96,7 +96,6 @@ import static java.util.prefs.Preferences.userNodeForPackage; import javax.swing.AbstractAction; import javax.swing.ImageIcon; -import javax.swing.JComponent; import javax.swing.JFileChooser; import static javax.swing.JOptionPane.CANCEL_OPTION; import static javax.swing.JOptionPane.CLOSED_OPTION; @@ -316,7 +315,7 @@ tileEdit = 0; init(); refreshMenusAndToolbars(); - archetypeSet.loadArches(); + archetypeSet.loadArchetypes(); validators = createMapValidators(); } @@ -518,7 +517,7 @@ /** Collect CF arches, animations and faces. */ @ActionMethod public void collectArches() { - archetypeSet.collectArches(); + archetypeSet.collectArchetypes(); } /** Collect Spells. */ @@ -676,11 +675,11 @@ // access to ArchNodeList // remark: i use before some weird access to it, use this instead when you find it public void addArchToList(final GameObject data) { - archetypeSet.addArchToList(data); + archetypeSet.addArchetype(data); } public void incArchObjCount() { - archetypeSet.incArchObjCount(); + archetypeSet.incArchetypeCount(); } public int getArchCount() { @@ -1111,7 +1110,7 @@ } final int returnVal = fileChooser.showOpenDialog(mainView); if (returnVal == JFileChooser.APPROVE_OPTION) { - if (ArchetypeSet.getLoadStatus() == ArchetypeSet.IS_EMPTY) { + if (archetypeSet.getLoadStatus() == ArchetypeSet.LoadStatus.EMPTY) { // ArchStack is empty -> abort! ACTION_FACTORY.showMessageDialog(mainView, "openFileWantedNoArches"); } else { @@ -1280,7 +1279,7 @@ //noinspection ForLoopWithMissingComponent for (final Iterator<GameObject> it = objects.iterator(); it.hasNext();) { final GameObject arch = it.next(); - final GameObject defarch = archetypeSet.getArch(arch.getArchetypeName()); + final GameObject defarch = archetypeSet.getArchetype(arch.getArchetypeName()); if (defarch == null) { noarch.append(arch.getArchetypeName()).append('\n'); noarchcount++; Modified: trunk/daimonin/src/daieditor/CMainStatusbar.java =================================================================== --- trunk/daimonin/src/daieditor/CMainStatusbar.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/daimonin/src/daieditor/CMainStatusbar.java 2006-10-03 14:21:46 UTC (rev 464) @@ -132,7 +132,7 @@ final long usedMem = totMem - freeMem; memory.setText(ACTION_FACTORY.format("memory", - mainControl.getArchetypeSet().getArchObjCount(), + mainControl.getArchetypeSet().getArchetypeCount(), mainControl.getArchetypeSet().getArchCount(), mainControl.getFaceObjects().size(), getMemoryString(usedMem), getMemoryString(freeMem), getMemoryString(totMem) Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-10-03 14:21:46 UTC (rev 464) @@ -802,8 +802,8 @@ aEnterExit.setEnabled(false); // collect arches is only allowed if we run from individual archfiles - aCollectArches.setEnabled(!ArchetypeSet.isLoadedFromArchive()); - aReloadFaces.setEnabled(!ArchetypeSet.isLoadedFromArchive()); + aCollectArches.setEnabled(!mainControl.getArchetypeSet().isLoadedFromArchive()); + aReloadFaces.setEnabled(!mainControl.getArchetypeSet().isLoadedFromArchive()); aViewTreasurelists.setEnabled(true); final boolean pickmapState = !mainControl.isLockAllPickmaps() && mainControl.getMainView().pickmapActive; Modified: trunk/daimonin/src/daieditor/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/ScriptArchData.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/daimonin/src/daieditor/ScriptArchData.java 2006-10-03 14:21:46 UTC (rev 464) @@ -590,7 +590,7 @@ event = new GameObject(); // FIXME: This arch has no default arch event.setArchTypNr(118); event.setArchetypeName("event_obj"); - event.setArchetype(CMainControl.getInstance().getArchetypeSet().getArch("event_obj")); + event.setArchetype(CMainControl.getInstance().getArchetypeSet().getArchetype("event_obj")); event.setObjectFace(); setEventData(eventType, pluginName, filePath, options); } Modified: trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-03 14:21:46 UTC (rev 464) @@ -119,7 +119,7 @@ final boolean isInternPath; // path is needed when we don't read from collection because there is no editor_folder in arc files final String path; - if (!ArchetypeSet.isLoadedFromArchive() && archName == null) { + if (!mainControl.getArchetypeSet().isLoadedFromArchive() && archName == null) { String tmpPath = (new File(PathManager.getArchPath(fname))).getParent().replace('\\', '/'); if (tmpPath == null) { tmpPath = "/"; @@ -240,7 +240,7 @@ // add arch to the archpanel - only if it is not the map arch and not in the intern folder if (!isInternPath && !(newCat != null && newCat.contains("intern"))) { - if (!ArchetypeSet.isLoadedFromArchive() || archName != null) { + if (!mainControl.getArchetypeSet().isLoadedFromArchive() || archName != null) { // loading from individual files, so we simply add it to list // ArchetypeSet.loadArchFromFiles() takes care of the panels mainControl.addArchPanelArch(arch.getArchetypeName(), index); Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 14:21:46 UTC (rev 464) @@ -64,6 +64,8 @@ import static net.sf.japi.swing.ActionFactory.getFactory; import net.sf.japi.swing.Progress; import net.sf.japi.swing.ProgressDisplay; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; /** * The <code>ArchetypeSet</code> contains all the default arches. @@ -71,7 +73,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class ArchetypeSet { +public final class ArchetypeSet implements net.sf.gridarta.gameobject.ArchetypeSet<GameObject> { /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = getFactory("daieditor"); @@ -79,24 +81,19 @@ /** Size of the image buffer. */ private static final int IMAGE_BUFFER_SIZE = 50 * 1024; - // load status: is archstack fully loaded? - public static final int IS_EMPTY = 0; + /** The load status of this ArchetypeSet. */ + private LoadStatus loadStatus = LoadStatus.EMPTY; - public static final int IS_LOADING = 1; + /** + * Whether Archetypes were loaded form an archive. + * @val <code>true</code> when Archetypes were loaded from the big collected archive files, + * @val <code>false<7code> when Archetypes were loaded from individual .arc-files + */ + private boolean loadedFromArchive; - public static final int IS_COMPLETE = 2; + /** The defined Archetypes. */ + private final Map<String, GameObject> archetypeMap = new TreeMap<String, GameObject>(); - private static int loadStatus = IS_EMPTY; - - // true when arches were loaded from the big collected archive files, - // false when arches were loaded from individual archfiles - private static boolean loadedFromArchive; - - private final List<GameObject> archObjects = new ArrayList<GameObject>(); - - /** The defined default arches. */ - private final Map<String, GameObject> arches = new TreeMap<String, GameObject>(); - private int archObjCount; // all objects, multi tile arches = 1 object private final CMainControl mainControl; @@ -117,23 +114,23 @@ this.mainControl = mainControl; } - public void incArchObjCount() { + /** {@inheritDoc} */ + public void incArchetypeCount() { archObjCount++; } - /** - * Gets the number of loaded arch objects (only default arches). - * @return number of loaded arch objects (default arches) - */ - public int getArchObjCount() { + /** {@inheritDoc} */ + public int getArchetypeCount() { return archObjCount; } - public static int getLoadStatus() { + /** {@inheritDoc} */ + public LoadStatus getLoadStatus() { return loadStatus; } - public static boolean isLoadedFromArchive() { + /** {@inheritDoc} */ + public boolean isLoadedFromArchive() { return loadedFromArchive; } @@ -163,42 +160,35 @@ return face; } + /** {@inheritDoc} */ public int getArchCount() { - return arches.size(); + return archetypeMap.size(); } - /** - * Get a Default GameObject by its archName. - * @param archName name of Default Archetype GameObject to get - * @return Default GameObject for <var>archName</var> or <code>null</code> if no such GameObject - */ - public GameObject getArch(final String archName) { - return arches.get(archName); + /** {@inheritDoc} */ + @Nullable public GameObject getArchetype(@NotNull final String archetypeName) { + return archetypeMap.get(archetypeName); } - /** - * Adds an GameObject to the stack. - * Only invoke this method if the GameObject is a default arch. - * Do not invoke this method on map arches. - * @param data GameObject with DefaultArch to add - * @todo check whether the GameObject is a default arch and reject no default arches with an exception - */ - public void addArchToList(final GameObject data) /*throws DuplicateArchetypeException*/ { - if (arches.containsKey(data.getArchetypeName())) { - ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "loadDuplicateArch", data.getArchetypeName(), currentFile); + /** {@inheritDoc} */ + public void addArchetype(final GameObject archetype) /*throws DuplicateArchetypeException*/ { + if (!archetype.isArchetype()) { + throw new IllegalArgumentException("Supplied GameObject " + archetype + " is not an Archetype."); + } + if (archetypeMap.containsKey(archetype.getArchetypeName())) { + ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "loadDuplicateArch", archetype.getArchetypeName(), currentFile); //throw new DuplicateArchetypeException(data); } else { - archObjects.add(data); - arches.put(data.getArchetypeName(), data); + archetypeMap.put(archetype.getArchetypeName(), archetype); } } /** load the arches */ - public void loadArches() { + public void loadArchetypes() { final long timeStart = System.currentTimeMillis(); - loadStatus = IS_LOADING; // status: loading - System.err.println("Start to collect arches..."); - mainControl.setStatusText(" Loading Arches... "); + loadStatus = LoadStatus.LOADING; // status: loading + System.err.println("Start to collect archetypes..."); + mainControl.setStatusText(" Loading Archetypes... "); // browse arch archive // load object from a arch file you found @@ -229,11 +219,11 @@ // print message if no arches were found if (getArchCount() == 0) { - loadStatus = IS_EMPTY; // status: stack is empty + loadStatus = LoadStatus.EMPTY; // status: stack is empty ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "loadArchesNoArchfiles"); } else { // display the time it took to collect arches: - loadStatus = IS_COMPLETE; // status: stack completed + loadStatus = LoadStatus.COMPLETE; // status: stack completed System.err.println("Arch collect took " + (System.currentTimeMillis() - timeStart) / 1000.0 + " Seconds"); // load pickmaps @@ -321,7 +311,7 @@ // TODO: Allow not having a def arch // at this point we MUST have a legal name and def arch // TODO:Then why not check this and throw an exception if not? - final GameObject defArch = getArch(defArchName); + final GameObject defArch = getArchetype(defArchName); if (name == null || defArchName == null || name.length() == 0 || defArchName.length() == 0 || defArch == null) { System.err.println("Artifacts file: Line " + lineCount + " Object >" + defArchName + "< / >" + name + "< / >" + objTitle + "< has missing name or defArch"); } else if (editorCode != 0 && editorCode != 2) { // the next line of our file is part of a arch parse until a "end" comes @@ -516,32 +506,33 @@ } } - public void connectFaces() { - for (final GameObject arch : archObjects) { + private void connectFaces() { + for (final GameObject arch : archetypeMap.values()) { arch.setObjectFace(); } } - /** - * Collect the existing arches and create archive-files for editor use as - * well as the Daimonin server. The arches also get a special path variable - * included which is used in the editor to categorize the arches. - * <p/> - * Output is: "archetypes", "daimonin.0", "animations", "bmaps" - */ - public void collectArches() { + /** {@inheritDoc} */ + public void collectArchetypes() { new Thread(archCollector).start(); } /** Thread code for collecting the arches. */ private final Runnable archCollector = new Runnable() { + /* + * Collect the existing arches and create archive-files for editor use as + * well as the Daimonin server. The arches also get a special path variable + * included which is used in the editor to categorize the arches. + * <p/> + * Output is: "archetypes", "daimonin.0", "animations", "bmaps" + */ /** {@inheritDoc} */ public void run() { final Progress pbar = new ProgressDisplay(mainControl.getMainView(), ""/*FIXME*/, mainControl.getArchetypeSet().getArchCount(), ACTION_FACTORY.getString("archCollectArches")); - collectDaimoninArchesArches(pbar); - collectDaimoninArchesAnimations(pbar); - collectDaimoninArchesAnimationTree(pbar); - collectDaimoninArchesImages(pbar); + collectDaimoninArchetypes(pbar); + collectDaimoninAnimations(pbar); + collectDaimoninAnimationTree(pbar); + collectDaimoninImages(pbar); pbar.finished(); mainControl.setStatusText(ACTION_FACTORY.getString("archCollectDone")); } @@ -551,7 +542,7 @@ * Collect arches. * @param pbar progress bar to update */ - private void collectDaimoninArchesArches(final Progress pbar) { + private void collectDaimoninArchetypes(final Progress pbar) { // WARNING: do not use out.println() because the server will crash if it's not "\n" but e.g. "\r"! try { final File dfile = new File(mainControl.getArchDefaultFolder(), IGUIConstants.ARCH_FILE); @@ -562,7 +553,7 @@ int count = 0; // count how much arches we've collected - for (final GameObject arch : archObjects) { + for (final GameObject arch : archetypeMap.values()) { // exclude arches generated from artifacts file from collection if (arch.isArtifact()) { @@ -724,7 +715,7 @@ * Collect Animations. * @param pbar progress bar to update */ - private void collectDaimoninArchesAnimations(final Progress pbar) { + private void collectDaimoninAnimations(final Progress pbar) { try { final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(mainControl.getArchDefaultFolder(), "animations")), CFileReader.MAP_ENCODING)); try { @@ -754,7 +745,7 @@ * Collect Animation Tree. * @param pbar progress bar to update */ - private void collectDaimoninArchesAnimationTree(final Progress pbar) { + private void collectDaimoninAnimationTree(final Progress pbar) { try { final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(new File(mainControl.getArchDefaultFolder(), IGUIConstants.CONFIG_DIR), IGUIConstants.ANIMTREE_FILE)), CFileReader.MAP_ENCODING)); try { @@ -785,7 +776,7 @@ * @param pbar progress bar to update * @todo I/O handling sucks here, this could be nicer. */ - private void collectDaimoninArchesImages(final Progress pbar) { + private void collectDaimoninImages(final Progress pbar) { DataOutputStream binFile = null; BufferedWriter textFile = null; BufferedWriter treeFile = null; Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-03 14:21:46 UTC (rev 464) @@ -1294,11 +1294,7 @@ } } - /** - * Create a new GameObject from this Archetype. - * If this GameObject is not an Archetype, this method recursively forwards to its Archetype. - * @return new GameObject - */ + /** {@inheritDoc} */ public GameObject createArch() { if (!isArchetype()) { return archetype.createArch(); Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-10-03 14:21:46 UTC (rev 464) @@ -632,7 +632,7 @@ * <code>archName</code>, or <code>null</code> if it does not exist */ private GameObject getDefaultArch(final String archName) { - return mainControl.getArchetypeSet().getArch(archName); + return mainControl.getArchetypeSet().getArchetype(archName); } } // class DefaultMapModel Added: trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java 2006-10-03 14:21:46 UTC (rev 464) @@ -0,0 +1,84 @@ +package net.sf.gridarta.gameobject; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Interface that captures similarities between different ArchetypeSet implementations. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public interface ArchetypeSet<T extends GameObject> { + + /** + * Increments the internal counter for the number of Archetypes. + * @deprecated only for transition, must only be used by the loaders of Archetypes and not any other purpose. + */ + @Deprecated void incArchetypeCount(); + + /** + * Returns the number of Archetypes loaded. + * @return The number of Archetypes loaded. + */ + int getArchetypeCount(); + + /** + * Returns the load status of this ArchetypeSet. + * @return The load status of this ArchetypeSet. + */ + LoadStatus getLoadStatus(); + + /** + * Returns whether the Archetypes in this ArchetypeSet were loaded from an archive. + * @return <code>true</code> if loaded from an archive, otherwise <code>false</code>. + */ + boolean isLoadedFromArchive(); + + /** + * Returns the number of Archetypes available. + * @return The number of Archetypes available + */ + int getArchCount(); + + /** + * Get an Archetype by its name. + * @param archetypeName name of the Archetype to get + * @return Archetype for <var>archetypeName</var> or <code>null</code> if no such Archetype + * @see GameObject#createArch() for a similar method that instantiates. + */ + @Nullable GameObject getArchetype(@NotNull final String archetypeName); + + /** + * Adds an Archetype to this Set. + * @param archetype Archetype to add. + * @throws IllegalArgumentException in case the added GameObject is not an Archetype. + */ + void addArchetype(final T archetype) throws IllegalArgumentException; + + /** + * Instructs this ArchetypeSet to load its Archetypes. + */ + void loadArchetypes(); + + /** + * Start collecting the Archetypes and other resource files to create an archive. + */ + void collectArchetypes(); + + + /** + * The load status of the ArchetypeSet. + */ + enum LoadStatus { + + /** The ArchetypeSet is empty, loading hasn't started yet. */ + EMPTY, + + /** The ArchetypeSet is loading right now. */ + LOADING, + + /** The ArchetypeSet has completed loading and is ready to use. */ + COMPLETE + + } // enum LoadStatus + +} // interface ArchetypeSet Property changes on: trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-03 13:06:41 UTC (rev 463) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-03 14:21:46 UTC (rev 464) @@ -222,4 +222,11 @@ */ int getMapY(); + /** + * Create a new GameObject from this Archetype. + * If this GameObject is not an Archetype, this method recursively forwards to its Archetype. + * @return new GameObject + */ + GameObject createArch(); + } // interface GameObject This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-03 14:34:01
|
Revision: 466 http://svn.sourceforge.net/gridarta/?rev=466&view=rev Author: christianhujer Date: 2006-10-03 07:33:49 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Fixed HTML bug in javadoc. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 14:29:10 UTC (rev 465) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 14:33:49 UTC (rev 466) @@ -77,7 +77,7 @@ /** * Whether Archetypes were loaded form an archive. * @val <code>true</code> when Archetypes were loaded from the big collected archive files, - * @val <code>false<7code> when Archetypes were loaded from individual .arc-files + * @val <code>false</code> when Archetypes were loaded from individual .arc-files */ private boolean loadedFromArchive = false; Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 14:29:10 UTC (rev 465) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 14:33:49 UTC (rev 466) @@ -87,7 +87,7 @@ /** * Whether Archetypes were loaded form an archive. * @val <code>true</code> when Archetypes were loaded from the big collected archive files, - * @val <code>false<7code> when Archetypes were loaded from individual .arc-files + * @val <code>false</code> when Archetypes were loaded from individual .arc-files */ private boolean loadedFromArchive; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-03 14:54:40
|
Revision: 467 http://svn.sourceforge.net/gridarta/?rev=467&view=rev Author: christianhujer Date: 2006-10-03 07:54:22 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Extracted equal implementation of ArchetypeSets into an abstract common superclass. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 14:33:49 UTC (rev 466) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 14:54:22 UTC (rev 467) @@ -58,6 +58,7 @@ import javax.swing.SwingConstants; import net.sf.gridarta.io.CFileInputStream; import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.gameobject.AbstractArchetypeSet; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.NotNull; @@ -67,23 +68,10 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public final class ArchetypeSet implements net.sf.gridarta.gameobject.ArchetypeSet<GameObject> { +public final class ArchetypeSet extends AbstractArchetypeSet<GameObject> { private static final Logger log = Logger.getLogger(ArchetypeSet.class); - /** The load status of this ArchetypeSet. */ - private LoadStatus loadStatus = LoadStatus.EMPTY; - - /** - * Whether Archetypes were loaded form an archive. - * @val <code>true</code> when Archetypes were loaded from the big collected archive files, - * @val <code>false</code> when Archetypes were loaded from individual .arc-files - */ - private boolean loadedFromArchive = false; - - /** The defined Archetypes. */ - private final Map<String, GameObject> archetypeMap = new TreeMap<String, GameObject>(); - private final FaceObject[] faceObjects = new FaceObject[10000]; // The hash tables hold the name and the index for the field @@ -91,8 +79,6 @@ // in the table is faster than in the static arrays, we can change this private static final Map<String, Integer> faceMap = new HashMap<String, Integer>(); - private int archObjCount; // all objects, multi tile arches = 1 object - private int faceListCount; // all loaded face pictures private final CMainControl mainControl; @@ -106,30 +92,9 @@ public ArchetypeSet(final CMainControl mainControl) { this.mainControl = mainControl; faceListCount = 0; - archObjCount = 0; GameObject.setArchetypeSet(this); // add static reference to GameObject } - /** {@inheritDoc} */ - public void incArchetypeCount() { - archObjCount++; - } - - /** {@inheritDoc} */ - public int getArchetypeCount() { - return archObjCount; - } - - /** {@inheritDoc} */ - public LoadStatus getLoadStatus() { - return loadStatus; - } - - /** {@inheritDoc} */ - public boolean isLoadedFromArchive() { - return loadedFromArchive; - } - /** Returns the index of a face in the face map or -1. * @param faceName name of face to get index for * @return index of face in map or -1 if face is not in map @@ -155,36 +120,18 @@ return null; } - /** {@inheritDoc} */ - public int getArchCount() { - return archetypeMap.size(); - } - public int getFaceCount() { return faceListCount; } - /** {@inheritDoc} */ - @Nullable public GameObject getArchetype(@NotNull final String archetypeName) { - return archetypeMap.get(archetypeName); + protected void handleDuplicate(final GameObject archetype) { + log.warn("addArchToList: duplicate archetype '" + archetype.getArchetypeName() + "'"); } - /** {@inheritDoc} */ - public void addArchetype(final GameObject archetype) { - if (!archetype.isArchetype()) { - throw new IllegalArgumentException("Supplied GameObject " + archetype + " is not an Archetype."); - } - if (archetypeMap.containsKey(archetype.getArchetypeName())) { - log.warn("addArchToList: duplicate archetype '" + archetype.getArchetypeName() + "'"); - } else { - archetypeMap.put(archetype.getArchetypeName(), archetype); - } - } - /** load the arches */ public void loadArchetypes() { final Date timeStart = new Date(); // get starting time - loadStatus = LoadStatus.LOADING; // status: loading + setLoadStatus(LoadStatus.LOADING); // status: loading log.info("Start to collect archetypes..."); CMainStatusbar.getInstance().setText(" Loading Archetypes... "); @@ -215,13 +162,13 @@ // print message if no arches were found if (getArchCount() == 0) { - loadStatus = LoadStatus.EMPTY; // status: stack is empty + setLoadStatus(LoadStatus.EMPTY); // status: stack is empty mainControl.showMessage("No Archfiles", "No archfiles could be found. If you have no archfiles\n" + "yet, you need to download them. If you do, make sure\n" + "the path is correct under menu 'File->Options'.\n"); } else { // display the time it took to collect arches: - loadStatus = LoadStatus.COMPLETE; // status: stack completed + setLoadStatus(LoadStatus.COMPLETE); // status: stack completed final Date timeFinish = new Date(); // get finishing time final long diff = timeFinish.getTime() - timeStart.getTime(); if (log.isInfoEnabled()) { @@ -241,7 +188,7 @@ * "archtypes" and "crossfire.0" */ private void loadArchFromCollected() { - loadedFromArchive = true; // load from the collected files + setLoadedFromArchive(true); // load from the collected files try { // open the resource file @@ -270,7 +217,7 @@ private void loadArchetypesFromFiles(final File f, int index) { final String name = f.getName(); - loadedFromArchive = false; // don't load from the collected files + setLoadedFromArchive(false); // don't load from the collected files if (f.isDirectory()) { // now, setup the arch panels if (!"cvs".equalsIgnoreCase(name) && !"dev".equalsIgnoreCase(name) && !name.startsWith(".")) { Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 14:33:49 UTC (rev 466) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 14:54:22 UTC (rev 467) @@ -60,6 +60,7 @@ import java.util.TreeMap; import javax.swing.ImageIcon; import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.gameobject.AbstractArchetypeSet; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; import net.sf.japi.swing.Progress; @@ -73,7 +74,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class ArchetypeSet implements net.sf.gridarta.gameobject.ArchetypeSet<GameObject> { +public final class ArchetypeSet extends AbstractArchetypeSet<GameObject> { /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = getFactory("daieditor"); @@ -81,21 +82,6 @@ /** Size of the image buffer. */ private static final int IMAGE_BUFFER_SIZE = 50 * 1024; - /** The load status of this ArchetypeSet. */ - private LoadStatus loadStatus = LoadStatus.EMPTY; - - /** - * Whether Archetypes were loaded form an archive. - * @val <code>true</code> when Archetypes were loaded from the big collected archive files, - * @val <code>false</code> when Archetypes were loaded from individual .arc-files - */ - private boolean loadedFromArchive; - - /** The defined Archetypes. */ - private final Map<String, GameObject> archetypeMap = new TreeMap<String, GameObject>(); - - private int archObjCount; // all objects, multi tile arches = 1 object - private final CMainControl mainControl; private int folderLevel; @@ -114,26 +100,6 @@ this.mainControl = mainControl; } - /** {@inheritDoc} */ - public void incArchetypeCount() { - archObjCount++; - } - - /** {@inheritDoc} */ - public int getArchetypeCount() { - return archObjCount; - } - - /** {@inheritDoc} */ - public LoadStatus getLoadStatus() { - return loadStatus; - } - - /** {@inheritDoc} */ - public boolean isLoadedFromArchive() { - return loadedFromArchive; - } - /** * Get the face ImageIcon with a certain face name. * @param faceName faceName of face ImageIcon @@ -160,33 +126,15 @@ return face; } - /** {@inheritDoc} */ - public int getArchCount() { - return archetypeMap.size(); + protected void handleDuplicate(final GameObject archetype) { + ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "loadDuplicateArch", archetype.getArchetypeName(), currentFile); + //throw new DuplicateArchetypeException(data); } - /** {@inheritDoc} */ - @Nullable public GameObject getArchetype(@NotNull final String archetypeName) { - return archetypeMap.get(archetypeName); - } - - /** {@inheritDoc} */ - public void addArchetype(final GameObject archetype) /*throws DuplicateArchetypeException*/ { - if (!archetype.isArchetype()) { - throw new IllegalArgumentException("Supplied GameObject " + archetype + " is not an Archetype."); - } - if (archetypeMap.containsKey(archetype.getArchetypeName())) { - ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "loadDuplicateArch", archetype.getArchetypeName(), currentFile); - //throw new DuplicateArchetypeException(data); - } else { - archetypeMap.put(archetype.getArchetypeName(), archetype); - } - } - /** load the arches */ public void loadArchetypes() { final long timeStart = System.currentTimeMillis(); - loadStatus = LoadStatus.LOADING; // status: loading + setLoadStatus(LoadStatus.LOADING); // status: loading System.err.println("Start to collect archetypes..."); mainControl.setStatusText(" Loading Archetypes... "); @@ -200,7 +148,7 @@ loadArchFromCollected(); // collect arches & images from collection } else { FaceFacade.setNormal(new ArchFaceProvider()); - loadedFromArchive = false; // don't load from the collected files + setLoadedFromArchive(false); // don't load from the collected files animFiles = new ArrayList<File>(); loadArchFromFiles(new File(mainControl.getArchDefaultFolder()), 0, false); // collect arches & images from individual files loadAnimsFromFiles(); @@ -219,11 +167,11 @@ // print message if no arches were found if (getArchCount() == 0) { - loadStatus = LoadStatus.EMPTY; // status: stack is empty + setLoadStatus(LoadStatus.EMPTY); // status: stack is empty ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "loadArchesNoArchfiles"); } else { // display the time it took to collect arches: - loadStatus = LoadStatus.COMPLETE; // status: stack completed + setLoadStatus(LoadStatus.COMPLETE); // status: stack completed System.err.println("Arch collect took " + (System.currentTimeMillis() - timeStart) / 1000.0 + " Seconds"); // load pickmaps @@ -345,7 +293,7 @@ /** Load all arches and pngs from the collected files "archtypes" and "daimonin.0" */ private void loadArchFromCollected() { - loadedFromArchive = true; // load from the collected files + setLoadedFromArchive(true); // load from the collected files try { mainControl.getAnimationObjects().loadAnimTree( new File(new File(mainControl.getArchDefaultFolder(), IGUIConstants.CONFIG_DIR), IGUIConstants.ANIMTREE_FILE)); Added: trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java 2006-10-03 14:54:22 UTC (rev 467) @@ -0,0 +1,104 @@ +package net.sf.gridarta.gameobject; + +import java.util.Map; +import java.util.TreeMap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Base implementation of ArchetypeSet. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public abstract class AbstractArchetypeSet<T extends GameObject> implements ArchetypeSet<T> { + + /** + * Counter of all archetypes, multi tile archetypes = 1. + */ + private int archObjCount; + + /** The load status of this ArchetypeSet. */ + private LoadStatus loadStatus = LoadStatus.EMPTY; + + /** The defined Archetypes. */ + protected final Map<String, T> archetypeMap = new TreeMap<String, T>(); + + /** + * Whether Archetypes were loaded form an archive. + * @val <code>true</code> when Archetypes were loaded from the big collected archive files, + * @val <code>false</code> when Archetypes were loaded from individual .arc-files + */ + private boolean loadedFromArchive; + + /** + * Create an AbstractArchetypeSet. + */ + protected AbstractArchetypeSet() { + } + + /** {@inheritDoc} */ + public final void incArchetypeCount() { + archObjCount++; + } + + /** {@inheritDoc} */ + public final int getArchetypeCount() { + return archObjCount; + } + + /** {@inheritDoc} */ + public final LoadStatus getLoadStatus() { + return loadStatus; + } + + /** {@inheritDoc} */ + public final boolean isLoadedFromArchive() { + return loadedFromArchive; + } + + /** {@inheritDoc} */ + public final int getArchCount() { + return archetypeMap.size(); + } + + /** {@inheritDoc} */ + @Nullable public final T getArchetype(@NotNull final String archetypeName) { + return archetypeMap.get(archetypeName); + } + + /** {@inheritDoc} */ + public final void addArchetype(final T archetype) { + if (!archetype.isArchetype()) { + throw new IllegalArgumentException("Supplied GameObject " + archetype + " is not an Archetype."); + } + if (archetypeMap.containsKey(archetype.getArchetypeName())) { + handleDuplicate(archetype); + } else { + archetypeMap.put(archetype.getArchetypeName(), archetype); + } + } + + /** + * Handle a duplicate Archetype + * @param archetype Dupliate Archetype to handle + */ + protected abstract void handleDuplicate(final T archetype); + + /** + * Sets the load status + * @param loadStatus new load status + * @see #getLoadStatus() + */ + protected void setLoadStatus(final LoadStatus loadStatus) { + this.loadStatus = loadStatus; + } + + /** + * Set whether Archetypes were loaded from an archive. + * @param loadedFromArchive <code>true</code> when loaded from archive, otherwise <code>false</code> + * @see #isLoadedFromArchive() + */ + protected void setLoadedFromArchive(final boolean loadedFromArchive) { + this.loadedFromArchive = loadedFromArchive; + } + +} // class AbstractArchetypeSet Property changes on: trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-03 14:33:49 UTC (rev 466) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-03 14:54:22 UTC (rev 467) @@ -143,6 +143,13 @@ @NotNull GameObject getArchetype(); /** + * Get the name of the Archetype this GameObject is based on. + * For an Archetype this method simply returns its name. + * @return the name of the Archetype this GameObject is based on + */ + @NotNull String getArchetypeName(); + + /** * Returns whether this GameObject is an Archetype. * @return <code>true</code> if this GameObject is an Archetype, otherwise <code>false</code> * @see #getArchetype() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-03 14:57:25
|
Revision: 468 http://svn.sourceforge.net/gridarta/?rev=468&view=rev Author: christianhujer Date: 2006-10-03 07:57:14 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Removed duplicate javadoc. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/GameObject.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-03 14:54:22 UTC (rev 467) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-03 14:57:14 UTC (rev 468) @@ -879,10 +879,7 @@ this.archetypeName = archetypeName != null ? archetypeName.intern() : null; } - /** - * Return the archetype name. - * @return the archetype name - */ + /** {@inheritDoc} */ public String getArchetypeName() { return archetypeName; } Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-03 14:54:22 UTC (rev 467) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-03 14:57:14 UTC (rev 468) @@ -788,10 +788,7 @@ this.archetypeName = archetypeName != null ? archetypeName.intern() : null; } - /** - * Return the archetype name. - * @return the archetype name - */ + /** {@inheritDoc} */ public String getArchetypeName() { return archetypeName; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-03 16:20:44
|
Revision: 469 http://svn.sourceforge.net/gridarta/?rev=469&view=rev Author: christianhujer Date: 2006-10-03 09:20:17 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Removed manual arch object counting - it was only used for the status bar, and documented nullability. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinList.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainStatusbar.java trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainStatusbar.java trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/messages.properties trunk/daimonin/src/daieditor/messages_de.properties trunk/daimonin/src/daieditor/messages_sv.properties trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java Modified: trunk/crossfire/src/cfeditor/AutojoinList.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinList.java 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/crossfire/src/cfeditor/AutojoinList.java 2006-10-03 16:20:17 UTC (rev 469) @@ -132,7 +132,7 @@ success = true; // we did it! } else if (count > 16) { log.warn("In file " + filename + ": List with more than 16 valid entries!"); - } else if (archstack.getArchCount() >= 1) { + } else if (archstack.getArchetypeCount() >= 1) { log.warn("In file " + filename + ": List with less than 16 valid entries!"); } sectionFlag = false; @@ -150,7 +150,7 @@ } } else { // (If no arches exist at all, errormessages are suppressed here) - if (archstack.getArchCount() >= 1) { + if (archstack.getArchetypeCount() >= 1) { log.warn("In file " + filename + ": Arch '" + line + "' not found."); } } Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-03 16:20:17 UTC (rev 469) @@ -367,12 +367,8 @@ archetypeSet.addArchetype(data); } - public void incArchObjCount() { - archetypeSet.incArchetypeCount(); - } - public int getArchCount() { - return archetypeSet.getArchCount(); + return archetypeSet.getArchetypeCount(); } public GameObject getArch(final String archname) { Modified: trunk/crossfire/src/cfeditor/CMainStatusbar.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainStatusbar.java 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/crossfire/src/cfeditor/CMainStatusbar.java 2006-10-03 16:20:17 UTC (rev 469) @@ -124,7 +124,6 @@ final long usedMem = totMem - freeMem; memory.setText(" ( " + mainControl.getArchetypeSet().getArchetypeCount() - + "/" + mainControl.getArchetypeSet().getArchCount() + "/" + mainControl.getArchetypeSet().getFaceCount() + " ) Memory Use:" + getMemoryString(usedMem) + "/" + getMemoryString(totMem)); repaint(); Modified: trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-03 16:20:17 UTC (rev 469) @@ -289,8 +289,6 @@ // add to head our x/y position so he can setup refmax firstArch.addTailPart(arch); } else { - mainControl.incArchObjCount(); - // add arch to the archpanel - only if it is not the map arch if (!arch.getArchetypeName().equals(STARTARCH_NAME)) { if (!mainControl.getArchetypeSet().isLoadedFromArchive() || archName != null) { Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 16:20:17 UTC (rev 469) @@ -48,7 +48,6 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; -import java.util.TreeMap; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JDialog; @@ -61,7 +60,6 @@ import net.sf.gridarta.gameobject.AbstractArchetypeSet; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NotNull; /** * The <code>ArchetypeSet</code> contains all the Archetypes. @@ -161,7 +159,7 @@ CMainStatusbar.getInstance().setText(" Ready."); // print message if no arches were found - if (getArchCount() == 0) { + if (getArchetypeCount() == 0) { setLoadStatus(LoadStatus.EMPTY); // status: stack is empty mainControl.showMessage("No Archfiles", "No archfiles could be found. If you have no archfiles\n" + "yet, you need to download them. If you do, make sure\n" + @@ -536,7 +534,7 @@ CMainStatusbar.getInstance().setText("Collect Archfile: write archetypes"); // open the process bar - final CollectProgressBar pbar = new CollectProgressBar(mainControl.getArchetypeSet().getArchCount(), + final CollectProgressBar pbar = new CollectProgressBar(mainControl.getArchetypeSet().getArchetypeCount(), "Collecting Archetypes..."); File dfile; Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-10-03 16:20:17 UTC (rev 469) @@ -678,12 +678,8 @@ archetypeSet.addArchetype(data); } - public void incArchObjCount() { - archetypeSet.incArchetypeCount(); - } - public int getArchCount() { - return archetypeSet.getArchCount(); + return archetypeSet.getArchetypeCount(); } /** Set all global settings from the preferences. */ Modified: trunk/daimonin/src/daieditor/CMainStatusbar.java =================================================================== --- trunk/daimonin/src/daieditor/CMainStatusbar.java 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/daimonin/src/daieditor/CMainStatusbar.java 2006-10-03 16:20:17 UTC (rev 469) @@ -133,7 +133,6 @@ memory.setText(ACTION_FACTORY.format("memory", mainControl.getArchetypeSet().getArchetypeCount(), - mainControl.getArchetypeSet().getArchCount(), mainControl.getFaceObjects().size(), getMemoryString(usedMem), getMemoryString(freeMem), getMemoryString(totMem) )); Modified: trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-03 16:20:17 UTC (rev 469) @@ -236,8 +236,6 @@ log.log(Level.WARNING, "defArchWithInvalidMpartNr", new Object[]{arch.getArchetypeName(), firstArch.getArchetypeName(), Integer.toString(multiShapeID), Integer.toString(firstArch.getMultiShapeID())}); } } else { - mainControl.incArchObjCount(); - // add arch to the archpanel - only if it is not the map arch and not in the intern folder if (!isInternPath && !(newCat != null && newCat.contains("intern"))) { if (!mainControl.getArchetypeSet().isLoadedFromArchive() || archName != null) { Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 16:20:17 UTC (rev 469) @@ -57,7 +57,6 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import java.util.TreeMap; import javax.swing.ImageIcon; import net.sf.gridarta.io.CFileReader; import net.sf.gridarta.gameobject.AbstractArchetypeSet; @@ -65,8 +64,6 @@ import static net.sf.japi.swing.ActionFactory.getFactory; import net.sf.japi.swing.Progress; import net.sf.japi.swing.ProgressDisplay; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NotNull; /** * The <code>ArchetypeSet</code> contains all the Archetypes. @@ -166,7 +163,7 @@ mainControl.setStatusText(" Ready."); // print message if no arches were found - if (getArchCount() == 0) { + if (getArchetypeCount() == 0) { setLoadStatus(LoadStatus.EMPTY); // status: stack is empty ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "loadArchesNoArchfiles"); } else { @@ -476,7 +473,7 @@ */ /** {@inheritDoc} */ public void run() { - final Progress pbar = new ProgressDisplay(mainControl.getMainView(), ""/*FIXME*/, mainControl.getArchetypeSet().getArchCount(), ACTION_FACTORY.getString("archCollectArches")); + final Progress pbar = new ProgressDisplay(mainControl.getMainView(), ""/*FIXME*/, mainControl.getArchetypeSet().getArchetypeCount(), ACTION_FACTORY.getString("archCollectArches")); collectDaimoninArchetypes(pbar); collectDaimoninAnimations(pbar); collectDaimoninAnimationTree(pbar); Modified: trunk/daimonin/src/daieditor/messages.properties =================================================================== --- trunk/daimonin/src/daieditor/messages.properties 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/daimonin/src/daieditor/messages.properties 2006-10-03 16:20:17 UTC (rev 469) @@ -939,7 +939,7 @@ ############# # Status Bar -memory=({0}/{1}/{2}) Memory: {3} used, {4} free, {5} total. +memory=({0}/{1}) Memory: {2} used, {3} free, {4} total. dialogDontShowAgain=Show this dialog again next time. Modified: trunk/daimonin/src/daieditor/messages_de.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_de.properties 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/daimonin/src/daieditor/messages_de.properties 2006-10-03 16:20:17 UTC (rev 469) @@ -466,6 +466,6 @@ ############# # Status Bar -memory=({0}/{1}/{2}) Speicher: {3} belegt, {4} frei, {5} gesamt. +memory=({0}/{1}) Speicher: {2} belegt, {3} frei, {4} gesamt. dialogDontShowAgain=Diesen Dialog n\xE4chstes Mal wieder anzeigen. Modified: trunk/daimonin/src/daieditor/messages_sv.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_sv.properties 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/daimonin/src/daieditor/messages_sv.properties 2006-10-03 16:20:17 UTC (rev 469) @@ -916,7 +916,7 @@ ############# # Status Bar -memory=({0}/{1}/{2}) Minne: {3} anv\xE4nt, {4} ledigt, {5} totalt. +memory=({0}/{1}) Minne: {2} anv\xE4nt, {3} ledigt, {4} totalt. dialogDontShowAgain=Visa inte denna dialog igen Modified: trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java 2006-10-03 16:20:17 UTC (rev 469) @@ -11,11 +11,6 @@ */ public abstract class AbstractArchetypeSet<T extends GameObject> implements ArchetypeSet<T> { - /** - * Counter of all archetypes, multi tile archetypes = 1. - */ - private int archObjCount; - /** The load status of this ArchetypeSet. */ private LoadStatus loadStatus = LoadStatus.EMPTY; @@ -36,17 +31,7 @@ } /** {@inheritDoc} */ - public final void incArchetypeCount() { - archObjCount++; - } - - /** {@inheritDoc} */ - public final int getArchetypeCount() { - return archObjCount; - } - - /** {@inheritDoc} */ - public final LoadStatus getLoadStatus() { + @NotNull public final LoadStatus getLoadStatus() { return loadStatus; } @@ -56,7 +41,7 @@ } /** {@inheritDoc} */ - public final int getArchCount() { + public final int getArchetypeCount() { return archetypeMap.size(); } @@ -66,7 +51,7 @@ } /** {@inheritDoc} */ - public final void addArchetype(final T archetype) { + public final void addArchetype(@NotNull final T archetype) { if (!archetype.isArchetype()) { throw new IllegalArgumentException("Supplied GameObject " + archetype + " is not an Archetype."); } Modified: trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java 2006-10-03 14:57:14 UTC (rev 468) +++ trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java 2006-10-03 16:20:17 UTC (rev 469) @@ -10,22 +10,10 @@ public interface ArchetypeSet<T extends GameObject> { /** - * Increments the internal counter for the number of Archetypes. - * @deprecated only for transition, must only be used by the loaders of Archetypes and not any other purpose. - */ - @Deprecated void incArchetypeCount(); - - /** - * Returns the number of Archetypes loaded. - * @return The number of Archetypes loaded. - */ - int getArchetypeCount(); - - /** * Returns the load status of this ArchetypeSet. * @return The load status of this ArchetypeSet. */ - LoadStatus getLoadStatus(); + @NotNull LoadStatus getLoadStatus(); /** * Returns whether the Archetypes in this ArchetypeSet were loaded from an archive. @@ -37,7 +25,7 @@ * Returns the number of Archetypes available. * @return The number of Archetypes available */ - int getArchCount(); + int getArchetypeCount(); /** * Get an Archetype by its name. @@ -52,7 +40,7 @@ * @param archetype Archetype to add. * @throws IllegalArgumentException in case the added GameObject is not an Archetype. */ - void addArchetype(final T archetype) throws IllegalArgumentException; + void addArchetype(@NotNull final T archetype) throws IllegalArgumentException; /** * Instructs this ArchetypeSet to load its Archetypes. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-03 16:46:15
|
Revision: 470 http://svn.sourceforge.net/gridarta/?rev=470&view=rev Author: christianhujer Date: 2006-10-03 09:45:57 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Made archetypeMap private. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 16:20:17 UTC (rev 469) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 16:45:57 UTC (rev 470) @@ -48,6 +48,7 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Collection; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JDialog; @@ -507,7 +508,7 @@ private void connectFaces() { // run through arches - for (final GameObject arch : archetypeMap.values()) { + for (final GameObject arch : getArchetypes()) { final String faceName = arch.getFaceName(); if (faceName != null) { final Integer num = (Integer) faceMap.get(faceName); @@ -830,8 +831,13 @@ CMainStatusbar.getInstance().setText("Collect Archetypes: done."); } + /** + * Returns an array with all Archetypes. + * @return An array with all Archetypes. + */ public GameObject[] getArchList() { - return archetypeMap.values().toArray(new GameObject[archetypeMap.size()]); + final Collection<GameObject> archetypes = getArchetypes(); + return archetypes.toArray(new GameObject[archetypes.size()]); } /** Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 16:20:17 UTC (rev 469) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 16:45:57 UTC (rev 470) @@ -452,7 +452,7 @@ } private void connectFaces() { - for (final GameObject arch : archetypeMap.values()) { + for (final GameObject arch : getArchetypes()) { arch.setObjectFace(); } } @@ -498,7 +498,7 @@ int count = 0; // count how much arches we've collected - for (final GameObject arch : archetypeMap.values()) { + for (final GameObject arch : getArchetypes()) { // exclude arches generated from artifacts file from collection if (arch.isArtifact()) { Modified: trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java 2006-10-03 16:20:17 UTC (rev 469) +++ trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java 2006-10-03 16:45:57 UTC (rev 470) @@ -2,6 +2,8 @@ import java.util.Map; import java.util.TreeMap; +import java.util.Collection; +import java.util.Collections; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -15,7 +17,7 @@ private LoadStatus loadStatus = LoadStatus.EMPTY; /** The defined Archetypes. */ - protected final Map<String, T> archetypeMap = new TreeMap<String, T>(); + private final Map<String, T> archetypeMap = new TreeMap<String, T>(); /** * Whether Archetypes were loaded form an archive. @@ -55,10 +57,11 @@ if (!archetype.isArchetype()) { throw new IllegalArgumentException("Supplied GameObject " + archetype + " is not an Archetype."); } - if (archetypeMap.containsKey(archetype.getArchetypeName())) { + final String name = archetype.getArchetypeName(); + if (archetypeMap.containsKey(name)) { handleDuplicate(archetype); } else { - archetypeMap.put(archetype.getArchetypeName(), archetype); + archetypeMap.put(name, archetype); } } @@ -86,4 +89,12 @@ this.loadedFromArchive = loadedFromArchive; } + /** + * Returns a read-only collection of all Archetypes. + * @return A read-only collection of all Archetypes. + */ + protected Collection<T> getArchetypes() { + return Collections.unmodifiableCollection(archetypeMap.values()); + } + } // class AbstractArchetypeSet This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-03 17:22:00
|
Revision: 472 http://svn.sourceforge.net/gridarta/?rev=472&view=rev Author: christianhujer Date: 2006-10-03 10:21:26 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Replaced CFileReader and CFileInputStream with corresponding factory methods in newly added class IOUtils. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinList.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/CMapFileDecode.java trunk/crossfire/src/cfeditor/FaceObject.java trunk/crossfire/src/cfeditor/MultiPositionData.java trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CMapFileDecode.java trunk/daimonin/src/daieditor/CMapFileEncode.java trunk/daimonin/src/daieditor/MultiPositionData.java trunk/daimonin/src/daieditor/Spells.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/anim/AnimationObjects.java trunk/daimonin/src/daieditor/gui/map/MapTilePane.java trunk/src/app/net/sf/gridarta/textedit/scripteditor/CFPythonPopup.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/io/IOUtils.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/io/CFileInputStream.java trunk/src/app/net/sf/gridarta/io/CFileReader.java Modified: trunk/crossfire/src/cfeditor/AutojoinList.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinList.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/crossfire/src/cfeditor/AutojoinList.java 2006-10-03 17:21:26 UTC (rev 472) @@ -30,7 +30,8 @@ import java.awt.Point; import java.io.FileNotFoundException; import java.io.IOException; -import net.sf.gridarta.io.CFileReader; +import java.io.BufferedReader; +import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -96,74 +97,75 @@ // open the resource file final String baseDir = IGUIConstants.CONFIG_DIR; - final CFileReader stream = new CFileReader(baseDir, filename); + final BufferedReader stream = IOUtils.createReader(baseDir, filename); + try { - // read the file - while ((line = stream.readLine()) != null) { - if (!line.startsWith("#") && line.length() > 0) { - line = line.trim(); // remove whitespace at both ends + // read the file + while ((line = stream.readLine()) != null) { + if (!line.startsWith("#") && line.length() > 0) { + line = line.trim(); // remove whitespace at both ends - if (!sectionFlag) { - // we are outside a section - if (line.equals("start")) { - sectionFlag = true; - count = 0; - } - } else { - // we are inside a section - if (line.equals("end")) { - if (count == 16) { - // we have 16 valid entries, now stick it into an AutojoinList - if (success) { - // attach a new element to the linked list - jlist.next = new AutojoinList(); - jlist = jlist.next; - } + if (!sectionFlag) { + // we are outside a section + if (line.equals("start")) { + sectionFlag = true; + count = 0; + } + } else { + // we are inside a section + if (line.equals("end")) { + if (count == 16) { + // we have 16 valid entries, now stick it into an AutojoinList + if (success) { + // attach a new element to the linked list + jlist.next = new AutojoinList(); + jlist = jlist.next; + } - jlist.stack = archstack; // set link to arch stack - jlist.archnames = new String[16]; // array to store the archetype names - for (int i = 0; i < 16; i++) { - jlist.archnames[i] = nbuf[i]; // store archetype name in the list - archstack.getArchetype(nbuf[i]).setJoinList(jlist); // set the link in the def. arch - if (log.isDebugEnabled()) { - log.debug("(" + i + ") arch: '" + archstack.getArchetype(nbuf[i]).getArchetypeName() + "' -> (" + nbuf[i] + ")"); + jlist.stack = archstack; // set link to arch stack + jlist.archnames = new String[16]; // array to store the archetype names + for (int i = 0; i < 16; i++) { + jlist.archnames[i] = nbuf[i]; // store archetype name in the list + archstack.getArchetype(nbuf[i]).setJoinList(jlist); // set the link in the def. arch + if (log.isDebugEnabled()) { + log.debug("(" + i + ") arch: '" + archstack.getArchetype(nbuf[i]).getArchetypeName() + "' -> (" + nbuf[i] + ")"); + } } + + success = true; // we did it! + } else if (count > 16) { + log.warn("In file " + filename + ": List with more than 16 valid entries!"); + } else if (archstack.getArchetypeCount() >= 1) { + log.warn("In file " + filename + ": List with less than 16 valid entries!"); } + sectionFlag = false; + } else if (count < 16) { + // add a new archid to the buffer - success = true; // we did it! - } else if (count > 16) { - log.warn("In file " + filename + ": List with more than 16 valid entries!"); - } else if (archstack.getArchetypeCount() >= 1) { - log.warn("In file " + filename + ": List with less than 16 valid entries!"); - } - sectionFlag = false; - } else if (count < 16) { - // add a new archid to the buffer + final GameObject arch = archstack.getArchetype(line); + if (arch != null) { + nbuf[count] = line; - final GameObject arch = archstack.getArchetype(line); - if (arch != null) { - nbuf[count] = line; - - if (!arch.isMulti()) { - count++; // no multipart, this one's okay + if (!arch.isMulti()) { + count++; // no multipart, this one's okay + } else { + log.warn("In file " + filename + ": Arch '" + line + "' is a multipart."); + } } else { - log.warn("In file " + filename + ": Arch '" + line + "' is a multipart."); + // (If no arches exist at all, errormessages are suppressed here) + if (archstack.getArchetypeCount() >= 1) { + log.warn("In file " + filename + ": Arch '" + line + "' not found."); + } } } else { - // (If no arches exist at all, errormessages are suppressed here) - if (archstack.getArchetypeCount() >= 1) { - log.warn("In file " + filename + ": Arch '" + line + "' not found."); - } + count++; // too many arches } - } else { - count++; // too many arches } } } + } finally { + stream.close(); } - - // close filestream - stream.close(); } catch (FileNotFoundException e) { if (log.isInfoEnabled()) { log.info("Autojoin definitions file '" + filename + "' not found."); @@ -271,7 +273,7 @@ /** * Looking up the given node in the archnames-array of this class. - * @param node node to lookup + * @param archname node to lookup * @return index of the node in the array. */ private int getIndex(final String archname) { Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-10-03 17:21:26 UTC (rev 472) @@ -39,7 +39,7 @@ import java.util.Vector; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; import org.jdom.Attribute; import org.jdom.DataConversionException; @@ -90,7 +90,7 @@ try { // open ascii filestream to the xml data final String baseDir = IGUIConstants.CONFIG_DIR; - final CFileReader fread = new CFileReader(baseDir, IGUIConstants.TYPEDEF_FILE); + final BufferedReader fread = IOUtils.createReader(baseDir, IGUIConstants.TYPEDEF_FILE); try { // parse xml document @@ -296,7 +296,7 @@ try { // open reading stream to the spells xml file final String baseDir = IGUIConstants.CONFIG_DIR; - final CFileReader reader = new CFileReader(baseDir, IGUIConstants.SPELL_FILE); + final BufferedReader reader = IOUtils.createReader(baseDir, IGUIConstants.SPELL_FILE); try { // parse xml document final SAXBuilder builder = new SAXBuilder(); @@ -418,17 +418,17 @@ fileReader = new FileReader(spellfile.getAbsolutePath()); bufferedReader = new BufferedReader(fileReader); - CFileReader.readUntil(bufferedReader, "spell spells", null); - CFileReader.readUntil(bufferedReader, "{", null); + IOUtils.readUntil(bufferedReader, "spell spells", null); + IOUtils.readUntil(bufferedReader, "{", null); // reading spellnames one after the other, // this loop is terminated by an EOFException int i = 0; // index for insertion in the vector for (int counter = 0; true; counter++) { - CFileReader.readUntil(bufferedReader, "{", "}"); - CFileReader.readUntil(bufferedReader, "\"", null); - String name = CFileReader.readUntil(bufferedReader, "\""); - CFileReader.readUntil(bufferedReader, "}", null); + IOUtils.readUntil(bufferedReader, "{", "}"); + IOUtils.readUntil(bufferedReader, "\"", null); + String name = IOUtils.readUntil(bufferedReader, "\""); + IOUtils.readUntil(bufferedReader, "}", null); name = name.trim(); // now insert this string lexographically into the vector Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-10-03 17:21:26 UTC (rev 472) @@ -29,7 +29,6 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; -import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; @@ -53,7 +52,7 @@ import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreePath; import net.sf.gridarta.help.Help; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -238,7 +237,7 @@ // first step: parsing datafile, adding all treasurelists to the tmpList vector try { final String baseDir = IGUIConstants.CONFIG_DIR; - final CFileReader reader = new CFileReader(baseDir, IGUIConstants.TREASURES_FILE); + final BufferedReader reader = IOUtils.createReader(baseDir, IGUIConstants.TREASURES_FILE); String line = null; // read line of file // read the whole file line by line Modified: trunk/crossfire/src/cfeditor/CMapFileDecode.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapFileDecode.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/crossfire/src/cfeditor/CMapFileDecode.java 2006-10-03 17:21:26 UTC (rev 472) @@ -34,7 +34,7 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -75,7 +75,7 @@ * @todo create a separate exception for the wrong format */ public List<GameObject> decodeMapFile(final File file) throws FileNotFoundException, IOException { - final BufferedReader myInput = new BufferedReader(new InputStreamReader(new FileInputStream(file), CFileReader.MAP_ENCODING)); + final BufferedReader myInput = new BufferedReader(new InputStreamReader(new FileInputStream(file), IOUtils.MAP_ENCODING)); try { maxxlen = 0; maxylen = 0; Modified: trunk/crossfire/src/cfeditor/FaceObject.java =================================================================== --- trunk/crossfire/src/cfeditor/FaceObject.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/crossfire/src/cfeditor/FaceObject.java 2006-10-03 17:21:26 UTC (rev 472) @@ -27,10 +27,11 @@ import com.sixlegs.image.png.PngImage; import java.awt.Toolkit; import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.lang.ref.Reference; import java.lang.ref.SoftReference; import javax.swing.ImageIcon; -import net.sf.gridarta.io.CFileInputStream; +import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -97,17 +98,21 @@ if (log.isDebugEnabled()) { log.debug("Lazy loading " + name); } - final CFileInputStream fi = new CFileInputStream(ressourceDirectory, ressourceName); - if (dataStartIndex > 0) { - fi.skip(dataStartIndex); + final InputStream fi = IOUtils.createStream(ressourceDirectory, ressourceName); + try { + if (dataStartIndex > 0) { + fi.skip(dataStartIndex); // FIXME: result of skip is ignored. + } + final byte[] data = new byte[dataSize]; + fi.read(data); // FIXME: result of read is ignored. + final PngImage png = new PngImage(new ByteArrayInputStream(data)); // read png data from bytestream + png.setFlushAfterNextProduction(true); + final ImageIcon im = new ImageIcon(Toolkit.getDefaultToolkit().createImage(png)); + setFace(im); + return im; + } finally { + fi.close(); } - final byte[] data = new byte[dataSize]; - fi.read(data); - final PngImage png = new PngImage(new ByteArrayInputStream(data)); // read png data from bytestream - png.setFlushAfterNextProduction(true); - final ImageIcon im = new ImageIcon(Toolkit.getDefaultToolkit().createImage(png)); - setFace(im); - return im; } catch (final Exception e) { log.warn("Problem lazy loading face " + name, e); return null; Modified: trunk/crossfire/src/cfeditor/MultiPositionData.java =================================================================== --- trunk/crossfire/src/cfeditor/MultiPositionData.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/crossfire/src/cfeditor/MultiPositionData.java 2006-10-03 17:21:26 UTC (rev 472) @@ -27,8 +27,9 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.BufferedReader; import java.util.StringTokenizer; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; /** @@ -74,7 +75,7 @@ private void load() { // read datafile line by line, parsing numbers into the array try { - final CFileReader reader = new CFileReader(CMainControl.getInstance().getArchDefaultFolder() + File.separator + IGUIConstants.CONFIG_DIR, IGUIConstants.ARCHDEF_FILE); + final BufferedReader reader = IOUtils.createReader(CMainControl.getInstance().getArchDefaultFolder() + File.separator + IGUIConstants.CONFIG_DIR, IGUIConstants.ARCHDEF_FILE); try { String num; // number, still in string format int xp = 0; // x-index in the data array Modified: trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-03 17:21:26 UTC (rev 472) @@ -35,7 +35,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; import org.jdom.DataConversionException; import org.jdom.Document; @@ -85,7 +85,7 @@ try { // open reading stream to the spells xml file final String baseDir = IGUIConstants.CONFIG_DIR; - final CFileReader reader = new CFileReader(baseDir, IGUIConstants.TYPENR_FILE); + final BufferedReader reader = IOUtils.createReader(baseDir, IGUIConstants.TYPENR_FILE); try { // parse xml document Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 17:21:26 UTC (rev 472) @@ -44,6 +44,7 @@ import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; import java.util.Arrays; import java.util.Date; import java.util.HashMap; @@ -56,8 +57,7 @@ import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.SwingConstants; -import net.sf.gridarta.io.CFileInputStream; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import net.sf.gridarta.gameobject.AbstractArchetypeSet; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -191,7 +191,7 @@ try { // open the resource file - final CFileReader stream = new CFileReader(IGUIConstants.CONFIG_DIR, IGUIConstants.ARCH_FILE); + final BufferedReader stream = IOUtils.createReader(IGUIConstants.CONFIG_DIR, IGUIConstants.ARCH_FILE); try { // load all arches mainControl.getArchObjectParser().parseDefArchFromStream(stream, 0); @@ -201,7 +201,7 @@ } loadAllCrossfirePNGFromCollect(); } catch (final FileNotFoundException e) { - // no need for a message here, CFileReader takes care of this + log.error("Error:", e); } catch (final IOException e) { log.error("Error:", e); } @@ -339,7 +339,7 @@ try { // open a bytestream to the resource file final String baseDir = IGUIConstants.CONFIG_DIR; - final CFileInputStream stream = new CFileInputStream(baseDir, IGUIConstants.PNG_FILE); + final InputStream stream = IOUtils.createStream(baseDir, IGUIConstants.PNG_FILE); try { int r; Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-10-03 17:21:26 UTC (rev 472) @@ -64,7 +64,7 @@ import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreePath; import net.sf.gridarta.help.Help; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import net.sf.japi.util.EnumerationIterator; import org.jetbrains.annotations.Nullable; @@ -222,7 +222,6 @@ final List<TreasureTreeNode> tmpList = new ArrayList<TreasureTreeNode>(); // tmp. container for all treasurelists final List<TreasureTreeNode> needLink = new ArrayList<TreasureTreeNode>(); // all sub-treasurelist nodes that need linking treasureTable = new HashMap<String, TreasureTreeNode>(); // hashtable for all treasureTreeNodes - final CFileReader reader = null; // first step: parsing datafile, adding all treasurelists to the tmpList vector loadTreasureList(IGUIConstants.TREASURES_FILE, tmpList, needLink); @@ -328,7 +327,7 @@ } else { baseDir = CMainControl.getInstance().getArchDefaultFolder(); } - final CFileReader reader = new CFileReader(baseDir, fname); + final BufferedReader reader = IOUtils.createReader(baseDir, fname); // read the whole file line by line try { for (String rawLine; (rawLine = reader.readLine()) != null;) { Modified: trunk/daimonin/src/daieditor/CMapFileDecode.java =================================================================== --- trunk/daimonin/src/daieditor/CMapFileDecode.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/daimonin/src/daieditor/CMapFileDecode.java 2006-10-03 17:21:26 UTC (rev 472) @@ -35,7 +35,7 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -75,7 +75,7 @@ * @todo create a separate exception for the wrong format */ @NotNull public synchronized List<GameObject> decodeMapFile(@NotNull final File file, final String mapDir) throws FileNotFoundException, IOException { - final BufferedReader myInput = new BufferedReader(new InputStreamReader(new FileInputStream(file), CFileReader.MAP_ENCODING)); + final BufferedReader myInput = new BufferedReader(new InputStreamReader(new FileInputStream(file), IOUtils.MAP_ENCODING)); try { objects = new ArrayList<GameObject>(); // first of all we read the map arch (if that fails we throw an exception) Modified: trunk/daimonin/src/daieditor/CMapFileEncode.java =================================================================== --- trunk/daimonin/src/daieditor/CMapFileEncode.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/daimonin/src/daieditor/CMapFileEncode.java 2006-10-03 17:21:26 UTC (rev 472) @@ -34,7 +34,7 @@ import java.io.IOException; import java.util.Formatter; import net.sf.gridarta.Size2D; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; /** * The <code>CMapFileEncode</code> is used to write a map to a file. @@ -63,7 +63,7 @@ public void encodeMapFile(final File file, final MapModel mapModel) throws FileNotFoundException, IOException { final MapArchObject mapArch = mapModel.getMapArchObject(); try { - format = new Formatter(file, CFileReader.MAP_ENCODING); + format = new Formatter(file, IOUtils.MAP_ENCODING); //GameObject multi; // write map header: map arch Modified: trunk/daimonin/src/daieditor/MultiPositionData.java =================================================================== --- trunk/daimonin/src/daieditor/MultiPositionData.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/daimonin/src/daieditor/MultiPositionData.java 2006-10-03 17:21:26 UTC (rev 472) @@ -29,7 +29,8 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import net.sf.gridarta.io.CFileReader; +import java.io.BufferedReader; +import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; /** @@ -74,7 +75,7 @@ private void load() { // read datafile line by line, parsing numbers into the array try { - final CFileReader reader = new CFileReader(CMainControl.getInstance().getArchDefaultFolder() + File.separator + IGUIConstants.CONFIG_DIR, IGUIConstants.ARCHDEF_FILE); + final BufferedReader reader = IOUtils.createReader(CMainControl.getInstance().getArchDefaultFolder() + File.separator + IGUIConstants.CONFIG_DIR, IGUIConstants.ARCHDEF_FILE); try { final Dimension d = new Dimension(); final Point p = new Point(); Modified: trunk/daimonin/src/daieditor/Spells.java =================================================================== --- trunk/daimonin/src/daieditor/Spells.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/daimonin/src/daieditor/Spells.java 2006-10-03 17:21:26 UTC (rev 472) @@ -39,7 +39,7 @@ import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import javax.xml.parsers.DocumentBuilder; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; import net.sf.japi.util.filter.file.FilenameFileFilter; @@ -109,14 +109,14 @@ try { final BufferedReader in = new BufferedReader(new FileReader(spellfile.getAbsolutePath())); try { - CFileReader.readUntil(in, "spell spells", null); - CFileReader.readUntil(in, "{", null); + IOUtils.readUntil(in, "spell spells", null); + IOUtils.readUntil(in, "{", null); for (int counter = 0; true; counter++) { // XXX this is ugly! - CFileReader.readUntil(in, "{", "}"); - CFileReader.readUntil(in, "\"", null); - final String name = CFileReader.readUntil(in, "\"").trim(); - CFileReader.readUntil(in, "}", null); + IOUtils.readUntil(in, "{", "}"); + IOUtils.readUntil(in, "\"", null); + final String name = IOUtils.readUntil(in, "\"").trim(); + IOUtils.readUntil(in, "}", null); spells.put(name, Integer.toString(counter)); } Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 17:21:26 UTC (rev 472) @@ -58,7 +58,7 @@ import java.util.List; import java.util.Map; import javax.swing.ImageIcon; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import net.sf.gridarta.gameobject.AbstractArchetypeSet; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; @@ -297,7 +297,7 @@ loadAllDaimoninAnimationsFromCollect(); // open the resource file final String baseDir = CMainControl.getInstance().getArchDefaultFolder(); - final CFileReader stream = new CFileReader(baseDir, IGUIConstants.ARCH_FILE); + final BufferedReader stream = IOUtils.createReader(baseDir, IGUIConstants.ARCH_FILE); try { // load all arches mainControl.getArchObjectParser().parseDefArchFromStream(stream, 0, IGUIConstants.ARCH_FILE); @@ -409,7 +409,7 @@ /** Loading all animations from the big collected animations file. */ private void loadAllDaimoninAnimationsFromCollect() { try { - final Reader in = new CFileReader(mainControl.getArchDefaultFolder(), "animations"); + final Reader in = IOUtils.createReader(mainControl.getArchDefaultFolder(), "animations"); try { mainControl.getAnimationObjects().loadAnims(in, null); } finally { @@ -492,7 +492,7 @@ try { final File dfile = new File(mainControl.getArchDefaultFolder(), IGUIConstants.ARCH_FILE); // now open the output-stream - final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dfile), CFileReader.MAP_ENCODING)); + final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dfile), IOUtils.MAP_ENCODING)); try { int artifactCount = 0; @@ -662,7 +662,7 @@ */ private void collectDaimoninAnimations(final Progress pbar) { try { - final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(mainControl.getArchDefaultFolder(), "animations")), CFileReader.MAP_ENCODING)); + final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(mainControl.getArchDefaultFolder(), "animations")), IOUtils.MAP_ENCODING)); try { final AnimationObjects animationObjects = mainControl.getAnimationObjects(); pbar.setLabel(ACTION_FACTORY.getString("archCollectAnimations"), animationObjects.size()); @@ -692,7 +692,7 @@ */ private void collectDaimoninAnimationTree(final Progress pbar) { try { - final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(new File(mainControl.getArchDefaultFolder(), IGUIConstants.CONFIG_DIR), IGUIConstants.ANIMTREE_FILE)), CFileReader.MAP_ENCODING)); + final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(new File(mainControl.getArchDefaultFolder(), IGUIConstants.CONFIG_DIR), IGUIConstants.ANIMTREE_FILE)), IOUtils.MAP_ENCODING)); try { final AnimationObjects animationObjects = mainControl.getAnimationObjects(); final Map<String, String> tree = animationObjects.getAnimPathTree(); Modified: trunk/daimonin/src/daieditor/gameobject/anim/AnimationObjects.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/anim/AnimationObjects.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/daimonin/src/daieditor/gameobject/anim/AnimationObjects.java 2006-10-03 17:21:26 UTC (rev 472) @@ -36,7 +36,7 @@ import java.io.Reader; import java.util.HashMap; import java.util.Map; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import org.jetbrains.annotations.Nullable; @@ -102,7 +102,7 @@ * @throws DuplicateAnimationException in case an animation was not unique */ public void loadAnims(final File animFile) throws FileNotFoundException, IOException, AnimationParseException, DuplicateAnimationException { - final Reader in = new InputStreamReader(new FileInputStream(animFile), CFileReader.MAP_ENCODING); + final Reader in = new InputStreamReader(new FileInputStream(animFile), IOUtils.MAP_ENCODING); try { final String path = (new File(PathManager.getArchPath(animFile.getPath()))).getParent().replace('\\', '/'); loadAnims(in, path); @@ -180,7 +180,7 @@ * @throws FileNotFoundException in case the file couldn't be opened */ public void loadAnimTree(final File animTreeFile) throws FileNotFoundException, IOException { - final Reader in = new InputStreamReader(new FileInputStream(animTreeFile), CFileReader.MAP_ENCODING); + final Reader in = new InputStreamReader(new FileInputStream(animTreeFile), IOUtils.MAP_ENCODING); try { loadAnimTree(in); } finally { Modified: trunk/daimonin/src/daieditor/gui/map/MapTilePane.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapTilePane.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/daimonin/src/daieditor/gui/map/MapTilePane.java 2006-10-03 17:21:26 UTC (rev 472) @@ -58,7 +58,7 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import net.sf.gridarta.Size2D; -import net.sf.gridarta.io.CFileReader; +import net.sf.gridarta.io.IOUtils; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; import org.jetbrains.annotations.Nullable; @@ -632,7 +632,7 @@ for (final TileMapHeader tileHeader : tileHeaders) { if (tileHeader != null) { try { - final BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tileHeader.mapfile), CFileReader.MAP_ENCODING)); + final BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tileHeader.mapfile), IOUtils.MAP_ENCODING)); try { tileHeader.maparch.writeMapArch(bufferedWriter); final String tail = tileHeader.maptail.toString().trim(); @@ -772,7 +772,7 @@ @Nullable private static TileMapHeader loadMapFileHeader(final File file) { TileMapHeader maphead = null; try { - final BufferedReader myInput = new BufferedReader(new InputStreamReader(new FileInputStream(file), CFileReader.MAP_ENCODING)); + final BufferedReader myInput = new BufferedReader(new InputStreamReader(new FileInputStream(file), IOUtils.MAP_ENCODING)); try { // first of all we read the map arch (if that fails we throw an exception) Deleted: trunk/src/app/net/sf/gridarta/io/CFileInputStream.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/CFileInputStream.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/src/app/net/sf/gridarta/io/CFileInputStream.java 2006-10-03 17:21:26 UTC (rev 472) @@ -1,127 +0,0 @@ -/* - * Daimonin Java Editor. - * Copyright (C) 2000 Michael Toennies - * Copyright (C) 2001 Andreas Vogl - * Copyright (C) 2005 Christian Hujer - * - * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package net.sf.gridarta.io; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.net.URI; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Class for opening and reading a buffered stream to a BINARY resource-file. - * If no such file is found, the file is loaded from the jar archive. - * This class is very similar to {@link CFileReader}. - * The file is tried to open in the following order: - * <ol> - * <li>Try opening it with the given directory. The directory path is relative - * to the current working directory, the file path relative to that - * directory..</li> - * <li>Try opening it without the given directory. The file path is relative to - * the current working directory.</li> - * <li>Try opening the file as a system resource through the class loader.</li> - * </ol> - * Only if all tries failed, creating the stream fails. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @see CFileReader - * @todo eventually remove this class in terms of instantiability. All functionality provided by CFileInputStream is static. - */ -public final class CFileInputStream extends BufferedInputStream { - - /** - * Creates a new CFileInputStream to a specified resource file. - * @param dname name of directory that the file is in (<code>null</code> - * means the file is located in the editor root dir) - * @param fname name of the resource file - * @throws FileNotFoundException In case all three tries to open the file failed - */ - public CFileInputStream(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { - super(createStream(dname, fname)); - } - - /** - * Open the resource file for reading. - * @param dname directory name to read from - * @param fname file name of file to read - * @return Stream for reading from <var>fname</var> - * @throws FileNotFoundException In case all tries to open the file failed - */ - @SuppressWarnings({"MethodWithMultipleReturnPoints", "MethodWithMoreThanThreeNegations"}) - @NotNull private static InputStream createStream(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { - try { // 1st try normal binary file relative to specified directory - return new FileInputStream(new File(dname, fname)); - } catch (final Exception e) { - // ignore - } - try { // 2nd try binary file relative to user's current working directory - return new FileInputStream(fname); - } catch (final Exception e) { // 3rd try via system resource from class loader - // ignore - } - final URI currentDir = new File(System.getProperty("user.dir")).toURI(); - final String relWithDir = currentDir.relativize(new File(dname, fname).toURI()).toString(); - final String relPlain = currentDir.relativize(new File(fname).toURI()).toString(); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - try { // 3rd try context class loader relative to specified directory - @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(relWithDir); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - try { // 4th try context class loader relative to class loader's top level directory - @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(relPlain); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - try { // 5th try system class loader relative to specified directory - @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(relWithDir); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - try { // 6th try system class loader relative to class loader's top level directory - @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(relPlain); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - throw new FileNotFoundException("CFileInputStream couldn't find " + new File(dname, fname) + "."); - } - -} // class CFileInputStream Deleted: trunk/src/app/net/sf/gridarta/io/CFileReader.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/CFileReader.java 2006-10-03 17:11:54 UTC (rev 471) +++ trunk/src/app/net/sf/gridarta/io/CFileReader.java 2006-10-03 17:21:26 UTC (rev 472) @@ -1,187 +0,0 @@ -/* - * Daimonin Java Editor. - * Copyright (C) 2000 Michael Toennies - * Copyright (C) 2001 Andreas Vogl - * Copyright (C) 2005 Christian Hujer - * - * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package net.sf.gridarta.io; - -import java.io.BufferedReader; -import java.io.EOFException; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.UnsupportedEncodingException; - -/** - * Class for opening and reading a buffered stream to an ASCII resource-file. - * If no such file is found, the file is loaded from the jar archive. - * This class is very similar to {@link CFileInputStream}. - * The file is tried to open in the following order: - * <ol> - * <li>Try opening it with the given directory. The directory path is relative to the current working directory, the file path relative to that - * directory..</li> - * <li>Try opening it without the given directory. The file path is relative to the current working directory.</li> - * <li>Try opening the file as a system resource through the class loader.</li> - * </ol> - * Only if all tries failed, creating the stream fails. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @todo eventually remove readUntil - this is afaik only used for reading arches and such, and since there should be an integrated arch editor... - * @todo eventually remove this class in terms of instantiability. All functionality provided by CFileReader is static. - * @see CFileInputStream - */ -public final class CFileReader extends BufferedReader { - - /** Maximum number of characters to read in readUntil. */ - private static final long READ_MAX = 10000L; - - /** - * Encoding to use for maps and other data. - * The encoding given here is used for reading and writing maps. - * You shouldn't change this only because you use an UTF-8 system or so, since the encoding used here MUST be compatible with the server and the - * client. The paragraph sign § is the critical character. - * @todo once the mailing list decided on the § character, eventually replace by "us-ascii". - */ - public static final String MAP_ENCODING = "iso-8859-1"; - - /** - * Open an ascii-stream to the specified resource file. - * @param dname name of directory that the file is in (<code>null</code> means the file is located in the editor root dir) - * @param fname name of the resource file - * @throws FileNotFoundException in case all three tries to open the file failed - */ - public CFileReader(final String dname, final String fname) throws FileNotFoundException { - super(createReader(dname, fname)); - } - - /** - * Open the resource file for reading. - * @param dname name of directory that the file is in (null means the file is located in the editor root dir) - * @param fname name of the resource file - * @return Stream for reading from <var>fname</var> - * @throws FileNotFoundException In case all three tries to open the file failed - */ - private static Reader createReader(final String dname, final String fname) throws FileNotFoundException { - try { - return new InputStreamReader(new CFileInputStream(dname, fname), MAP_ENCODING); - } catch (final UnsupportedEncodingException e) { - throw new Error(e); - } - } - - /** - * Reads characters from the BufferedReader stream till 'tag' is found. If - * found, the method returns with stream pointing right after the - * appearance of 'tag'. - * @param stream ascii input stream to read from - * @param tag stop reading at the string 'tag' - * @param abort throw <code>EOFException</code> at string 'abort' (this can be null) - * @throws IOException an I/O-error occurred while reading the file - * @throws EOFException the end of file was reached, or the 'abort' string - * has been encountered - * @todo Should the encounter of the abort string before the tag really be - * an EOFException? That's semantically wrong, but current usage code - * relies on this :( - */ - public static void readUntil(final BufferedReader stream, final String tag, final String abort) throws IOException { - int c; // character value, read from the stream - int t = 0; // tag index - int a = 0; // abort index - - if (abort != null) { - // look both for 'tag' and 'abort' - do { - c = stream.read(); - if (c == tag.charAt(t)) { - t++; - } else { - t = 0; - } - if (c == abort.charAt(a)) { - a++; - } else { - a = 0; - } - } while (t < tag.length() && a < abort.length() && c != -1); - } else { - // look only for 'tag' - do { - c = stream.read(); - if (c == tag.charAt(t)) { - t++; - } else { - t = 0; - } - } while (t < tag.length() && c != -1); - } - - // if we did not find the tag, an EOFException is thrown - if (c == -1) { - throw new EOFException(); - } - - // if we found the string 'abort', throw EOFException as well - if (abort != null && a == abort.length()) { - throw new EOFException(); - } - } - - /** - * Reads characters from the BufferedReader stream till 'tag' is found. - * Similar to readUntil(), except that the read String is returned. 'tag' - * is not included in the returned String. - * @param stream ascii input stream to read from - * @param tag stop reading at the string 'tag' - * @return the string between the starting pos. of 'stream' (inclusive) and - * the first character of 'tag' (exclusive). - * @throws IOException an I/O-error occurred while reading the file - * @throws EOFException the end of file was reached - */ - public static String readUntil(final BufferedReader stream, final String tag) throws IOException { - final StringBuilder sb = new StringBuilder(); - int c; // character value, read from the stream - int t = 0; // index - - long count = 0; // counter (to realize when shooting past EOF) - final long maxCount = READ_MAX; // bail out when counter exceeds this value - - do { - c = stream.read(); // read one character - sb.append((char) c); - if (c == tag.charAt(t)) { - t++; - } else { - t = 0; - } - } while (t < tag.length() && c != -1 && count++ < maxCount); - - // if we did not find the tag, an EOFException is thrown - if (c == -1 || count >= maxCount) { - throw new EOFException(); - } - // cut 'tag' off, at the end of the string - return sb.substring(0, sb.length() - tag.length()); - } - -} // class CFileReader Added: trunk/src/app/net/sf/gridarta/io/IOUtils.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/IOUtils.java (rev 0) +++ trunk/src/app/net/sf/gridarta/io/IOUtils.java 2006-10-03 17:21:26 UTC (rev 472) @@ -0,0 +1,229 @@ +package net.sf.gridarta.io; + +import java.io.Reader; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.EOFException; +import java.io.InputStream; +import java.io.FileInputStream; +import java.io.File; +import java.io.BufferedInputStream; +import java.net.URI; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Utility-class for Gridarta's I/O. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public final class IOUtils { + + /** Maximum number of characters to read in readUntil. */ + public static final long READ_MAX = 10000L; + + /** + * Encoding to use for maps and other data. + * The encoding given here is used for reading and writing maps. + * You shouldn't change this only because you use an UTF-8 system or so, since the encoding used here MUST be compatible with the server and the + * client. The paragraph sign § is the critical character. + * @todo once the mailing list decided on the § character, eventually replace by "us-ascii". + */ + public static final String MAP_ENCODING = "iso-8859-1"; + + /** Utility class - do not instanciate. */ + private IOUtils() { + } + + /** + * Open the resource file for reading. + * @param dname directory name to read from + * @param fname file name of file to read + * @return Stream for reading from <var>fname</var> + * @throws FileNotFoundException In case all tries to open the file failed + */ + @NotNull public static BufferedInputStream createStream(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { + return new BufferedInputStream(createStreamImpl(dname, fname)); + } + + /** + * Open the resource file for reading. + * @param dname directory name to read from + * @param fname file name of file to read + * @return Stream for reading from <var>fname</var> + * @throws FileNotFoundException In case all tries to open the file failed + */ + @SuppressWarnings({"MethodWithMultipleReturnPoints", "MethodWithMoreThanThreeNegations"}) + @NotNull private static InputStream createStreamImpl(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { + try { // 1st try normal binary file relative to specified directory + return new FileInputStream(new File(dname, fname)); + } catch (final Exception e) { + // ignore + } + try { // 2nd try binary file relative to user's current working directory + return new FileInputStream(fname); + } catch (final Exception e) { // 3rd try via system resource from class loader + // ignore + } + final URI currentDir = new File(System.getProperty("user.dir")).toURI(); + final String relWithDir = currentDir.relativize(new File(dname, fname).toURI()).toString(); + final String relPlain = currentDir.relativize(new File(fname).toURI()).toString(); + final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + try { // 3rd try context class loader relative to specified directory + @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(relWithDir); + if (stream != null) { + return stream; + } + } catch (final Exception e) { + // ignore + } + try { // 4th try context class loader relative to class loader's top level directory + @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(relPlain); + if (stream != null) { + return stream; + } + } catch (final Exception e) { + // ignore + } + try { // 5th try system class loader relative to specified directory + @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(relWithDir); + if (stream != null) { + return stream; + } + } catch (final Exception e) { + // ignore + } + try { // 6th try system class loader relative to class loader's top level directory + @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(relPlain); + if (stream != null) { + return stream; + } + } catch (final Exception e) { + // ignore + } + throw new FileNotFoundException("couldn't find " + new File(dname, fname) + "."); + } + + /** + * Open the resource file for reading. + * @param dname name of directory that the file is in (null means the file is located in the editor root dir) + * @param fname name of the resource file + * @return Stream for reading from <var>fname</var> + * @throws FileNotFoundException In case all three tries to open the file failed + */ + @NotNull public static BufferedReader createReader(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { + return new BufferedReader(createReaderImpl(dname, fname)); + } + + /** + * Open the resource file for reading. + * @param dname name of directory that the file is in (null means the file is located in the editor root dir) + * @param fname name of the resource file + * @return Stream for reading from <var>fname</var> + * @throws FileNotFoundException In case all three tries to open the file failed + */ + @NotNull private static Reader createReaderImpl(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { + try { + return new InputStreamReader(createStreamImpl(dname, fname), MAP_ENCODING); + } catch (final UnsupportedEncodingException e) { + throw new Error(e); + } + } + + /** + * Reads characters from the BufferedReader stream till 'tag' is found. If + * found, the method returns with stream pointing right after the + * appearance of 'tag'. + * @param stream ascii input stream to read from + * @param tag stop reading at the string 'tag' + * @param abort throw <code>EOFException</code> at string 'abort' (this can be null) + * @throws IOException an I/O-error occurred while reading the file + * @throws EOFException the end of file was reached, or the 'abort' string + * has been encountered + * @todo Should the encounter of the abort string before the tag really be + * an EOFException? That's semantically wrong, but current usage code + * relies on this :( + */ + public static void readUntil(@NotNull final BufferedReader stream, @NotNull final String tag, @Nullable final String abort) throws IOException { + int c; // character value, read from the stream + int t = 0; // tag index + int a = 0; // abort index + + if (abort != null) { + // look both for 'tag' and 'abort' + do { + c = stream.read(); + if (c == tag.charAt(t)) { + t++; + } else { + t = 0; + } + if (c == abort.charAt(a)) { + a++; + } else { + a = 0; + } + } while (t < tag.length() && a < abort.length() && c != -1); + } else { + // look only for 'tag' + do { + c = stream.read(); + if (c == tag.charAt(t)) { + t++; + } else { + t = 0; + } + } while (t < tag.length() && c != -1); + } + + // if we did not find the tag, an EOFException is thrown + if (c == -1) { + throw new EOFException(); + } + + // if we found the string 'abort', throw EOFException as well + if (abort != null && a == abort.length()) { + throw new EOFException(); + } + } + + /** + * Reads characters from the BufferedReader stream till 'tag' is found. + * Similar to readUntil(), except that the read String is returned. 'tag' + * is not included in the returned String. + * @param stream ascii input stream to read from + * @param tag stop reading at the string 'tag' + * @return the string between the starting pos. of 'stream' (inclusive) and + * the first character of 'tag' (exclusive). + * @throws java.io.IOException an I/O-error occurred while reading the file + * @throws java.io.EOFException the end of file was reached + */ + public static String readUntil(@NotNull final BufferedReader stream, @NotNull final String tag) throws IOException { + final StringBuilder sb = new StringBuilder(); + int c; // character value, read from the stream + int t = 0; // index + + long count = 0; // counter (to realize when shooting past EOF) + final long maxCount = READ_MAX; // bail out when counter exceeds this value + + do { + c = stream.read(); // read one character + sb.append((char) c); + if (c == tag.charAt(t)) { + t++; + } else { + t = 0; + } + } while (t < tag.length() && c != -1 && count++ < maxCount); + + // if we did not find the tag, an EOFException is thrown + if (c == -1 || count >= maxCount) { + throw new EOFException(); + } + // cut 'tag' off, at the end of the string + return sb.substring(0, sb.length() - tag.length()); + } + +} // class IOUtils Property changes on: trunk/src/app/net/sf/gridarta/io/IOUtils.java ___________... [truncated message content] |
From: <chr...@us...> - 2006-10-03 18:42:51
|
Revision: 475 http://svn.sourceforge.net/gridarta/?rev=475&view=rev Author: christianhujer Date: 2006-10-03 11:42:15 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Clarified variable names to denote either gameObject or archetype. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinList.java trunk/crossfire/src/cfeditor/CArchPanelPan.java trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/crossfire/src/cfeditor/CMapTileList.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/parameter/ArchParameter.java trunk/daimonin/src/daieditor/CArchPanelPan.java trunk/daimonin/src/daieditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java Modified: trunk/crossfire/src/cfeditor/AutojoinList.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinList.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/crossfire/src/cfeditor/AutojoinList.java 2006-10-03 18:42:15 UTC (rev 475) @@ -327,18 +327,18 @@ * Add/remove a certain connection of the given arch * by changing archtype and face. */ - private void connectArch(final GameObject arch, final String archname) { - final GameObject defarch = stack.getArchetype(archname); // new default arch + private void connectArch(final GameObject gameObject, final String archname) { + final GameObject archetype = stack.getArchetype(archname); // new default arch - if (!arch.getArchetypeName().equals(archname)) { + if (!gameObject.getArchetypeName().equals(archname)) { // set new archtype - arch.setArchetypeName(archname); + gameObject.setArchetypeName(archname); // set face of new default arch - arch.setFaceNr(defarch.getFaceNr()); - arch.setFaceFlag(defarch.getFaceFlag()); - if (arch.getFaceName() != null && arch.getFaceName().length() > 0) { - arch.setFaceName(null); // take default face + gameObject.setFaceNr(archetype.getFaceNr()); + gameObject.setFaceFlag(archetype.getFaceFlag()); + if (gameObject.getFaceName() != null && gameObject.getFaceName().length() > 0) { + gameObject.setFaceName(null); // take default face } } } Modified: trunk/crossfire/src/cfeditor/CArchPanelPan.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-10-03 18:42:15 UTC (rev 475) @@ -120,23 +120,22 @@ } public GameObject getArchListObject() { - GameObject arch = null; + GameObject archetype = null; int index = theList.getSelectedIndex(); - if (index != -1) { final String archname = theList.getSelectedValue().toString(); - arch = mainControl.getArchetypeSet().getArchetype(archname); + archetype = mainControl.getArchetypeSet().getArchetype(archname); } - return arch; + return archetype; } public void showArchListObject(int index) { - GameObject arch = null; + GameObject archetype = null; if (index != -1) { try { final String archname = theList.getSelectedValue().toString(); - arch = mainControl.getArchetypeSet().getArchetype(archname); + archetype = mainControl.getArchetypeSet().getArchetype(archname); } catch (final NullPointerException e) { /* log.info("NullPointerException in showArchListObject()!", e); @@ -146,7 +145,7 @@ } catch (final NumberFormatException e) { } } - mainControl.showArchPanelQuickObject(arch); // send it to quick view + mainControl.showArchPanelQuickObject(archetype); // send it to quick view } /** @@ -270,19 +269,19 @@ /* We additionally set the JLabels icon property here. */ - final GameObject arch = mainControl.getArchetypeSet().getArchetype(value.toString()); + final GameObject archetype = mainControl.getArchetypeSet().getArchetype(value.toString()); if (isSelected) { archPanel.setPanelArch(value.toString()); mainControl.setStatusText(" " + value + " "); } - setText(arch.getArchetypeName()); + setText(archetype.getArchetypeName()); - if (arch.getFaceFlag()) { + if (archetype.getFaceFlag()) { setIcon(mainControl.getNofaceTileIcon()); - } else if (arch.getFaceNr() == -1) { + } else if (archetype.getFaceNr() == -1) { setIcon(mainControl.getUnknownTileIcon()); } else { - setIcon(mainControl.getFace(arch.getFaceNr())); + setIcon(mainControl.getFace(archetype.getFaceNr())); } return this; Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-10-03 18:42:15 UTC (rev 475) @@ -954,11 +954,11 @@ } else if (content.getType() != TreasureObj.FOLDER) { // normal arch: display the face icon if (CMainControl.getInstance().getArchetypeSet().getLoadStatus() == ArchetypeSet.LoadStatus.COMPLETE) { - final String archname = content.getName(); - final GameObject arch = CMainControl.getInstance().getArch(archname); - if (arch != null) { - if (!arch.getFaceFlag()) { - setIcon(CMainControl.getInstance().getFace(arch.getFaceNr())); + final String archetypeName = content.getName(); + final GameObject archetype = CMainControl.getInstance().getArchetype(archetypeName); + if (archetype != null) { + if (!archetype.getFaceFlag()) { + setIcon(CMainControl.getInstance().getFace(archetype.getFaceNr())); } else { setIcon(noface); } Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-03 18:42:15 UTC (rev 475) @@ -361,20 +361,10 @@ mainView.openHelpWindow(); } - // access to ArchNodeList - // remark: i use before some weird access to it, use this instead when you find it - public void addArchToList(final GameObject data) { - archetypeSet.addArchetype(data); + public GameObject getArchetype(final String archetypeName) { + return archetypeSet.getArchetype(archetypeName); } - public int getArchCount() { - return archetypeSet.getArchetypeCount(); - } - - public GameObject getArch(final String archname) { - return archetypeSet.getArchetype(archname); - } - public CopyBuffer getCopyBuffer() { return copybuffer; } @@ -959,33 +949,33 @@ final List<GameObject> tailList = new ArrayList<GameObject>(); // first: attach our map sucker to a default arch we have loaded for (final Iterator<GameObject> it = objects.iterator(); it.hasNext();) { - final GameObject arch = it.next(); - final GameObject defarch = archetypeSet.getArchetype(arch.getArchetypeName()); - if (defarch == null) { + final GameObject gameObject = it.next(); + final GameObject archetype = archetypeSet.getArchetype(gameObject.getArchetypeName()); + if (archetype == null) { // we had an unknown arch here!! // showMessage("Error Loading Map File "+file.getName(), "\n Found Unknown Arch < "+arch.getArchetypeName()+" >"); // return false; } else { - arch.setArchetype(defarch); + gameObject.setArchetype(archetype); } // 2nd: attach the right face... // if there was no special face added in map, get it from def object - if (arch.getFaceName() != null) { - final int index2 = ArchetypeSet.getFaceIndex(arch.getFaceName()); + if (gameObject.getFaceName() != null) { + final int index2 = ArchetypeSet.getFaceIndex(gameObject.getFaceName()); if (index2 == -1) { // just warn here we have not the gfx //showMessage("LOAD FILE", "Arch: "+arch.getFaceName()+" Face: " +arch.getFaceName()+" Face Name Unknown"); } else { - arch.setFaceNr(index2); + gameObject.setFaceNr(index2); } } // Ok, now is attached to default arch and loaded png // NOW we post parse the object... // (We calculate only edit types that are active, to save time) - archObjectParser.postParseMapArch(arch, tileEdit); + archObjectParser.postParseMapArch(gameObject, tileEdit); - archObjectParser.expandMulti(arch, tailList); + archObjectParser.expandMulti(gameObject, tailList); } for (final GameObject tail : tailList) { Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-10-03 18:42:15 UTC (rev 475) @@ -306,33 +306,34 @@ // If the active arch is part of a multi, the mutli-head's stats // are taken instead: - final GameObject arch = activeArch.getHead(); + final GameObject gameObject = activeArch.getHead(); - final GameObject defarch = mainControl.getArch(arch.getArchetypeName()); - if (defarch == null) { // hm, this should NOT happen + // FIXME cher: shouldn't this be replaced by archetype = gameObject.getArchetype() ? + final GameObject archetype = mainControl.getArchetype(gameObject.getArchetypeName()); + if (archetype == null) { // hm, this should NOT happen return; } - final String oldArchText = arch.getObjectText(); - final String oldMsg = arch.getMsgText(); + final String oldArchText = gameObject.getObjectText(); + final String oldMsg = gameObject.getMsgText(); // We update all panels: name, face, msg and archText (more to come...) // the obj name: if (testForText(archNameField.getText())) { // there is something in // if this equal the default name... - if (defarch.getObjName() != null) { - if (archNameField.getText().compareTo(defarch.getObjName()) == 0) { - arch.setObjName(null); // yes, we don't need it in map + if (archetype.getObjName() != null) { + if (archNameField.getText().compareTo(archetype.getObjName()) == 0) { + gameObject.setObjName(null); // yes, we don't need it in map } else { - arch.setObjName(archNameField.getText()); // overrule in map arch + gameObject.setObjName(archNameField.getText()); // overrule in map arch } - } else if (archNameField.getText().compareTo(arch.getArchetypeName()) == 0) { - arch.setObjName(null); + } else if (archNameField.getText().compareTo(gameObject.getArchetypeName()) == 0) { + gameObject.setObjName(null); } else { // def is null, something is in panel, so we set it - arch.setObjName(archNameField.getText()); // overrule in map arch + gameObject.setObjName(archNameField.getText()); // overrule in map arch } } else { - arch.setObjName(null); // nothing in, nothing in map arch + gameObject.setObjName(null); // nothing in, nothing in map arch // hm, there is no way yet to overrule a default arch name with "nothing" // like <name > ore <name "">..?? } @@ -340,12 +341,12 @@ // set face if (testForText(archFaceField.getText())) { // there is something in // check if we need a map redraw - if (defarch.getFaceName() != null) { + if (archetype.getFaceName() != null) { final String facename; - if (arch.getFaceName() != null) { - facename = arch.getFaceName(); + if (gameObject.getFaceName() != null) { + facename = gameObject.getFaceName(); } else { - facename = defarch.getFaceName(); + facename = archetype.getFaceName(); } if (archFaceField.getText() != null && @@ -354,81 +355,81 @@ } } - if (defarch.getFaceName() != null) { - if (archFaceField.getText().compareTo(defarch.getFaceName()) == 0) { - arch.setFaceName(null); // yes, we don't need it in map + if (archetype.getFaceName() != null) { + if (archFaceField.getText().compareTo(archetype.getFaceName()) == 0) { + gameObject.setFaceName(null); // yes, we don't need it in map } else { - arch.setFaceName(archFaceField.getText()); // overrule in map arch + gameObject.setFaceName(archFaceField.getText()); // overrule in map arch } } else { - arch.setFaceName(archFaceField.getText()); // overrule in map arch + gameObject.setFaceName(archFaceField.getText()); // overrule in map arch } } else { - if (arch.getFaceName() != null) { + if (gameObject.getFaceName() != null) { needRedraw = true; // reset to default arch - needs redraw } - arch.setFaceName(null); // nothing in, nothing in map arch + gameObject.setFaceName(null); // nothing in, nothing in map arch // also, no overrule... } - if (arch.getFaceName() != null) { + if (gameObject.getFaceName() != null) { // we have a non-default face - final int index = ArchetypeSet.getFaceIndex(arch.getFaceName()); - arch.setFaceNr(index); + final int index = ArchetypeSet.getFaceIndex(gameObject.getFaceName()); + gameObject.setFaceNr(index); } else { // we have the default face - final int index = ArchetypeSet.getFaceIndex(defarch.getFaceName()); - arch.setFaceNr(index); + final int index = ArchetypeSet.getFaceIndex(archetype.getFaceName()); + gameObject.setFaceNr(index); } // the msg TEXT!! ("msg ... endmsg") // if there is an entry in the archTextArea (msg window), this // overrules the default text (if any) if (testForText(archTextArea.getText())) { // there is something in the msg win - if (defarch.getMsgText() != null) { + if (archetype.getMsgText() != null) { // trim text from message window String newMsgtext = archTextArea.getText(); if (newMsgtext != null) { newMsgtext = newMsgtext.trim(); } - if (newMsgtext.equals(defarch.getMsgText().trim())) { - arch.deleteMsgText(); // yes, we don't need it in map + if (newMsgtext.equals(archetype.getMsgText().trim())) { + gameObject.deleteMsgText(); // yes, we don't need it in map } else { - arch.resetMsgText(); - arch.addMsgText(newMsgtext); + gameObject.resetMsgText(); + gameObject.addMsgText(newMsgtext); } } else { - arch.resetMsgText(); - arch.addMsgText(archTextArea.getText()); + gameObject.resetMsgText(); + gameObject.addMsgText(archTextArea.getText()); } } else { // there is nothing in the msg win - arch.deleteMsgText(); // always delete this... - if (defarch.getMsgText() != null) { - arch.addMsgText(""); // but here we must overrule default with msg/endmsg (empty msg) + gameObject.deleteMsgText(); // always delete this... + if (archetype.getMsgText() != null) { + gameObject.addMsgText(""); // but here we must overrule default with msg/endmsg (empty msg) } } // read from archEdit (bottom right textwin) only the attributes // that differ from the default arch. These get stored into // the arche's archText (and finally in the map). - arch.setObjectText(defarch.diffArchText(archEdit.getText(), false)); + gameObject.setObjectText(archetype.diffArchText(archEdit.getText(), false)); // we look for 'type' in the ArchText. In future maybe type should get // a seperate textfield - if (arch.getAttributeString("type", false).length() > 0) { - arch.setArchTypNr(arch.getAttributeInt("type", false)); // specified type + if (gameObject.getAttributeString("type", false).length() > 0) { + gameObject.setArchTypNr(gameObject.getAttributeInt("type", false)); // specified type } // Recalculate the editType value. It shall stay 100% accurate ;) - arch.calculateEditType(mainControl.getCurrentMap().getActiveEditType()); + gameObject.calculateEditType(mainControl.getCurrentMap().getActiveEditType()); // if the archtext changed, set the map changed flag - if ((oldArchText != null && !oldArchText.equals(arch.getObjectText())) || - (oldArchText == null && arch.getObjectText() != null) || - (oldMsg != null && !oldMsg.equals(arch.getMsgText())) || - (oldMsg == null && arch.getMsgText() != null)) { + if ((oldArchText != null && !oldArchText.equals(gameObject.getObjectText())) || + (oldArchText == null && gameObject.getObjectText() != null) || + (oldMsg != null && !oldMsg.equals(gameObject.getMsgText())) || + (oldMsg == null && gameObject.getMsgText() != null)) { mainControl.getCurrentMap().setLevelChangedFlag(); } @@ -659,65 +660,65 @@ // If the active arch is part of a multi, the mutli-head's stats // are displayed (Only the head can store information!). - final GameObject arch = activeArch.getHead(); + final GameObject gameObject = activeArch.getHead(); // no text, we try to set the default text final boolean hasMessage; - if (arch.getMsgText() == null && arch.getArchetypeName() != null) { + if (gameObject.getMsgText() == null && gameObject.getArchetypeName() != null) { archTextArea.setForeground(Color.black); - if (mainControl.getArch(arch.getArchetypeName()).getMsgText() == null) { + if (mainControl.getArchetype(gameObject.getArchetypeName()).getMsgText() == null) { archTextArea.setText(""); hasMessage = false; } else { - archTextArea.setText(mainControl.getArch(arch.getArchetypeName()).getMsgText()); + archTextArea.setText(mainControl.getArchetype(gameObject.getArchetypeName()).getMsgText()); hasMessage = true; } } else { archTextArea.setForeground(Color.blue); - archTextArea.setText(arch.getMsgText()); + archTextArea.setText(gameObject.getMsgText()); hasMessage = true; } archTextArea.setCaretPosition(0); // end msg text // SET FACE - if (arch.getFaceFlag()) { + if (gameObject.getFaceFlag()) { archFaceField.setText(""); - } else if (arch.getFaceName() != null) { // custom face + } else if (gameObject.getFaceName() != null) { // custom face archFaceField.setForeground(Color.blue); - archFaceField.setText(arch.getFaceName()); - } else if (arch.getArchetypeName() != null) { + archFaceField.setText(gameObject.getFaceName()); + } else if (gameObject.getArchetypeName() != null) { archFaceField.setForeground(Color.black); - archFaceField.setText(mainControl.getArch(arch.getArchetypeName()).getFaceName()); + archFaceField.setText(mainControl.getArchetype(gameObject.getArchetypeName()).getFaceName()); } // end face // *** OBJECT NAME *** - if (arch.getObjName() == null && arch.getArchetypeName() != null) { + if (gameObject.getObjName() == null && gameObject.getArchetypeName() != null) { archNameField.setForeground(Color.black); - if (mainControl.getArch(arch.getArchetypeName()).getObjName() == null) { + if (mainControl.getArchetype(gameObject.getArchetypeName()).getObjName() == null) { // arch name - if (arch.getArchetypeName() != null) { - archNameField.setText(arch.getArchetypeName()); + if (gameObject.getArchetypeName() != null) { + archNameField.setText(gameObject.getArchetypeName()); } else { archNameField.setText(""); } } else { // default name - archNameField.setText(mainControl.getArch(arch.getArchetypeName()).getObjName()); + archNameField.setText(mainControl.getArchetype(gameObject.getArchetypeName()).getObjName()); } } else { // object name ("special") archNameField.setForeground(Color.blue); - archNameField.setText(arch.getObjName()); + archNameField.setText(gameObject.getObjName()); } // end ObjName // set hint for "specials": scripts/inventory/message String specialText = ""; final int i; - if ((i = arch.countInvObjects()) > 0) { + if ((i = gameObject.countInvObjects()) > 0) { specialText += "Inv: " + i; } - if (arch.isScripted()) { + if (gameObject.isScripted()) { specialText += specialText.length() > 0 ? ", Script" : "Script"; } if (hasMessage) { @@ -725,19 +726,19 @@ } archInvCount.setText(specialText); // set text to label - archMapPos.setText("Map: " + arch.getMapX() + ", " + arch.getMapY()); + archMapPos.setText("Map: " + gameObject.getMapX() + ", " + gameObject.getMapY()); - if (arch.getArchetypeName() != null) { - archTypeText.setText("Type: " + mainControl.getArchObjectParser().getArchTypeName(arch.getArchTypNr()) - + " (" + arch.getArchTypNr() + ") [" + arch.getArchetypeName() + "]"); + if (gameObject.getArchetypeName() != null) { + archTypeText.setText("Type: " + mainControl.getArchObjectParser().getArchTypeName(gameObject.getArchTypNr()) + + " (" + gameObject.getArchTypNr() + ") [" + gameObject.getArchetypeName() + "]"); } else { archTypeText.setText("Type: <unknown>"); } // check for multi tile - if (arch.isMulti()) { + if (gameObject.isMulti()) { // multi: print size - archTileText.setText("Tile: " + arch.getSizeX() + "x" + arch.getSizeY()); + archTileText.setText("Tile: " + gameObject.getSizeX() + "x" + gameObject.getSizeY()); } else { // single archTileText.setText("Tile: single"); @@ -749,8 +750,8 @@ try { // blue: the "special" attributes, differ from the default archetype StyleConstants.setForeground(currentAttributes, Color.blue); - if (arch.getObjectText() != null) { - doc.insertString(doc.getLength(), arch.getObjectText(), currentAttributes); + if (gameObject.getObjectText() != null) { + doc.insertString(doc.getLength(), gameObject.getObjectText(), currentAttributes); } // doc.insertString(doc.getLength(), "ID#"+arch.getMyID()+ " inv#: "+arch.countInvObjects()+"\n", currentAttributes); @@ -758,8 +759,8 @@ // black: the attributes from the default archetype // that don't exist among the "special" ones StyleConstants.setForeground(currentAttributes, Color.black); - if (arch.getObjectText() != null && mainControl.getArchetypeSet().getArchetype(arch.getArchetypeName()) != null) { - doc.insertString(doc.getLength(), arch.diffArchText(mainControl.getArchetypeSet().getArchetype(arch.getArchetypeName()).getObjectText(), true), currentAttributes); + if (gameObject.getObjectText() != null && mainControl.getArchetypeSet().getArchetype(gameObject.getArchetypeName()) != null) { + doc.insertString(doc.getLength(), gameObject.diffArchText(mainControl.getArchetypeSet().getArchetype(gameObject.getArchetypeName()).getObjectText(), true), currentAttributes); } } catch (final BadLocationException e) { // TODO @@ -767,9 +768,9 @@ archEdit.setCaretPosition(0); // ------ script panel ------ - if (arch.isScripted()) { + if (gameObject.isScripted()) { eventList.removeAll(); // clear event list - arch.addEventsToJList(eventList); // update JList to display all events + gameObject.addEventsToJList(eventList); // update JList to display all events s_modify.setEnabled(true); s_path.setEnabled(true); Modified: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-10-03 18:42:15 UTC (rev 475) @@ -404,7 +404,7 @@ final int num = Integer.parseInt(entry.substring(0, 10)); final int indent = Integer.parseInt(entry.substring(10, 20)); - GameObject arch = mainControl.getMapArch(num, currentSquare); + GameObject gameObject = mainControl.getMapArch(num, currentSquare); //String label; // We must set a disabled Icon (even though we don't want it) @@ -414,31 +414,31 @@ // arch == null should not happen, but it *can* happen when the active // window gets changed by user and java is still blitting here - if (arch != null) { - arch = arch.getHead(); + if (gameObject != null) { + gameObject = gameObject.getHead(); if (!isSelected && indent == 0) { this.setBackground(IGUIConstants.BG_COLOR); } - if (arch.getArchetypeName() == null) { + if (gameObject.getArchetypeName() == null) { setIcon(mainControl.getNoarchTileIcon()); - } else if (arch.getFaceFlag()) { + } else if (gameObject.getFaceFlag()) { setIcon(mainControl.getNofaceTileIcon()); - } else if (arch.getFaceNr() == -1) { + } else if (gameObject.getFaceNr() == -1) { setIcon(mainControl.getUnknownTileIcon()); } else { - setIcon(mainControl.getFace(arch.getFaceNr())); + setIcon(mainControl.getFace(gameObject.getFaceNr())); } // In the map-tile-window the object names are displayed // next to the icons - if (arch.getObjName() != null && arch.getObjName().length() > 0) { - setText(arch.getObjName()); // special name + if (gameObject.getObjName() != null && gameObject.getObjName().length() > 0) { + setText(gameObject.getObjName()); // special name } else { final String defname; - if (arch.getArchetypeName() != null) { - defname = mainControl.getArch(arch.getArchetypeName()).getObjName(); + if (gameObject.getArchetypeName() != null) { + defname = mainControl.getArchetype(gameObject.getArchetypeName()).getObjName(); } else { defname = null; } @@ -446,7 +446,7 @@ if (defname != null && defname.length() > 0) { setText(defname); // default name } else { - setText(arch.getArchetypeName()); // arch name + setText(gameObject.getArchetypeName()); // arch name } } } else { Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-10-03 18:42:15 UTC (rev 475) @@ -414,7 +414,7 @@ final Point[] redraw; // return value (coords needing redraw) - if (mainControl.getAutojoin() && mainControl.getArch(arch.getArchetypeName()).getJoinList() != null) { + if (mainControl.getAutojoin() && mainControl.getArchetype(arch.getArchetypeName()).getJoinList() != null) { // this arch does autojoining: // first look how many we need Modified: trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-03 18:42:15 UTC (rev 475) @@ -331,7 +331,7 @@ } } postParseDefArch(arch); - mainControl.addArchToList(arch); + mainControl.getArchetypeSet().addArchetype(arch); archmore = false; // we assume this is last... but perhaps.. @@ -486,28 +486,28 @@ * if null, copy the default text in arch, so the user can see and edit it * if at save time msg-maparch == msg-default, we ignore it * in every other case (even "" text) we save - * @param arch map arch to be parsed + * @param gameObject map arch to be parsed * @param editType edit type(s) to be calculated for the arch */ - public void postParseMapArch(final GameObject arch, final int editType) { - if (arch.getArchetypeName() == null) { + public void postParseMapArch(final GameObject gameObject, final int editType) { + if (gameObject.getArchetypeName() == null) { return; } - final String text = arch.getObjectText(); + final String text = gameObject.getObjectText(); final int len = text.length(); - final GameObject defarch = mainControl.getArch(arch.getArchetypeName()); + final GameObject archetype = mainControl.getArchetype(gameObject.getArchetypeName()); - arch.resetArchText(); + gameObject.resetArchText(); for (int i = 0, s = 0; i < len; i++) { if (text.charAt(i) == '\n') { if (i - s > 0) { if (text.regionMatches(s, "name ", 0, 5)) { - arch.setObjName(text.substring(s + 5, i)); + gameObject.setObjName(text.substring(s + 5, i)); } else { // this is an unparsed arch attribute, it has to stay in the archtext - arch.addArchText(text.substring(s, i) + "\n"); + gameObject.addArchText(text.substring(s, i) + "\n"); } } s = i + 1; @@ -515,36 +515,36 @@ } // so, lets check the stuff a last time - if (arch.getFaceName() == null) { - arch.setFaceNr(defarch.getFaceNr()); - arch.setFaceFlag(defarch.getFaceFlag()); + if (gameObject.getFaceName() == null) { + gameObject.setFaceNr(archetype.getFaceNr()); + gameObject.setFaceFlag(archetype.getFaceFlag()); } // if the type is still unset, then we take the default one - if (arch.getArchTypNr() == GameObject.TYPE_UNSET) { - arch.setArchTypNr(defarch.getArchTypNr()); + if (gameObject.getArchTypNr() == GameObject.TYPE_UNSET) { + gameObject.setArchTypNr(archetype.getArchTypNr()); } - arch.setMultiX(defarch.getMultiX()); - arch.setMultiY(defarch.getMultiY()); + gameObject.setMultiX(archetype.getMultiX()); + gameObject.setMultiY(archetype.getMultiY()); // arch.setEditType(defarch.getEditType()); // validate the ScriptedEvents - arch.validateAllEvents(); + gameObject.validateAllEvents(); // we don't handle anim yet, so attach then back to archtext - if (arch.getAnimText() != null) { - arch.addArchText("anim\n"); - arch.addArchText(arch.getAnimText()); - arch.addArchText("mina\n"); + if (gameObject.getAnimText() != null) { + gameObject.addArchText("anim\n"); + gameObject.addArchText(gameObject.getAnimText()); + gameObject.addArchText("mina\n"); } // Finally, we calculate the desired editType of the arch - if (arch.isTail()) { - arch.setEditType(arch.getHead().getEditType()); // copy from head + if (gameObject.isTail()) { + gameObject.setEditType(gameObject.getHead().getEditType()); // copy from head } else if (editType != 0) { - arch.setEditType(arch.calculateEditType(editType)); // calculate new + gameObject.setEditType(gameObject.calculateEditType(editType)); // calculate new } } @@ -554,25 +554,25 @@ * to the temp list, not a map. This method should only be called * after map-loading. * The ArchetypeSet should be fully initialized at this point. - * @param arch multipart head that needs tail attached + * @param gameObject multipart head that needs tail attached */ - public void expandMulti(final GameObject arch, final List<GameObject> objects) { - final GameObject defarch = mainControl.getArch(arch.getArchetypeName()); // default arch + public void expandMulti(final GameObject gameObject, final List<GameObject> objects) { + final GameObject archetype = mainControl.getArchetype(gameObject.getArchetypeName()); // default arch // is it a multi head? - if (defarch != null && defarch.isMulti() && arch.getMultiRefCount() <= 1) { + if (archetype != null && archetype.isMulti() && gameObject.getMultiRefCount() <= 1) { // we have a multi head and need to insert his tail now // do insertion for all non-head parts of the multi - for (GameObject oldPart = defarch.getMultiNext(); oldPart != null; oldPart = oldPart.getMultiNext()) { + for (GameObject oldPart = archetype.getMultiNext(); oldPart != null; oldPart = oldPart.getMultiNext()) { final GameObject newarch = oldPart.createArch(); - arch.addTailPart(newarch); + gameObject.addTailPart(newarch); objects.add(newarch); // set map position (x, y) - newarch.setMapX(arch.getMapX() + newarch.getMultiX()); - newarch.setMapY(arch.getMapY() + newarch.getMultiY()); + newarch.setMapX(gameObject.getMapX() + newarch.getMultiX()); + newarch.setMapY(gameObject.getMapY() + newarch.getMultiY()); // now attach the default arch and stuff // (don't need edit type as we copy from head) Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-03 18:42:15 UTC (rev 475) @@ -561,7 +561,7 @@ // loop through all existing ArchPanels and find all arches // along with their display-category - GameObject arch; + GameObject archetype; for (CArchPanel.PanelNode node = CArchPanel.getStartPanelNode(); node != null; node = node.next) { @@ -571,34 +571,34 @@ // process every arch in this panel for (int i = 0; i < numList.length; i++) { - arch = mainControl.getArch(numList[i]); + archetype = mainControl.getArchetype(numList[i]); - if (arch.isTail()) { + if (archetype.isTail()) { log.error("Collect Error: Multipart Tail in Panel found!"); } - out.writeBytes("Object " + arch.getArchetypeName() + "\n"); + out.writeBytes("Object " + archetype.getArchetypeName() + "\n"); - if (arch.getObjName() != null) { - out.writeBytes("name " + arch.getObjName() + "\n"); + if (archetype.getObjName() != null) { + out.writeBytes("name " + archetype.getObjName() + "\n"); } - if (arch.getFaceName() != null) { - out.writeBytes("face " + arch.getFaceName() + "\n"); + if (archetype.getFaceName() != null) { + out.writeBytes("face " + archetype.getFaceName() + "\n"); } - if (arch.getArchTypNr() > 0) { - out.writeBytes("type " + arch.getArchTypNr() + "\n"); + if (archetype.getArchTypNr() > 0) { + out.writeBytes("type " + archetype.getArchTypNr() + "\n"); } // special: add a string-attribute with the display-category out.writeBytes("editor_folder " + node.getTitle() + "/" + catList[i] + "\n"); // add message text - if (arch.getMsgText() != null && arch.getMsgText().trim().length() > 0) { - out.writeBytes("msg\n" + arch.getMsgText().trim() + "\nendmsg\n"); + if (archetype.getMsgText() != null && archetype.getMsgText().trim().length() > 0) { + out.writeBytes("msg\n" + archetype.getMsgText().trim() + "\nendmsg\n"); } - out.writeBytes(arch.getObjectText()); - if (arch.getObjectText().lastIndexOf(0x0a) != arch.getObjectText().length() - 1) { + out.writeBytes(archetype.getObjectText()); + if (archetype.getObjectText().lastIndexOf(0x0a) != archetype.getObjectText().length() - 1) { out.writeBytes("\n"); } @@ -609,7 +609,7 @@ } // if multi-head, we must attach the tails - for (GameObject tail = arch.getMultiNext(); tail != null; tail = tail.getMultiNext()) { + for (GameObject tail = archetype.getMultiNext(); tail != null; tail = tail.getMultiNext()) { out.writeBytes("More\n"); out.writeBytes("Object " + tail.getArchetypeName() + "\n"); @@ -649,7 +649,7 @@ } // finally we need to get the "map"-arch, which is not in the panels - final GameObject maparch = mainControl.getArch(ArchObjectParser.STARTARCH_NAME); + final GameObject maparch = mainControl.getArchetype(ArchObjectParser.STARTARCH_NAME); if (maparch != null) { count++; @@ -682,8 +682,8 @@ } // check if we still missed any arches - if (count - mainControl.getArchCount() != 0) { - log.warn((mainControl.getArchCount() - count) + " archetypes have been missed during collect!"); + if (count - getArchetypeCount() != 0) { + log.warn((getArchetypeCount() - count) + " archetypes have been missed during collect!"); } pbar.setValue(count); @@ -820,7 +820,7 @@ } } pbar.setValue(faceListCount); // finished - pbar.finished(mainControl.getArchCount(), faceListCount); + pbar.finished(getArchetypeCount(), faceListCount); // close png file out.close(); Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-10-03 18:42:15 UTC (rev 475) @@ -332,13 +332,13 @@ /** * Check if a given archetype fits within map bounds. Multi tiles can't be * set if going out of borders. - * @param archnanme the archetype to check + * @param archName the archetype to check * @param xx the x-coordinate to place archName * @param yy the y-coordinate to place archName * @param intern ??? */ private boolean testArchToMap(final String archName, final int xx, final int yy, final int intern) { - for (GameObject part = getDefaultArch(archName); part != null; part = part.getMultiNext()) { + for (GameObject part = getArchetype(archName); part != null; part = part.getMultiNext()) { final int mapx = xx + part.getMultiX(); final int mapy = yy + part.getMultiY(); if (!isPointValid(mapx, mapy)) { @@ -391,7 +391,7 @@ return false; } - newarch = getDefaultArch(archName); // temp. store this arch + newarch = getArchetype(archName); // temp. store this arch if (newarch == null) { return false; } @@ -403,7 +403,7 @@ if (archName == null) { return false; // only one autojoin type per square allowed } - newarch = getDefaultArch(archName); + newarch = getArchetype(archName); } GameObject newHead = null; @@ -507,7 +507,7 @@ archName = newarch.getArchetypeName(); } // create a new copy of a default arch - invnew = getDefaultArch(archName).createArch(); + invnew = getArchetype(archName).createArch(); } else { // create clone from a pickmap if (!newarch.isMulti()) { @@ -649,7 +649,7 @@ node.remove(); // do autojoining - final GameObject temp = getDefaultArch(node.getArchetypeName()); // get defarch + final GameObject temp = getArchetype(node.getArchetypeName()); // get defarch if (mainControl.getAutojoin() && join == JOIN_ENABLE && mainControl.getJoinlist() != null && temp.getJoinList() != null && !temp.isMulti()) { // remove connections to the deleted arch @@ -1025,7 +1025,7 @@ * @return the default arch object instance corresponding to * <code>archName</code>, or <code>null</code> if it does not exist */ - private GameObject getDefaultArch(final String archName) { + private GameObject getArchetype(final String archName) { return mainControl.getArchetypeSet().getArchetype(archName); } Modified: trunk/crossfire/src/cfeditor/parameter/ArchParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/ArchParameter.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/crossfire/src/cfeditor/parameter/ArchParameter.java 2006-10-03 18:42:15 UTC (rev 475) @@ -30,19 +30,19 @@ parameterType = getParameterType(); } - @Nullable private GameObject locateArch(final String name) { - final ArchetypeSet stack = CMainControl.getInstance().getArchetypeSet(); + @Nullable private GameObject locateArchetype(final String archetypeName) { + final ArchetypeSet archetypeSet = CMainControl.getInstance().getArchetypeSet(); if (CMainControl.getInstance().getArchetypeSet().getLoadStatus() != ArchetypeSet.LoadStatus.COMPLETE) { return null; } - return stack.getArchetype(name); + return archetypeSet.getArchetype(archetypeName); } @Override public void fromXML(final Element e) { super.fromXML(e); valueString = e.getChildTextTrim("value"); if (CMainControl.getInstance().getArchetypeSet().getLoadStatus() == ArchetypeSet.LoadStatus.COMPLETE) { - setValue(locateArch(valueString)); + setValue(locateArchetype(valueString)); } } @@ -64,7 +64,7 @@ @Override public Object getValue() { if (super.getValue() == null) { - final GameObject o = locateArch(valueString); + final GameObject o = locateArchetype(valueString); if (o != null) { setValue(o); } Modified: trunk/daimonin/src/daieditor/CArchPanelPan.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-10-03 18:42:15 UTC (rev 475) @@ -270,18 +270,18 @@ super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); final ArchetypeSet archetypeSet = mainControl.getArchetypeSet(); - final String archname = (String) value; - final GameObject arch = archetypeSet.getArchetype(archname); + final String archetypeName = (String) value; + final GameObject archetype = archetypeSet.getArchetype(archetypeName); if (isSelected) { // XXX it is not a good idea to query the selection information at this place. - archPanel.setSelectedArch(archname); + archPanel.setSelectedArch(archetypeName); mainControl.setStatusText(' ' + value.toString() + ' '); } - setText(archname); + setText(archetypeName); - if (arch.hasFaceObject()) { + if (archetype.hasFaceObject()) { setIcon(CMainControl.nofaceTileIcon); } else { - final ImageIcon icon = archetypeSet.getFace(arch.getFaceRealName()); + final ImageIcon icon = archetypeSet.getFace(archetype.getFaceRealName()); if (icon == null) { //setIcon(mainControl.nofaceTileIcon); } else { Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-10-03 18:42:15 UTC (rev 475) @@ -942,10 +942,10 @@ } } else if (content.getType() != TreasureObj.FOLDER) { // normal arch: display the face icon - final GameObject arch = CMainControl.getInstance().getArchetypeSet().getArchetype(content.getName()); - if (arch != null) { - if (!arch.hasFaceObject()) { - setIcon(CMainControl.getInstance().getArchetypeSet().getFace(arch.getFaceObjName())); + final GameObject archetype = CMainControl.getInstance().getArchetypeSet().getArchetype(content.getName()); + if (archetype != null) { + if (!archetype.hasFaceObject()) { + setIcon(CMainControl.getInstance().getArchetypeSet().getFace(archetype.getFaceObjName())); } else { setIcon(noface); } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-10-03 18:42:15 UTC (rev 475) @@ -672,16 +672,6 @@ mainView.openHelpWindow(); } - // access to ArchNodeList - // remark: i use before some weird access to it, use this instead when you find it - public void addArchToList(final GameObject data) { - archetypeSet.addArchetype(data); - } - - public int getArchCount() { - return archetypeSet.getArchetypeCount(); - } - /** Set all global settings from the preferences. */ void readGlobalSettings() { initDirs(); @@ -1274,22 +1264,22 @@ // first: attach our map sucker to a default arch we have loaded //noinspection ForLoopWithMissingComponent for (final Iterator<GameObject> it = objects.iterator(); it.hasNext();) { - final GameObject arch = it.next(); - final GameObject defarch = archetypeSet.getArchetype(arch.getArchetypeName()); - if (defarch == null) { - noarch.append(arch.getArchetypeName()).append('\n'); + final GameObject gameObject = it.next(); + final GameObject archetype = archetypeSet.getArchetype(gameObject.getArchetypeName()); + if (archetype == null) { + noarch.append(gameObject.getArchetypeName()).append('\n'); noarchcount++; it.remove(); } - arch.setArchetype(defarch); + gameObject.setArchetype(archetype); // Ok, now is attached to default arch and loaded png // NOW we post parse the object... // (We calculate only edit types that are active, to save time) - ArchObjectParser.postParseMapArch(arch, tileEdit); + ArchObjectParser.postParseMapArch(gameObject, tileEdit); // now lets assign the visible face - perhaps we have still a anim - arch.setObjectFace(); + gameObject.setObjectFace(); - archObjectParser.expandMulti(arch, tailList); + archObjectParser.expandMulti(gameObject, tailList); } for (final GameObject tail : tailList) { Modified: trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-03 18:42:15 UTC (rev 475) @@ -293,7 +293,7 @@ // TODO cher: check whether the arch always is an Archetype and if so remove the method below. arch.setIsArchetype(); arch.setEditorFolder(newCat); - mainControl.addArchToList(arch); + mainControl.getArchetypeSet().addArchetype(arch); if (archmore) { calcLowestMulti(arch); Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-03 18:42:15 UTC (rev 475) @@ -256,14 +256,14 @@ // TODO: Allow not having a def arch // at this point we MUST have a legal name and def arch // TODO:Then why not check this and throw an exception if not? - final GameObject defArch = getArchetype(defArchName); - if (name == null || defArchName == null || name.length() == 0 || defArchName.length() == 0 || defArch == null) { + final GameObject archetype = getArchetype(defArchName); + if (name == null || defArchName == null || name.length() == 0 || defArchName.length() == 0 || archetype == null) { System.err.println("Artifacts file: Line " + lineCount + " Object >" + defArchName + "< / >" + name + "< / >" + objTitle + "< has missing name or defArch"); } else if (editorCode != 0 && editorCode != 2) { // the next line of our file is part of a arch parse until a "end" comes // now the editor will do the same as the real server: // get the default arch as base and parse the new values over it // the extended functions of the artifacts file can be ignored here. - mainControl.getArchObjectParser().parseDefArchFromStream(myInput, editorCode == 2 ? null : defArch, thisLine, name, 0, fname); + mainControl.getArchObjectParser().parseDefArchFromStream(myInput, editorCode == 2 ? null : archetype, thisLine, name, 0, fname); // note: in the parser is a small part where we handle the title setting // and the reverse type setting for type == -1 (unique items marker in artifacts file) } else { @@ -644,8 +644,8 @@ } // check if we still missed any arches - if ((count + artifactCount) - mainControl.getArchCount() != 0) { - ACTION_FACTORY.showMessageDialog(pbar.getParentComponent(), "archCollectWarningMissed", mainControl.getArchCount() - count); + if ((count + artifactCount) - getArchetypeCount() != 0) { + ACTION_FACTORY.showMessageDialog(pbar.getParentComponent(), "archCollectWarningMissed", getArchetypeCount() - count); } pbar.setValue(count); } finally { Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-10-03 17:47:02 UTC (rev 474) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-10-03 18:42:15 UTC (rev 475) @@ -95,7 +95,7 @@ /** * The MapControl that controls this MapModel. - * @deprecated it's not a good idea to require the MapModel implementation to know such a heavy-weight strongly UI-related glue class like {@link CMapControl}. + * @deprecated it's not a good idea to require the MapModel implementation to know such a heavy-weight strongly UI-related glue class like {@link MapControl}. * @todo care about Serialization if this field remains */ @Deprecated private final MapControl mapControl; @@ -219,7 +219,7 @@ /** {@inheritDoc} */ public boolean isMultiArchFittingToMap(final String archName, final Point pos, final boolean allowDouble) { - final GameObject head = getDefaultArch(archName); + final GameObject head = getArchetype(archName); final Point mapH = new Point(head.getMultiX(), head.getMultiY()); mapH.translate(pos.x, pos.y); if (!isPointValid(mapH)) { @@ -253,7 +253,7 @@ return false; } - final GameObject defaultArch = getDefaultArch(archName); + final GameObject defaultArch = getArchetype(archName); // FIXME: Check maximum RefX and RefY to check whether the multitile arch fits on the map. if (pos.x + defaultArch.getMinX() < 0 || pos.y + defaultArch.getMinY() < 0 || pos.x + defaultArch.getMaxX() > mapSize.getWidth() || pos.y + defaultArch.getMaxY() > mapSize.getHeight()) { @@ -344,7 +344,7 @@ archName = newarch.getArchetypeName(); } // create a new copy of a default arch - invnew = getDefaultArch(archName).createArch(); + invnew = getArchetype(archName).createArch(); } else { // create clone from a pickmap if (!newarch.isMulti()) { @@ -624,14 +624,14 @@ } /** - * Get a default {@link GameObject} instance. + * Get an Archetype. * * @param archName the archetype name * * @return the default arch object instance corresponding to * <code>archName</code>, or <code>null</code> if it does not exist */ - private GameObject getDefaultArch(final String archName) { + private GameObject getArchetype(final String archName) { return mainControl.getArchetypeSet().getArchetype(archName); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-07 13:42:53
|
Revision: 484 http://svn.sourceforge.net/gridarta/?rev=484&view=rev Author: christianhujer Date: 2006-10-07 06:41:41 -0700 (Sat, 07 Oct 2006) Log Message: ----------- Moved unified classes (GameObjectContainer, MapSquare) from crossfire / daimonin to gridarta. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/map/MapModel.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMapFileEncode.java trunk/daimonin/src/daieditor/CMapTileList.java trunk/daimonin/src/daieditor/CMapViewBasic.java trunk/daimonin/src/daieditor/CopyBuffer.java trunk/daimonin/src/daieditor/ReplaceDialog.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gui/ConnectionView.java trunk/daimonin/src/daieditor/gui/ErrorListView.java trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java trunk/daimonin/src/daieditor/gui/map/tools/DeletionTool.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java trunk/daimonin/src/daieditor/map/MapControl.java trunk/daimonin/src/daieditor/map/MapModel.java trunk/daimonin/src/daieditor/map/MapModelEvent.java trunk/daimonin/src/daieditor/map/validation/DelegatingMapValidator.java trunk/daimonin/src/daieditor/map/validation/GameObjectsValidationError.java trunk/daimonin/src/daieditor/map/validation/MapValidationError.java trunk/daimonin/src/daieditor/map/validation/SquareValidationError.java trunk/daimonin/src/daieditor/map/validation/SquareValidator.java trunk/daimonin/src/daieditor/map/validation/ValidationError.java trunk/daimonin/src/daieditor/map/validation/checks/BlockedMobOrSpawnPointChecker.java trunk/daimonin/src/daieditor/map/validation/checks/BlockedMobOrSpawnPointError.java trunk/daimonin/src/daieditor/map/validation/checks/DoubleLayerChecker.java trunk/daimonin/src/daieditor/map/validation/checks/DoubleLayerError.java trunk/daimonin/src/daieditor/map/validation/checks/DoubleTypeChecker.java trunk/daimonin/src/daieditor/map/validation/checks/DoubleTypeError.java trunk/daimonin/src/daieditor/map/validation/checks/ExitChecker.java trunk/daimonin/src/daieditor/map/validation/checks/SquareWithoutFloorChecker.java trunk/daimonin/src/daieditor/map/validation/checks/SquareWithoutFloorError.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/map/MapModel.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gameobject/GameObjectContainer.java trunk/src/app/net/sf/gridarta/gameobject/RecursiveGameObjectIterator.java trunk/src/app/net/sf/gridarta/map/MapSquare.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/GameObjectContainer.java trunk/crossfire/src/cfeditor/gameobject/RecursiveGameObjectIterator.java trunk/crossfire/src/cfeditor/map/MapSquare.java trunk/daimonin/src/daieditor/gameobject/GameObjectContainer.java trunk/daimonin/src/daieditor/gameobject/RecursiveGameObjectIterator.java trunk/daimonin/src/daieditor/map/MapSquare.java Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-10-07 13:41:41 UTC (rev 484) @@ -307,7 +307,7 @@ // now try to get the topmost object GameObject arch = null; if (pmap.isPointValid(pmap.getMapView().getHighlightStart())) { - arch = pmap.getMapModel().getMapSquare(pmap.getMapView().getHighlightStart()).getFirst(); + arch = (GameObject) pmap.getMapModel().getMapSquare(pmap.getMapView().getHighlightStart()).getFirst(); } if (arch != null) { // so here we return the arch from the pickmap Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 13:41:41 UTC (rev 484) @@ -31,16 +31,15 @@ import cfeditor.IGUIConstants; import cfeditor.MultiArchData; import cfeditor.ScriptArchData; -import cfeditor.map.MapSquare; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import javax.swing.JList; +import net.sf.gridarta.gameobject.GameObjectContainer; +import net.sf.gridarta.map.MapSquare; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,7 +49,7 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public class GameObject extends GameObjectContainer implements Cloneable, net.sf.gridarta.gameobject.GameObject, Iterable<GameObject> { +public class GameObject extends net.sf.gridarta.gameobject.GameObject<GameObject> implements Cloneable, Iterable<GameObject> { private static final Logger log = Logger.getLogger(GameObject.class); @@ -154,7 +153,7 @@ * <li>A MapSquare, which means that this GameObject is top level on that MapSquare.</li> * </ul> */ - private GameObjectContainer container; + private GameObjectContainer<GameObject> container; /** * All inventory objects. Set to {@link Collections#EMPTY_LIST} @@ -224,13 +223,6 @@ this.archetype = archetype; } - /** {@inheritDoc} - * @note DO NOT INVOKE DIRECTLY YET! - */ - public void setArchetype(final net.sf.gridarta.gameobject.GameObject archetype) { - this.archetype = (GameObject) archetype; - } - /** {@inheritDoc} */ public boolean isArchetype() { return archetype == this; @@ -454,32 +446,18 @@ return isInContainer() ? ((GameObject) container).getTopContainer() : this; } - /** - * Sets container of this GameObject. - * There are two possibilities for the container: - * <ul> - * <li>Another GameObject, which means this object is in the inventory of that GameObject.</li> - * <li>A MapSquare, which means that this GameObject is top level on that MapSquare.</li> - * </ul> - * @param container container of this GameObject. - */ - public void setContainer(final GameObjectContainer container) { + /** {@inheritDoc} */ + public void setContainer(final GameObjectContainer<GameObject> container) { this.container = container; } - /** - * Check whether this GameObject is in a Container (in Daimonin sense, - * which means being in a MapSquare isn't, but being in an GameObject is). - * @return <code>true</code> if this GameObject has a Container and the - * Container is an GameObject, otherwise (no Container or Container is not - * an GameObject) false - */ + /** {@inheritDoc} */ public boolean isInContainer() { return container != null && container instanceof GameObject; } /** {@inheritDoc} */ - @Override public MapSquare getMapSquare() { + @Override public MapSquare<GameObject> getMapSquare() { return container != null ? container.getMapSquare() : null; } Deleted: trunk/crossfire/src/cfeditor/gameobject/GameObjectContainer.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObjectContainer.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/crossfire/src/cfeditor/gameobject/GameObjectContainer.java 2006-10-07 13:41:41 UTC (rev 484) @@ -1,427 +0,0 @@ -/* - * Daimonin Java Editor. - * Copyright (C) 2005 Christian Hujer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package cfeditor.gameobject; - -import cfeditor.map.MapSquare; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Base class for classes that contain GameObjects as children in the sense of containment. - * The interface serves 2 main purposes: - * <ul> - * <li>{@link GameObject} extends this class for containing other GameObjects, like inventory contents e.g. of a bag or attached events.</li> - * <li>{@link MapSquare} extends this class to list the tiles on a MapSquare.</li> - * </ul> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @todo: In case of MapSquares, this class is most likely bogus regarding multipart objects. This needs to be fixed. - */ -@SuppressWarnings({"ClassReferencesSubclass"}) -public abstract class GameObjectContainer implements Iterable<GameObject>, Serializable { - - /** Serial Version. */ - private static final long serialVersionUID = 1L; - - /** - * The contents of this container. - * @note the order of this container is bottom to top. - */ - @NotNull private List<GameObject> contents; - - /** Iterable implementation for recursice traversal. */ - @NotNull private transient Iterable<GameObject> recursive; - - /** Iterable implementation for reverse traversal. */ - @NotNull private transient Iterable<GameObject> reverse; - - /** Create a new GameObjectContainer. */ - protected GameObjectContainer() { - initData(); - } - - /** - * Initialize the fields. - * This is needed because there are two ways of object construction, - * <ul> - * <li>regular object construction via constructor invocation and</li> - * <li>cloning of objects via {@link #clone()}.</li> - * </ul> - */ - private void initData() { - contents = new ArrayList<GameObject>(); - recursive = new Iterable<GameObject>() { - /** {@inheritDoc} */ - public Iterator<GameObject> iterator() { - return new RecursiveGameObjectIterator(GameObjectContainer.this); - } - }; - reverse = new Iterable<GameObject>() { - /** {@inheritDoc} */ - public Iterator<GameObject> iterator() { - return new ReverseIterator<GameObject>(contents); - } - }; // Iterable<GameObject> reverse - } - - /** - * {@inheritDoc} - * The Iterator returned does not recurse, it only contains objects on the first level. - * The Iterator returned is transparent, that means modifying the iterator's collection actually modifies the underlying GameObjectContainer. - */ - @NotNull public final Iterator<GameObject> iterator() { - // Do not return contents.iterator() directly because otherwise the remove() operation will not properly unlink the removed GameObject from its container. - return new Iterator<GameObject>() { - - /** The basic iterator. */ - private Iterator<GameObject> delegate = contents.iterator(); - private GameObject current; - - /** {@inheritDoc} */ - public boolean hasNext() { - return delegate.hasNext(); - } - - /** {@inheritDoc} */ - public GameObject next() { - return current = delegate.next(); - } - - /** {@inheritDoc} */ - public void remove() { - // keep this in sync with GameObjectContainer#remove(GameObject) - // we can't simply invoke GameObjectContainer#remove(current) because that would result in a ConcurrentModificationException. - delegate.remove(); - current.setContainer(null); - squareChanged(); - } - }; - } - - /** - * Return an object that is the reverse representation. - * Invoke this method if you want to iterate over the contained GameObjects in reverse order. - * @return reverse representation - */ - @NotNull public final Iterable<GameObject> reverse() { - return reverse; - } - - /** - * Return an object that is a recursive representation. - * Invoke this method if you want to iterate over the contained GameObjects recursively. - * @return recursive representation - */ - @NotNull public final Iterable<GameObject> recursive() { - return recursive; - } - - /** - * Check whether this square is empty. - * @return <code>true</code> if this square is empty, otherwise <code>false</code> - */ - public boolean isEmpty() { - return contents.isEmpty(); - } - - /** - * Return the first GameObject contained in this container. - * @return first GameObject contained or <code>null</code> if {@link #isEmpty()} returns <code>true</code> - */ - @Nullable public final GameObject getFirst() { - return contents.isEmpty() ? null : contents.get(0); - } - - /** - * Return the last GameObject contained in this container. - * You should not invoke this method to iterate over GameObjects, such invocation is regarded deprecated. - * @return last GameObject contained or <code>null</code> if {@link #isEmpty()} returns <code>true</code> - */ - @Nullable public final GameObject getLast() { - return contents.isEmpty() ? null : contents.get(contents.size() - 1); - } - - /** - * Remove a GameObject from this container. - * @param gameObject GameObject to remove - * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container - */ - final void remove(@NotNull final GameObject gameObject) { - // keep this in sync with iterator() - if (!contents.remove(gameObject)) { - throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); - } - gameObject.setContainer(null); - squareChanged(); - } - - /** Remove all GameObjects from this container. */ - public final void removeAll() { - if (contents.size() <= 0) { - return; - } - - for (final GameObject gameObject : contents) { - gameObject.setContainer(null); - } - contents.clear(); - squareChanged(); - } - - /** - * Move an item to top. - * @param gameObject item to move to top - * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container - */ - public final void moveTop(@NotNull final GameObject gameObject) { - final int oldIndex = contents.indexOf(gameObject); - if (oldIndex != contents.size() - 1) { - if (!contents.remove(gameObject)) { - throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); - } - contents.add(gameObject); - squareChanged(); - } - } - - /** - * Move an item up. - * @param gameObject item to move up - * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container - */ - public final void moveUp(@NotNull final GameObject gameObject) { - final int oldIndex = contents.indexOf(gameObject); - if (oldIndex < contents.size() - 1) { - if (!contents.remove(gameObject)) { - throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); - } - contents.add(oldIndex + 1, gameObject); - squareChanged(); - } - } - - /** - * Move an item down. - * @param gameObject item to move down - * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container - */ - public final void moveDown(@NotNull final GameObject gameObject) { - final int oldIndex = contents.indexOf(gameObject); - if (oldIndex > 0) { - if (!contents.remove(gameObject)) { - throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); - } - contents.add(oldIndex - 1, gameObject); - squareChanged(); - } - } - - /** - * Move an item to bottom. - * @param gameObject item to move to bottom - * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container - */ - public final void moveBottom(@NotNull final GameObject gameObject) { - final int oldIndex = contents.indexOf(gameObject); - if (oldIndex != 0) { - if (!contents.remove(gameObject)) { - throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); - } - contents.add(0, gameObject); - squareChanged(); - } - } - - /** - * Get the X coordinate on the map. - * @return X coordinate on map - */ - public abstract int getMapX(); - - /** - * Get the Y coordinate on the map. - * @return Y coordinate on map - */ - public abstract int getMapY(); - - /** - * Add the given GameObject at the end of this Container. - * @param gameObject the free yet unlinked <code>GameObject</code> to be placed in the inventory - * @throws IllegalArgumentException if <var>gameObject</var> already is inside another container - */ - public void addLast(@NotNull final GameObject gameObject) { - if (gameObject.isInContainer()) { - throw new IllegalArgumentException("Can't add " + gameObject + " to " + this + " because it's already inside " + gameObject.getContainer()); - } - contents.add(gameObject); - gameObject.setContainer(this); - squareChanged(); - } - - /** - * Add the given GameObject at the end of this Container. - * @param gameObject the free yet unlinked <code>GameObject</code> to be placed in the inventory - * @throws IllegalArgumentException if <var>gameObject</var> already is inside another container - */ - public void addFirst(@NotNull final GameObject gameObject) { - if (gameObject.isInContainer()) { - throw new IllegalArgumentException("Can't add " + gameObject + " to " + this + " because it's already inside " + gameObject.getContainer()); - } - contents.add(0, gameObject); - gameObject.setContainer(this); - squareChanged(); - } - - /** - * Add a GameObject after another. - * @param previousGameObject previous anchor - * @param newGameObject GameObject to insert - * @throws IllegalArgumentException if <var>newGameObject</var> already is inside another container or <var>previousGameObject</var> isn't inside this container - */ - public void insertAfter(@NotNull final GameObject previousGameObject, @NotNull final GameObject newGameObject) { - if (newGameObject.isInContainer()) { - throw new IllegalArgumentException("Can't add " + newGameObject + " to " + this + " because it's already inside " + newGameObject.getContainer()); - } - final int insertIndex = contents.indexOf(previousGameObject); - if (insertIndex == -1) { - throw new IllegalArgumentException("Can't insert " + newGameObject + " after " + previousGameObject + " because that isn't inside " + this); - } - contents.add(insertIndex, newGameObject); - newGameObject.setContainer(this); - squareChanged(); - } - - /** - * Add a GameObject before another. - * @param newGameObject GameObject to insert - * @param nextGameObject nextGameObject anchor - * @throws IllegalArgumentException if <var>newGameObject</var> already is inside another container or <var>prev</var> isn't inside this container - */ - public void insertBefore(@NotNull final GameObject newGameObject, @NotNull final GameObject nextGameObject) { - if (newGameObject.isInContainer()) { - throw new IllegalArgumentException("Can't add " + newGameObject + " to " + this + " because it's already inside " + newGameObject.getContainer()); - } - final int insertIndex = contents.indexOf(nextGameObject); - if (insertIndex == -1) { - throw new IllegalArgumentException("Can't insert " + newGameObject + " before " + nextGameObject + " because that isn't inside " + this); - } - contents.add(insertIndex + 1, newGameObject); - newGameObject.setContainer(this); - squareChanged(); - } - - /** - * Replace an GameObject with another one. - * @param oldGameObject old GameObject to be replaced - * @param newGameObject new GameObject that replaces oldGameObject - * @throws IllegalArgumentException if <var>oldGameObject</var> isn't in this container - */ - public void replace(@NotNull final GameObject oldGameObject, @NotNull final GameObject newGameObject) { - final int insertIndex = contents.indexOf(oldGameObject); - if (insertIndex == -1) { - throw new IllegalArgumentException(oldGameObject + " wasn't inside container " + this); - } - contents.remove(oldGameObject); - oldGameObject.setContainer(null); - contents.add(insertIndex, newGameObject); - newGameObject.setContainer(this); - squareChanged(); - } - - /** - * Get the MapSquare of this GameObjectContainer. - * @return MapSquare of this GameObjectContainer or <code>null</code> if this GameObjectContainer is not (yet?) connected to a map (a {@link MapSquare} would return itself) - */ - @Nullable public abstract MapSquare getMapSquare(); - - /** - * Tell the model that this MapSquare has changed. - * This method must be invoked by all other methods that change something. - */ - protected final void squareChanged() { - final MapSquare square = getMapSquare(); - if (square != null) { - square.getModel().squareChanged(square); - } - } - - /** {@inheritDoc} */ - @NotNull @Override protected GameObjectContainer clone() throws CloneNotSupportedException { - try { - final GameObjectContainer clone = (GameObjectContainer) super.clone(); - clone.initData(); - return clone; - } catch (final CloneNotSupportedException e) { - assert false; - throw new AssertionError(); - } - } - - /** {@inheritDoc} */ - // writeObject() is not required because this class doesn't require special handling during serialization. - private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - // initialize transients - initData(); - } - - /** - * An iterator for iterating over a list in reverse order. - * @todo move this class to JAPI - */ - private static class ReverseIterator<T> implements Iterator<T> { - - /** The iterator used for delegation. */ - @NotNull private final ListIterator<T> delegate; - - /** - * Create a reverse iterator. - * @param list to iterate over in reverse order - */ - public ReverseIterator(final List<T> list) { - delegate = list.listIterator(list.size()); - } - - /** {@inheritDoc} */ - public boolean hasNext() { - return delegate.hasPrevious(); - } - - /** {@inheritDoc} */ - @NotNull public T next() { - return delegate.previous(); - } - - /** {@inheritDoc} */ - public void remove() { - delegate.remove(); - } - - } // class ReverseIterator - -} // interface GameObjectContainer Deleted: trunk/crossfire/src/cfeditor/gameobject/RecursiveGameObjectIterator.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/RecursiveGameObjectIterator.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/crossfire/src/cfeditor/gameobject/RecursiveGameObjectIterator.java 2006-10-07 13:41:41 UTC (rev 484) @@ -1,58 +0,0 @@ -package cfeditor.gameobject; - -import java.util.EmptyStackException; -import java.util.Iterator; -import java.util.Stack; - -/** - * Iterator for recursively iterating over ArchObjectContainers. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -class RecursiveGameObjectIterator implements Iterator<GameObject> { - - /** The Iterator stack. */ - private Stack<Iterator<GameObject>> iteratorStack = new Stack<Iterator<GameObject>>(); - - /** The current iterator. */ - private Iterator<GameObject> current; - - /** - * Create a recursive GameObject Iterator. - * @param container GameObjectContainer to start with - */ - RecursiveGameObjectIterator(final GameObjectContainer container) { - current = container.iterator(); - } - - /** {@inheritDoc} */ - public boolean hasNext() { - return current.hasNext(); - } - - /** {@inheritDoc} */ - public GameObject next() { - final GameObject arch = current.next(); - try { - return arch; - } finally { - if (!arch.isEmpty()) { - iteratorStack.push(current); - current = arch.iterator(); - } else { - try { - while (!current.hasNext() ) { - current = iteratorStack.pop(); - } - } catch (final EmptyStackException e) { - /* ignore. */ - } - } - } - } - - /** {@inheritDoc} */ - public void remove() { - current.remove(); - } - -} // class RecursiveGameObjectIterator Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-10-07 13:41:41 UTC (rev 484) @@ -38,6 +38,7 @@ import java.util.List; import java.util.NoSuchElementException; import net.sf.gridarta.Size2D; +import net.sf.gridarta.map.MapSquare; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -58,7 +59,7 @@ * The map, containing all arches grid-wise. * Index: [width][height] */ - private MapSquare[][] mapGrid; + private MapSquare<GameObject>[][] mapGrid; /** Size of this map. */ private Size2D mapSize; @@ -92,7 +93,7 @@ } /** Iterator for iterating over all squares of a model. */ - private class MapSquareIterator implements Iterator<MapSquare> { + private class MapSquareIterator implements Iterator<MapSquare<GameObject>> { /** * Index of current map square. @@ -116,9 +117,9 @@ } /** {@inheritDoc} */ - public MapSquare next() { + public MapSquare<GameObject> next() { try { - final MapSquare square = mapGrid[point / mapSize.getHeight()][point % mapSize.getHeight()]; + final MapSquare<GameObject> square = mapGrid[point / mapSize.getHeight()][point % mapSize.getHeight()]; point++; return square; } catch (final ArrayIndexOutOfBoundsException e) { @@ -207,12 +208,12 @@ } /** {@inheritDoc} */ - public Iterator<MapSquare> iterator() { + public Iterator<MapSquare<GameObject>> iterator() { return new MapSquareIterator(); } /** {@inheritDoc} */ - public MapSquare getMapSquare(final Point p) throws ArrayIndexOutOfBoundsException { + public MapSquare<GameObject> getMapSquare(final Point p) throws ArrayIndexOutOfBoundsException { return mapGrid[p.x][p.y]; } @@ -870,7 +871,7 @@ // Now the critical step: create an GameObject array of new dimension, // copy all objects and set it to replace the current one. - final MapSquare[][] newGrid = new MapSquare[newSize.getWidth()][newSize.getHeight()]; + final MapSquare<GameObject>[][] newGrid = new MapSquare[newSize.getWidth()][newSize.getHeight()]; // relink all arches to the new grid for (int x = 0; x < newSize.getWidth(); x++) { @@ -878,7 +879,7 @@ if (x < mapSize.getWidth() && y < mapSize.getHeight()) { newGrid[x][y] = mapGrid[x][y]; } else { - newGrid[x][y] = new MapSquare(this, x, y); + newGrid[x][y] = new MapSquare<GameObject>(this, x, y); } } } @@ -1014,7 +1015,7 @@ */ /** {@inheritDoc} */ - public void squareChanged(final MapSquare square) { + public void squareChanged(@NotNull final MapSquare<GameObject> square) { } /** Modified: trunk/crossfire/src/cfeditor/map/MapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapModel.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/crossfire/src/cfeditor/map/MapModel.java 2006-10-07 13:41:41 UTC (rev 484) @@ -5,12 +5,13 @@ import java.util.Iterator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import net.sf.gridarta.map.MapSquare; /** * Interface for MapModels. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public interface MapModel extends net.sf.gridarta.map.MapModel { +public interface MapModel extends net.sf.gridarta.map.MapModel<GameObject> { /** Enable autojoin when inserting objects. */ boolean JOIN_ENABLE = true; @@ -19,7 +20,7 @@ boolean JOIN_DISABLE = false; /** {@inheritDoc} */ - Iterator<MapSquare> iterator(); + Iterator<MapSquare<GameObject>> iterator(); /** * Get the square at a specified location. @@ -27,7 +28,7 @@ * @return square at <var>p</var> * @throws ArrayIndexOutOfBoundsException in case p specifies a location that's not valid within this map model */ - MapSquare getMapSquare(Point p) throws ArrayIndexOutOfBoundsException; + MapSquare<GameObject> getMapSquare(Point p) throws ArrayIndexOutOfBoundsException; @Nullable Point getMouseRightPos(); @@ -71,13 +72,8 @@ void setFileName(String strFileName); - /** - * Method to notify the model that a map square was changed. - * A change to a square is atomic if {@link #getTransactionDepth()} returns 0, otherwise it is transactional. - * The model then notifies the registered listeners of the changes. - * @param square MapSquare that has changed - */ - void squareChanged(@NotNull MapSquare square); + /** {@inheritDoc} */ + void squareChanged(@NotNull MapSquare<GameObject> square); MapArchObject getMapArchObject(); Deleted: trunk/crossfire/src/cfeditor/map/MapSquare.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapSquare.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/crossfire/src/cfeditor/map/MapSquare.java 2006-10-07 13:41:41 UTC (rev 484) @@ -1,90 +0,0 @@ -/* - * Daimonin Java Editor. - * Copyright (C) 2000 Michael Toennies - * Copyright (C) 2001 Andreas Vogl - * - * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package cfeditor.map; - -import cfeditor.gameobject.GameObject; -import cfeditor.gameobject.GameObjectContainer; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * A single Map Square. - * This class is implemented in a way that changes via some modifier methods in a map square will automatically fire events in the associated MapModel. - * A MapSquare always knows its model. - * It's not possible to create a MapSquare that is not associated to a model. - * - * <p>The objects are stored bottom to top: {@link #getFirst()} returns the - * object at the bottom, {@link #getLast()} returns the object at the top of - * the tile. - * - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public class MapSquare extends GameObjectContainer { - - /** The MaoModel this square is associated with. */ - @NotNull private final MapModel model; - - /** The X Coordinate of this map square within the model's grid. */ - private final int x; - - /** The Y Coordinate of this map square within the model's grid. */ - private final int y; - - /** - * Creates a new instance of MapSquare. - * @param model MapModel for this MapSquare - * @param x X Coordinate of this map square within the model's grid - * @param y Y Coordinate of this map square within the model's grid - */ - MapSquare(@NotNull final MapModel model, final int x, final int y) { - this.model = model; - this.x = x; - this.y = y; - } - - /** - * Get the MapModel. - * @return MapModel - */ - @NotNull public MapModel getModel() { - return model; - } - - /** {@inheritDoc} */ - @Override public final int getMapX() { - return x; - } - - /** {@inheritDoc} */ - @Override public final int getMapY() { - return y; - } - - /** {@inheritDoc} */ - @Override @NotNull public final MapSquare getMapSquare() { - return this; - } - -} // class MapSquare Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-10-07 13:41:41 UTC (rev 484) @@ -53,7 +53,6 @@ import daieditor.map.MapModel; import daieditor.map.MapModelEvent; import daieditor.map.MapModelListener; -import daieditor.map.MapSquare; import daieditor.map.validation.DefaultErrorCollector; import daieditor.map.validation.DelegatingMapValidator; import daieditor.map.validation.ErrorCollector; @@ -115,6 +114,7 @@ import net.sf.gridarta.MainControl; import net.sf.gridarta.gui.HideFileFilterProxy; import net.sf.gridarta.map.MapType; +import net.sf.gridarta.map.MapSquare; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; @@ -2052,7 +2052,7 @@ /** {@inheritDoc} */ public void mapSquaresChanged(final MapModelEvent e) { if (prefs.getBoolean(PREFS_VALIDATOR_AUTO, PREFS_VALIDATOR_AUTO_DEFAULT)) { - final MapSquare[] squares = e.getSquares(); + final MapSquare<GameObject>[] squares = e.getSquares(); if (squares != null) { final ErrorCollector errorCollector = new DefaultErrorCollector(); validators.validate(squares, errorCollector); Modified: trunk/daimonin/src/daieditor/CMapFileEncode.java =================================================================== --- trunk/daimonin/src/daieditor/CMapFileEncode.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/daimonin/src/daieditor/CMapFileEncode.java 2006-10-07 13:41:41 UTC (rev 484) @@ -27,13 +27,13 @@ import daieditor.gameobject.GameObject; import daieditor.map.MapArchObject; import daieditor.map.MapModel; -import daieditor.map.MapSquare; import java.awt.Point; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Formatter; import net.sf.gridarta.Size2D; +import net.sf.gridarta.map.MapSquare; import net.sf.gridarta.io.IOUtils; /** @@ -83,7 +83,7 @@ } // y } // x - for (final MapSquare square : mapModel) { + for (final MapSquare<GameObject> square : mapModel) { final int x = square.getMapX(); final int y = square.getMapY(); for (final GameObject node : square) { Modified: trunk/daimonin/src/daieditor/CMapTileList.java =================================================================== --- trunk/daimonin/src/daieditor/CMapTileList.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/daimonin/src/daieditor/CMapTileList.java 2006-10-07 13:41:41 UTC (rev 484) @@ -27,7 +27,6 @@ import daieditor.gameobject.GameObject; import daieditor.map.MapControl; -import daieditor.map.MapSquare; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -54,6 +53,7 @@ import javax.swing.event.ListSelectionListener; import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapCursorListener; +import net.sf.gridarta.map.MapSquare; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; import net.sf.japi.swing.ActionMethod; @@ -86,7 +86,7 @@ private int listCounter; /** The currently selected MapSquare. */ - private transient MapSquare currentSquare; + private transient MapSquare<GameObject> currentSquare; /** Build Panel */ public CMapTileList(final CMainControl mainControl, final CMainView mainView) { Modified: trunk/daimonin/src/daieditor/CMapViewBasic.java =================================================================== --- trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-10-07 13:41:41 UTC (rev 484) @@ -31,7 +31,6 @@ import daieditor.map.MapModel; import daieditor.map.MapModelEvent; import daieditor.map.MapModelListener; -import daieditor.map.MapSquare; import daieditor.map.validation.ErrorCollector; import daieditor.map.validation.ErrorHandler; import daieditor.map.validation.ValidationError; @@ -50,6 +49,7 @@ import javax.swing.JScrollPane; import javax.swing.JViewport; import net.sf.gridarta.Size2D; +import net.sf.gridarta.map.MapSquare; import net.sf.gridarta.gui.MapView; import net.sf.gridarta.gui.map.MapCursor; import net.sf.gridarta.gui.map.MapCursorEvent; @@ -105,7 +105,7 @@ private final MapView frame; /** The MapSquares that are known to contain errors. */ - private Map<MapSquare, ValidationError> erraneousMapSquares = new HashMap<MapSquare, ValidationError>(); + private Map<MapSquare<GameObject>, ValidationError> erraneousMapSquares = new HashMap<MapSquare<GameObject>, ValidationError>(); /** The ArchObjects that are known to contain errors. */ private Map<GameObject,ValidationError> erraneousArchObjects = new HashMap<GameObject,ValidationError>(); @@ -250,7 +250,7 @@ * @return cursor square or <code>null</code> if no current cursor * @see #getCursorPosition() */ - @Nullable public MapSquare getCursorSquare() { + @Nullable public MapSquare<GameObject> getCursorSquare() { try { return mapModel.getMapSquare(getCursorPosition()); } catch (final ArrayIndexOutOfBoundsException e) { @@ -288,8 +288,8 @@ * Get the selected squares. * @return selected squares */ - public List<MapSquare> getSelectedSquares() { - final List<MapSquare> selection = new ArrayList<MapSquare>(); + public List<MapSquare<GameObject>> getSelectedSquares() { + final List<MapSquare<GameObject>> selection = new ArrayList<MapSquare<GameObject>>(); final Size2D mapSize = mapModel.getMapSize(); final Point pos = new Point(); for (pos.x = 0; pos.x < mapSize.getWidth(); pos.x++) { @@ -389,7 +389,7 @@ erraneousArchObjects.clear(); mapGrid.clearErrors(); for (ValidationError validationError : errors.getErrors()) { - final MapSquare mapSquare = validationError.getMapSquare(); + final MapSquare<GameObject> mapSquare = validationError.getMapSquare(); final GameObject archObject = validationError.getGameObject(); if (mapSquare != null) { erraneousMapSquares.put(mapSquare, validationError); Modified: trunk/daimonin/src/daieditor/CopyBuffer.java =================================================================== --- trunk/daimonin/src/daieditor/CopyBuffer.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/daimonin/src/daieditor/CopyBuffer.java 2006-10-07 13:41:41 UTC (rev 484) @@ -29,12 +29,12 @@ import daieditor.map.MapArchObject; import daieditor.map.MapControl; import daieditor.map.MapModel; -import daieditor.map.MapSquare; import java.awt.Point; import java.awt.Rectangle; import java.util.ArrayList; import java.util.List; import net.sf.gridarta.Size2D; +import net.sf.gridarta.map.MapSquare; import org.jetbrains.annotations.Nullable; /** @@ -150,7 +150,7 @@ final Point offset = selRec.getLocation(); mapControl.getMapModel().beginTransaction(); final List<GameObject> archesToDelete = new ArrayList<GameObject>(); - for (final MapSquare square : mapControl.getMapViewFrame().getView().getSelectedSquares()) { + for (final MapSquare<GameObject> square : mapControl.getMapViewFrame().getView().getSelectedSquares()) { final int posx = square.getMapX(); final int posy = square.getMapY(); for (final GameObject arch : square) { @@ -200,7 +200,7 @@ mapControl.getMapModel().beginTransaction(); final Point pos = new Point(); assert copyMap != null; - for (final MapSquare square : copyMap) { + for (final MapSquare<GameObject> square : copyMap) { pos.setLocation(startp.x + square.getMapX(), startp.y + square.getMapY()); // paste the archs if on the map: if (mapControl.isPointValid(pos)) { @@ -214,7 +214,7 @@ } assert copyMapCtrl != null; - for (final MapSquare square : copyMapCtrl.getMapModel()) { + for (final MapSquare<GameObject> square : copyMapCtrl.getMapModel()) { pos.setLocation(startp); pos.translate(square.getMapX(), square.getMapY()); if (mapControl.isPointValid(pos)) { // paste the archs if on the map: @@ -295,7 +295,7 @@ final Point pos = new Point(); for (pos.x = 0; pos.x < mapSize.getWidth(); pos.x++) { for (pos.y = 0; pos.y < mapSize.getHeight(); pos.y++) { - for (GameObject node : map.getMapSquare(pos)) { + for (final GameObject node : map.getMapSquare(pos)) { // only non multi suckers if (!node.isTail()) { @@ -341,11 +341,11 @@ return null; } final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); - final Iterable<MapSquare> mapSquares; + final Iterable<MapSquare<GameObject>> mapSquares; if (mapViewIFrame == null) { mapSquares = mapControl.getAllSquares(); } else { - final List<MapSquare> selectedMapSquares = mapViewIFrame.getView().getSelectedSquares(); + final List<MapSquare<GameObject>> selectedMapSquares = mapViewIFrame.getView().getSelectedSquares(); if (selectedMapSquares.size() == 0) { mapSquares = mapControl.getAllSquares(); } else { @@ -353,7 +353,7 @@ } } final List<GameObject> objects = new ArrayList<GameObject>(max); - for (final MapSquare mapSquare : mapSquares) { + for (final MapSquare<GameObject> mapSquare : mapSquares) { for (final GameObject node : mapSquare) { if (!node.isTail()) { objects.add(node); Modified: trunk/daimonin/src/daieditor/ReplaceDialog.java =================================================================== --- trunk/daimonin/src/daieditor/ReplaceDialog.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/daimonin/src/daieditor/ReplaceDialog.java 2006-10-07 13:41:41 UTC (rev 484) @@ -27,7 +27,6 @@ import daieditor.gameobject.GameObject; import daieditor.map.MapControl; -import daieditor.map.MapSquare; import java.awt.FlowLayout; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; @@ -47,6 +46,7 @@ import static javax.swing.WindowConstants.HIDE_ON_CLOSE; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; +import net.sf.gridarta.map.MapSquare; /** * This dialog manages the replace action. @@ -313,8 +313,8 @@ assert mapViewIFrame != null; int replaceCount = 0; final int replaceListSize = replaceList == null ? 0 : replaceList.size(); - for (MapSquare square : entireMap ? mapControl.getMapModel() : mapViewIFrame.getView().getSelectedSquares()) { - for (GameObject node : square) { + for (final MapSquare<GameObject> square : entireMap ? mapControl.getMapModel() : mapViewIFrame.getView().getSelectedSquares()) { + for (final GameObject node : square) { if (!node.isMulti() && (matchCriteria == MATCH_ARCH_NAME && node.getArchetypeName() != null && node.getArchetypeName().equalsIgnoreCase(matchString) || matchCriteria == MATCH_OBJ_NAME && node.getBestName().equalsIgnoreCase(matchString))) { Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 13:41:41 UTC (rev 484) @@ -34,12 +34,13 @@ import daieditor.ScriptArchData; import daieditor.gameobject.anim.AnimationObject; import daieditor.gameobject.anim.AnimationObjects; -import daieditor.map.MapSquare; import java.io.Serializable; import javax.swing.ImageIcon; import javax.swing.JList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import net.sf.gridarta.gameobject.GameObjectContainer; +import net.sf.gridarta.map.MapSquare; /** * The <code>GameObject</code> class handles the Daimonin GameObjects. @@ -54,7 +55,7 @@ * normal arches. * @todo this class is not always the best place for multipart object handling, see also {@link GameObjectContainer} for issues about this */ -public final class GameObject /*extends NamedObject*/ extends GameObjectContainer implements Cloneable, net.sf.gridarta.gameobject.GameObject, Serializable { +public final class GameObject /*extends NamedObject*/ extends net.sf.gridarta.gameobject.GameObject<GameObject> implements Cloneable, Serializable { /** Serial Version. */ private static final long serialVersionUID = 1L; @@ -164,7 +165,7 @@ * <li>A MapSquare, which means that this GameObject is top level on that MapSquare.</li> * </ul> */ - private GameObjectContainer container; + private GameObjectContainer<GameObject> container; private int archType; // CF object type of the arch @@ -202,11 +203,6 @@ this.archetype = archetype; } - /** {@inheritDoc} */ - public void setArchetype(final net.sf.gridarta.gameobject.GameObject archetype) { - this.archetype = (GameObject) archetype; - } - /** Set this to default arch. */ public void setIsArchetype() { this.archetype = this; @@ -431,32 +427,18 @@ return isInContainer() ? ((GameObject) container).getTopContainer() : this; } - /** - * Sets container of this GameObject. - * There are two possibilities for the container: - * <ul> - * <li>Another GameObject, which means this object is in the inventory of that GameObject.</li> - * <li>A MapSquare, which means that this GameObject is top level on that MapSquare.</li> - * </ul> - * @param container container of this GameObject. - */ - public void setContainer(final GameObjectContainer container) { + /** {@inheritDoc} */ + public void setContainer(final GameObjectContainer<GameObject> container) { this.container = container; } - /** - * Check whether this GameObject is in a Container (in Daimonin sense, - * which means being in a MapSquare isn't, but being in an GameObject is). - * @return <code>true</code> if this GameObject has a Container and the - * Container is an GameObject, otherwise (no Container or Container is not - * an GameObject) false - */ + /** {@inheritDoc} */ public boolean isInContainer() { return container != null && container instanceof GameObject; } /** {@inheritDoc} */ - @Override public MapSquare getMapSquare() { + @Override public MapSquare<GameObject> getMapSquare() { return container != null ? container.getMapSquare() : null; } Deleted: trunk/daimonin/src/daieditor/gameobject/GameObjectContainer.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObjectContainer.java 2006-10-07 11:38:41 UTC (rev 483) +++ trunk/daimonin/src/daieditor/gameobject/GameObjectContainer.java 2006-10-07 13:41:41 UTC (rev 484) @@ -1,427 +0,0 @@ -/* - * Daimonin Java Editor. - * Copyright (C) 2005 Christian Hujer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package daieditor.gameobject; - -import daieditor.map.MapSquare; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Base class for classes that contain GameObjects as children in the sense of containment. - * The interface serves 2 main purposes: - * <ul> - * <li>{@link GameObject} extends this class for containing other GameObjects, like inventory contents e.g. of a bag or attached events.</li> - * <li>{@link MapSquare} extends this class to list the tiles on a MapSquare.</li> - * </ul> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @todo: In case of MapSquares, this class is most likely bogus regarding multipart objects. This needs to be fixed. - */ -@SuppressWarnings({"ClassReferencesSubclass"}) -public abstract class GameObjectContainer implements Iterable<GameObject>, Serializable { - - /** Serial Version. */ - private static final long serialVersionUID = 1L; - - /** - * The contents of this container. - * @note the order of this container is bottom to top. - */ - @NotNull private List<GameObject> contents; - - /** Iterable implementation for recursice traversal. */ - @NotNull private transient Iterable<GameObject> recursive; - - /** Iterable implementation for reverse traversal. */ - @NotNull private transient Iterable<GameObject> reverse; - - /** Create a new GameObjectContainer. */ - protected GameObjectContainer() { - initData(); - } - - /** - * Initialize the fields. - * This is needed because there are two ways of object construction, - * <ul> - * <li>regular object construction via constructor invocation and</li> - * <li>cloning of objects via {@link #clone()}.</li> - * </ul> - */ - private void initData() { - contents = new ArrayList<GameObject>(); - recursive = new Iterable<GameObject>() { - /** {@inheritDoc} */ - public Iterator<GameObject> iterator() { - return new RecursiveGameObjectIterator(GameObjectContainer.this); - } - }; - reverse = new Iterable<GameObject>() { - /** {@inheritDoc} */ - public Iterator<GameObject> iterator() { - return new ReverseIterator<GameObject>(contents); - } - }; // Iterable<GameObject> reverse - } - - /** - * {@inheritDoc} - * The Iterator returned does not recurse, it only contains objects on the first level. - * The Iterator returned is transparent, that means modifying the iterator's collection actually modifies the underlying GameObjectContainer. - */ - @NotNull public final Iterator<GameObject> iterator() { - // Do not return contents.iterator() directly because otherwise the remove() operation will not properly unlink the removed GameObject from its container. - return new Iterator<GameObject>() { - - /** The basic iterator. */ - private Iterator<GameObject> delegate = contents.iterator(); - private GameObject current; - - /** {@inheritDoc} */ - public boolean hasNext() { - return delegate.hasNext(); - } - - /** {@inheritDoc} */ - public GameObject next() { - return current = delegate.next(); - } - - /** {@inheritDoc} */ - public void remove() { - // keep this in sync with GameObjectContainer#remove(GameObject) - // we can't simply invoke GameObjectContainer#remove(current) because that would result in a ConcurrentModificationException. - delegate.remove(); - current.setContainer(null); - squareChanged(); - } - }; - } - - /** - * Return an object that is the reverse representation. - * Invoke this method if you want to iterate over the contained GameObjects in reverse order. - * @return reverse representation - */ - @NotNull public final Iterable<GameObject> reverse() { - return reverse; - } - - /** - * Return an object that is a recursive representation. - * Invoke this method if you want to iterate over the contained GameObjects recursively. - * @return recursive representation - */ - @NotNull public final Iterable<GameObject> recursive() { - return recursive; - } - - /** - * Check whether this square is empty. - * @return <code>true</code> if this square is empty, otherwise <code>false</code> - */ - public boolean isEmpty() { - return contents.isEmpty(); - } - - /** - * Return the first GameObject contained in this container. - * @return first GameObject contained or <code>null</code> if {@link #isEmpty()} returns <code>true</code> - */ - @Nullable public final GameObject getFirst() { - return contents.isEmpty() ? null : contents.get(0); - } - - /** - * Return the last GameObject contained in this container. - * You should not invoke this method to iterate over GameObjects, such invocation is regarded deprecated. - * @return last GameObject contained or <code>null</code> if {@link #isEmpty()} returns <code>true</code> - */ - @Nullable public final GameObject getLast() { - return contents.isEmpty() ? null : contents.get(contents.size() - 1); - } - - /** - * Remove a GameObject from this container. - * @param gameObject GameObject to remove - * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container - */ - final void remove(@NotNull final GameObject gameObject) { - // keep this in sync with iterator() - if (!contents.remove(gameObject)) { - throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); - } - gameObject.setContainer(null); - squareChanged(); - } - - /** Remove all GameObjects from this container. */ - public final void removeAll() { - if (contents.size() <= 0) { - return; - } - - for (final GameObject gameObject : contents) { - gameObject.setContainer(null); - } - contents.clear(); - squareChanged(); - } - - /** - * Move an item to top. - * @param gameObject item to move to top - * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container - */ - public final void moveTop(@NotNull final GameObject gameObject) { - final int oldIndex = contents.indexOf(gameObject); - if (oldIndex != contents.size() - 1) { - if (!contents.remove(gameObject)) { - throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); - } - contents.add(gameObject); - squareChanged(); - } - } - - /** - * Move an item up. - * @param gameObject item to move up - * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container - */ - public final void moveUp(@NotNull final GameObject gameObject) { - final int oldIndex = contents.indexOf(gameObject); - if (oldIndex < contents.size() - 1) { - if (!contents.remove(gameObject)) { - throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); - } - contents.add(oldIndex + 1, gameObject); - squareChanged(); - } - } - - /** - * Move an item down. - * @param gameObject item to move down - * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container - */ - public final void moveDown(@NotNull final GameObject gameObject) { - final int oldIndex = contents.indexOf(gameObject); - if (oldIndex > 0) { - if (!contents.remove(gameObject)) { - throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); - } - contents.add(oldIndex - 1, gameObject); - squareChanged(); - } - } - - /** - * Move an item to bottom. - * @param gameObject item to move to bottom - * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container - */ - public final void moveBottom(@NotNull final GameObject gameObject) { - final int oldIndex = contents.indexOf(gameObject); - if (oldIndex != 0) { - if (!contents.remove(gameObject)) { - throw new IllegalArgumentException(ga... [truncated message content] |
From: <chr...@us...> - 2006-10-07 14:01:52
|
Revision: 485 http://svn.sourceforge.net/gridarta/?rev=485&view=rev Author: christianhujer Date: 2006-10-07 07:01:36 -0700 (Sat, 07 Oct 2006) Log Message: ----------- Some MapModel unification and cleanup. Modified Paths: -------------- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/map/MapModel.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java trunk/daimonin/src/daieditor/map/MapModel.java trunk/src/app/net/sf/gridarta/map/MapModel.java Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-10-07 13:41:41 UTC (rev 484) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-10-07 14:01:36 UTC (rev 485) @@ -213,8 +213,8 @@ } /** {@inheritDoc} */ - public MapSquare<GameObject> getMapSquare(final Point p) throws ArrayIndexOutOfBoundsException { - return mapGrid[p.x][p.y]; + public MapSquare<GameObject> getMapSquare(@NotNull final Point pos) throws ArrayIndexOutOfBoundsException { + return mapGrid[pos.x][pos.y]; } /** Modified: trunk/crossfire/src/cfeditor/map/MapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapModel.java 2006-10-07 13:41:41 UTC (rev 484) +++ trunk/crossfire/src/cfeditor/map/MapModel.java 2006-10-07 14:01:36 UTC (rev 485) @@ -2,10 +2,9 @@ import cfeditor.gameobject.GameObject; import java.awt.Point; -import java.util.Iterator; +import net.sf.gridarta.map.MapSquare; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import net.sf.gridarta.map.MapSquare; /** * Interface for MapModels. @@ -19,17 +18,6 @@ /** Disable autojoin when inserting objects. */ boolean JOIN_DISABLE = false; - /** {@inheritDoc} */ - Iterator<MapSquare<GameObject>> iterator(); - - /** - * Get the square at a specified location. - * @param p location to get square at - * @return square at <var>p</var> - * @throws ArrayIndexOutOfBoundsException in case p specifies a location that's not valid within this map model - */ - MapSquare<GameObject> getMapSquare(Point p) throws ArrayIndexOutOfBoundsException; - @Nullable Point getMouseRightPos(); @Deprecated boolean addArchToMap(String archname, int xx, int yy, int intern, boolean join, boolean insertBelow); Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-10-07 13:41:41 UTC (rev 484) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-10-07 14:01:36 UTC (rev 485) @@ -185,8 +185,8 @@ } /** {@inheritDoc} */ - public MapSquare<GameObject> getMapSquare(final Point p) throws ArrayIndexOutOfBoundsException { - return mapGrid[p.x][p.y]; + public MapSquare<GameObject> getMapSquare(@NotNull final Point pos) throws ArrayIndexOutOfBoundsException { + return mapGrid[pos.x][pos.y]; } /** Modified: trunk/daimonin/src/daieditor/map/MapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapModel.java 2006-10-07 13:41:41 UTC (rev 484) +++ trunk/daimonin/src/daieditor/map/MapModel.java 2006-10-07 14:01:36 UTC (rev 485) @@ -3,10 +3,9 @@ import daieditor.gameobject.GameObject; import java.awt.Point; import java.io.Serializable; -import java.util.Iterator; +import net.sf.gridarta.map.MapSquare; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import net.sf.gridarta.map.MapSquare; /** * Interface for MapModels. @@ -19,20 +18,9 @@ * And there is no rollback. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public interface MapModel extends Iterable<MapSquare<GameObject>>, net.sf.gridarta.map.MapModel<GameObject>, Serializable { +public interface MapModel extends net.sf.gridarta.map.MapModel<GameObject>, Serializable { - /** {@inheritDoc} */ - Iterator<MapSquare<GameObject>> iterator(); - /** - * Get the square at a specified location. - * @param p location to get square at - * @return square at <var>p</var> - * @throws ArrayIndexOutOfBoundsException in case p specifies a location that's not valid within this map model - */ - MapSquare<GameObject> getMapSquare(Point p) throws ArrayIndexOutOfBoundsException; - - /** * Get the currently selected map square. * @return currently selected map square * @deprecated this method requires MapModel implementations to know their views Modified: trunk/src/app/net/sf/gridarta/map/MapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapModel.java 2006-10-07 13:41:41 UTC (rev 484) +++ trunk/src/app/net/sf/gridarta/map/MapModel.java 2006-10-07 14:01:36 UTC (rev 485) @@ -10,7 +10,7 @@ * A MapModel reflects the data of a map. * This MapModel interface covers the similarities between the current CFEditor and DaiEditor implementations. */ -public interface MapModel<G extends GameObject> { +public interface MapModel<G extends GameObject> extends Iterable<MapSquare<G>> { /** * Return the map size of this level. @@ -55,4 +55,12 @@ */ void squareChanged(@NotNull final MapSquare<G> square); + /** + * Get the square at a specified location. + * @param pos location to get square at + * @return square at <var>p</var> + * @throws ArrayIndexOutOfBoundsException in case p specifies a location that's not valid within this map model + */ + MapSquare<G> getMapSquare(@NotNull Point pos) throws ArrayIndexOutOfBoundsException; + } // interface MapModel This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-07 14:12:28
|
Revision: 486 http://svn.sourceforge.net/gridarta/?rev=486&view=rev Author: christianhujer Date: 2006-10-07 07:12:12 -0700 (Sat, 07 Oct 2006) Log Message: ----------- Some GameObject unification. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-07 14:01:36 UTC (rev 485) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-07 14:12:12 UTC (rev 486) @@ -91,7 +91,6 @@ public ArchetypeSet(final CMainControl mainControl) { this.mainControl = mainControl; faceListCount = 0; - GameObject.setArchetypeSet(this); // add static reference to GameObject } /** Returns the index of a face in the face map or -1. Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 14:01:36 UTC (rev 485) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 14:12:12 UTC (rev 486) @@ -56,9 +56,6 @@ /** Special constant that's used if an arch has no arch type set. */ public static final int TYPE_UNSET = -666; - /** Static reference to the ArchetypeSet (Archetypes). */ - private static ArchetypeSet archetypeSet; - /** Static reference to the typeList (find syntax errors). */ private static CFArchTypeList typeList; @@ -130,13 +127,6 @@ private boolean noface; // if true, arch has no face as default - /** - * If this flag is set, the arch is not a "real" arch but comes from the - * artifacts file. Such GameObject instances are not included in the arch - * collection, since the artifacts file is the same for editor and server. - */ - private boolean artifact; - private int facenr; // the index of faceImages[] private boolean editflag; // if true, object is in a editor @@ -183,7 +173,6 @@ objName = null; noface = true; // this sucker has no face - artifact = false; // will be true for arches from the artifacts file faceName = null; // if there is a face cmd, this is the face name facenr = -1; // if we have a face AND we have loaded the face, this is his number. // if faceName != null and facenr == -1, we haven't loaded the face @@ -199,14 +188,6 @@ editType = 0; } - /** - * Set the ArchetypeSet to get information on Archetypes. - * @param archetypeSet ArchetypeSet - */ - public static void setArchetypeSet(final ArchetypeSet archetypeSet) { - GameObject.archetypeSet = archetypeSet; - } - public static void setTypeList(final CFArchTypeList tlist) { typeList = tlist; } @@ -603,16 +584,6 @@ myId = num; } - /** {@inheritDoc} */ - public void setArtifact(final boolean artifact) { - this.artifact = artifact; - } - - /** {@inheritDoc} */ - public boolean isArtifact() { - return artifact; - } - /** * Insert an GameObject before this GameObject. * @param node GameObject to append @@ -629,16 +600,6 @@ getContainer().insertAfter(this, node); } - /** {@inheritDoc} */ - public int countInvObjects() { - int count = 0; - for (final GameObject arch : this) { - count++; - count += arch.countInvObjects(); - } - return count; - } - /** * Determine the horizontal extent in tiles. For single-part objects 1 is * returned. Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 14:01:36 UTC (rev 485) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 14:12:12 UTC (rev 486) @@ -139,13 +139,6 @@ private boolean noface; - /** - * If this flag is set, the arch is not a "real" arch but comes from the - * artifacts file. Such GameObject instances are not included in the arch - * collection, since the artifacts file is the same for editor and server. - */ - private boolean artifact; - /** State where the face comes from. */ private FaceDesc faceobjdesc; @@ -219,7 +212,7 @@ * a default arch itself, otherwise <code>false</code> */ public boolean hasArchetype() { - return archetype != null; + return getArchetype() != null; } /** @@ -230,7 +223,7 @@ * as the other GameObject, otherwise <code>false</code> */ public boolean hasSameArchetype(final GameObject other) { - return archetype == other.archetype; + return getArchetype() == other.getArchetype(); } /** {@inheritDoc} */ @@ -442,16 +435,6 @@ return container != null ? container.getMapSquare() : null; } - /** {@inheritDoc} */ - public void setArtifact(final boolean artifact) { - this.artifact = artifact; - } - - /** {@inheritDoc} */ - public boolean isArtifact() { - return artifact; - } - /** Move this GameObject top. */ public void moveTop() { container.moveTop(this); @@ -505,16 +488,6 @@ getContainer().insertAfter(this, node); } - /** {@inheritDoc} */ - public int countInvObjects() { - int count = 0; - for (final GameObject arch : this) { - count++; - count += arch.countInvObjects(); - } - return count; - } - /** * Determine the horizontal extent in tiles. For single-part objects 1 is * returned. Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-07 14:01:36 UTC (rev 485) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-07 14:12:12 UTC (rev 486) @@ -4,7 +4,8 @@ import org.jetbrains.annotations.Nullable; /** - * This interface serves as a common interface for GameObjects for Daimonin and Crossfire to allow classes that use GameObjects being reused and moved to Gridarta. + * A GameObject instance reflects a GameObject (object on a map) or an Archetype. + * This abstract class serves as a common base for GameObjects for Daimonin and Crossfire to allow classes that use GameObjects being reused and moved to Gridarta. * * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ @@ -12,11 +13,24 @@ public abstract class GameObject<G extends GameObject> extends GameObjectContainer<G> { /** + * If this flag is set, this Archetype is not a "real" Archetype but comes from the artifacts file. + * Such Archetypes instances are not included in the Archetype collection process, since the artifacts file is the same for editor and server. + */ + private boolean artifact; + + /** * Count the number of all inventory items (recursively). * The returned value does not include this GameObject. * @return number of objects in the inventory (recursively) */ - public abstract int countInvObjects(); + public int countInvObjects() { + int count = 0; + for (final GameObject arch : this) { + count++; + count += arch.countInvObjects(); + } + return count; + } /** * Returns the object text of this game object as String. @@ -197,14 +211,18 @@ * @see #setArtifact(boolean) * @see #isArchetype() */ - public abstract boolean isArtifact(); + public boolean isArtifact() { + return artifact; + } /** * Sets whether this GameObject is an Artifact. * @param artifact <code>true</code> if this GameObject is an Artifact, otherwise <code>false</code>. * @see #isArtifact() */ - public abstract void setArtifact(boolean artifact); + public void setArtifact(final boolean artifact) { + this.artifact = artifact; + } /** * Get the EditType of an GameObject (e.g. floor, monster, etc). These are This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-07 14:24:55
|
Revision: 488 http://svn.sourceforge.net/gridarta/?rev=488&view=rev Author: christianhujer Date: 2006-10-07 07:24:41 -0700 (Sat, 07 Oct 2006) Log Message: ----------- Fixed unspecified return type. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/GameObject.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 14:21:57 UTC (rev 487) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 14:24:41 UTC (rev 488) @@ -412,7 +412,7 @@ } /** {@inheritDoc} */ - @NotNull public GameObjectContainer getContainer() { + @NotNull public GameObjectContainer<GameObject> getContainer() { return container; } Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 14:21:57 UTC (rev 487) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 14:24:41 UTC (rev 488) @@ -411,7 +411,7 @@ } /** {@inheritDoc} */ - @NotNull public GameObjectContainer getContainer() { + @NotNull public GameObjectContainer<GameObject> getContainer() { return container; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-07 14:41:48
|
Revision: 489 http://svn.sourceforge.net/gridarta/?rev=489&view=rev Author: christianhujer Date: 2006-10-07 07:41:30 -0700 (Sat, 07 Oct 2006) Log Message: ----------- Merged container related GameObject features. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 14:24:41 UTC (rev 488) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 14:41:30 UTC (rev 489) @@ -38,8 +38,6 @@ import java.util.HashMap; import java.util.List; import javax.swing.JList; -import net.sf.gridarta.gameobject.GameObjectContainer; -import net.sf.gridarta.map.MapSquare; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -132,16 +130,6 @@ private boolean editflag; // if true, object is in a editor /** - * Container of this GameObject. - * There are two possibilities for the container: - * <ul> - * <li>Another GameObject, which means this object is in the inventory of that GameObject.</li> - * <li>A MapSquare, which means that this GameObject is top level on that MapSquare.</li> - * </ul> - */ - private GameObjectContainer<GameObject> container; - - /** * All inventory objects. Set to {@link Collections#EMPTY_LIST} * (to save space) if the object has no inventory. */ @@ -411,69 +399,7 @@ return getAttributeDouble(attributeName, true); } - /** {@inheritDoc} */ - @NotNull public GameObjectContainer<GameObject> getContainer() { - return container; - } - - /** {@inheritDoc} */ - @NotNull public GameObject getTopContainer() { - return isInContainer() ? ((GameObject) container).getTopContainer() : this; - } - - /** {@inheritDoc} */ - public void setContainer(final GameObjectContainer<GameObject> container) { - this.container = container; - } - - /** {@inheritDoc} */ - public boolean isInContainer() { - return container != null && container instanceof GameObject; - } - - /** {@inheritDoc} */ - @Override public MapSquare<GameObject> getMapSquare() { - return container != null ? container.getMapSquare() : null; - } - - /** Move this GameObject top. */ - public void moveTop() { - container.moveTop(this); - } - - /** Move this GameObject up. */ - public void moveUp() { - container.moveUp(this); - } - - /** Move this GameObject down. */ - public void moveDown() { - container.moveDown(this); - } - - /** Move this GameObject bottom. */ - public void moveBottom() { - container.moveBottom(this); - } - /** - * Remove this GameObject from its container. Do nothing if the object is - * not inside a container. - * This method also takes perfectly well care of multihead arches. - */ - public void remove() { - final GameObject head = getHead(); - for (GameObject tail = head.getMultiNext(); tail != null; tail = tail.getMultiNext()) { - if (tail.container != null) { - tail.container.remove(tail); - } - } - if (head.container != null) { - head.container.remove(head); - } - } - - /** * Set the String of an arch attribute in the objectText. * @param attributeName search for "attributeName <string>" * @param value value to set Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 14:24:41 UTC (rev 488) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 14:41:30 UTC (rev 489) @@ -37,10 +37,9 @@ import java.io.Serializable; import javax.swing.ImageIcon; import javax.swing.JList; +import net.sf.gridarta.gameobject.GameObjectContainer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import net.sf.gridarta.gameobject.GameObjectContainer; -import net.sf.gridarta.map.MapSquare; /** * The <code>GameObject</code> class handles the Daimonin GameObjects. @@ -150,16 +149,6 @@ private int direction; - /** - * Container of this GameObject. - * There are two possibilities for the container: - * <ul> - * <li>Another GameObject, which means this object is in the inventory of that GameObject.</li> - * <li>A MapSquare, which means that this GameObject is top level on that MapSquare.</li> - * </ul> - */ - private GameObjectContainer<GameObject> container; - private int archType; // CF object type of the arch /** Edit Type. */ @@ -410,69 +399,7 @@ return getAttributeDouble(attributeName, true); } - /** {@inheritDoc} */ - @NotNull public GameObjectContainer<GameObject> getContainer() { - return container; - } - - /** {@inheritDoc} */ - @NotNull public GameObject getTopContainer() { - return isInContainer() ? ((GameObject) container).getTopContainer() : this; - } - - /** {@inheritDoc} */ - public void setContainer(final GameObjectContainer<GameObject> container) { - this.container = container; - } - - /** {@inheritDoc} */ - public boolean isInContainer() { - return container != null && container instanceof GameObject; - } - - /** {@inheritDoc} */ - @Override public MapSquare<GameObject> getMapSquare() { - return container != null ? container.getMapSquare() : null; - } - - /** Move this GameObject top. */ - public void moveTop() { - container.moveTop(this); - } - - /** Move this GameObject up. */ - public void moveUp() { - container.moveUp(this); - } - - /** Move this GameObject down. */ - public void moveDown() { - container.moveDown(this); - } - - /** Move this GameObject bottom. */ - public void moveBottom() { - container.moveBottom(this); - } - /** - * Remove this GameObject from its container. Do nothing if the object is - * not inside a container. - * This method also takes perfectly well care of multihead arches. - */ - public void remove() { - final GameObject head = getHead(); - for (GameObject tail = head.getMultiNext(); tail != null; tail = tail.getMultiNext()) { - if (tail.container != null) { - tail.container.remove(tail); - } - } - if (head.container != null) { - head.container.remove(head); - } - } - - /** * Insert a GameObject before this GameObject. * @param node GameObject to append */ @@ -1064,7 +991,7 @@ clone.mapx = -1; clone.mapy = -1; clone.multi = null; - clone.container = null; + clone.setContainer(null); return clone; } catch (final CloneNotSupportedException e) { assert false; @@ -1267,7 +1194,7 @@ * @param other GameObject that is to replace this one */ public void replace(final GameObject other) { - container.replace(this, other); + getContainer().replace(this, other); } /** Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-07 14:24:41 UTC (rev 488) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-07 14:41:30 UTC (rev 489) @@ -2,6 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import net.sf.gridarta.map.MapSquare; /** * A GameObject instance reflects a GameObject (object on a map) or an Archetype. @@ -19,6 +20,16 @@ private boolean artifact; /** + * Container of this GameObject. + * There are two possibilities for the container: + * <ul> + * <li>Another GameObject, which means this object is in the inventory of that GameObject.</li> + * <li>A MapSquare, which means that this GameObject is top level on that MapSquare.</li> + * </ul> + */ + @Nullable private GameObjectContainer<G> container; + + /** * Count the number of all inventory items (recursively). * The returned value does not include this GameObject. * @return number of objects in the inventory (recursively) @@ -135,7 +146,9 @@ * @return container of this GameObject. * @see #getTopContainer() */ - @Nullable public abstract GameObjectContainer<G> getContainer(); // todo: change return type to something more specific. + @Nullable public GameObjectContainer<G> getContainer() { + return container; + } /** * Get the topmost container of this GameObject (in Game sense, which @@ -144,7 +157,9 @@ * If this object is topmost itself, it returns itself. * @see #getContainer() */ - @NotNull public abstract G getTopContainer(); + @NotNull public G getTopContainer() { + return (G) (isInContainer() ? ((G) container).getTopContainer() : this); + } /** * Sets container of this GameObject. @@ -155,7 +170,9 @@ * </ul> * @param container container of this GameObject. */ - public abstract void setContainer(final GameObjectContainer<G> container); + public void setContainer(@Nullable final GameObjectContainer<G> container) { + this.container = container; + } /** * Check whether this GameObject is in a Container (in Daimonin sense, @@ -164,9 +181,53 @@ * Container is an GameObject, otherwise (no Container or Container is not * an GameObject) false */ - public abstract boolean isInContainer(); + public boolean isInContainer() { + return container != null && container instanceof GameObject; + } + /** {@inheritDoc} */ + @Override public MapSquare<G> getMapSquare() { + return container != null ? container.getMapSquare() : null; + } + + /** Move this GameObject top. */ + public void moveTop() { + container.moveTop((G) this); + } + + /** Move this GameObject up. */ + public void moveUp() { + container.moveUp((G) this); + } + + /** Move this GameObject down. */ + public void moveDown() { + container.moveDown((G) this); + } + + /** Move this GameObject bottom. */ + public void moveBottom() { + container.moveBottom((G) this); + } + /** + * Remove this GameObject from its container. Do nothing if the object is + * not inside a container. + * This method also takes perfectly well care of multihead arches. + */ + public void remove() { + final GameObject head = getHead(); + for (GameObject tail = head.getMultiNext(); tail != null; tail = tail.getMultiNext()) { + if (tail.container != null) { + tail.container.remove(tail); + } + } + if (head.container != null) { + head.container.remove(head); + } + } + + /** * Get the Archetype this GameObject is based on. * @return Archetype this GameObject is based on. * @note For Archetypes, this method returns <code>thus</code>. @@ -277,4 +338,14 @@ */ public abstract G createArch(); + /** + * Return the head part of a multi-part object. For single-part objects it + * is the object itself. + * + * @return the head of the object + */ + public abstract G getHead(); + + @Nullable public abstract G getMultiNext(); + } // interface GameObject This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-07 15:37:36
|
Revision: 490 http://svn.sourceforge.net/gridarta/?rev=490&view=rev Author: christianhujer Date: 2006-10-07 08:37:20 -0700 (Sat, 07 Oct 2006) Log Message: ----------- Merged Archetype related code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 14:41:30 UTC (rev 489) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 15:37:20 UTC (rev 490) @@ -90,9 +90,6 @@ private int archTextCount; // lines inserted in ArchText - /** The Archetype of this GameObject. */ - @NotNull private GameObject archetype = this; - /** Map x position if on map. */ private int mapx; @@ -146,6 +143,7 @@ /** Create an GameObject. */ public GameObject() { + setArchetype(this); script = null; // this object stays 'null' unless there are events defined myId = myIdCounter++; // increase ID counter for every new arch created @@ -175,23 +173,6 @@ } /** {@inheritDoc} */ - public GameObject getArchetype() { - return archetype; - } - - /** {@inheritDoc} - * @note DO NOT INVOKE DIRECTLY YET! - */ - public void setArchetype(final GameObject archetype) { - this.archetype = archetype; - } - - /** {@inheritDoc} */ - public boolean isArchetype() { - return archetype == this; - } - - /** {@inheritDoc} */ public int getEditType() { return editType; } @@ -278,7 +259,7 @@ int j; attributeName = attributeName.trim() + " "; // attributeName must be followed by space String result = ""; - if (archetype == getArchetype()) { + if (queryArchetype) { result = getCachedAttributeValue(attributeName); if (result != null) { return result; @@ -286,8 +267,8 @@ result = ""; } // Add all attributes from archetype that don't already exist in aText - if (archetype != null) { - aText = aText + diffArchText(archetype.getObjectText(), true); + if (queryArchetype && hasArchetype()) { + aText = aText + diffArchText(getArchetype().getObjectText(), true); } if (!aText.endsWith("\n")) { @@ -308,7 +289,7 @@ j = i + 1; } } - if (archetype == getArchetype()) { + if (queryArchetype) { setCachedAttributeValue(attributeName, result); } @@ -324,8 +305,8 @@ public int getAttributeInt(@NotNull final String attributeName, final boolean queryArchetype) { String aText = objectText.toString(); // The "real" Archtext from arch & archetype // Add all attributes from archetype that don't already exist in aText - if (archetype != null) { - aText += diffArchText(archetype.getObjectText(), true); + if (queryArchetype && hasArchetype()) { + aText += diffArchText(getArchetype().getObjectText(), true); } assert aText.endsWith("\n"); final String attr2 = attributeName.trim() + ' '; @@ -351,8 +332,8 @@ public long getAttributeLong(@NotNull final String attributeName, final boolean queryArchetype) { String aText = objectText.toString(); // Add all attributes from archetype that don't already exist in aText - if (archetype != null) { - aText += diffArchText(archetype.getObjectText(), true); + if (queryArchetype && hasArchetype()) { + aText += diffArchText(getArchetype().getObjectText(), true); } final String attr2 = attributeName.trim() + ' '; long result = 0; @@ -377,8 +358,8 @@ public double getAttributeDouble(@NotNull final String attributeName, final boolean queryArchetype) { String aText = objectText.toString(); // Add all attributes from archetype that don't already exist in aText - if (archetype != null) { - aText += diffArchText(archetype.getObjectText(), true); + if (queryArchetype && hasArchetype()) { + aText += diffArchText(getArchetype().getObjectText(), true); } final String attr2 = attributeName.trim() + ' '; double result = 0; @@ -761,6 +742,7 @@ * @return best suitable descriptive name */ public String getBestName() { + final GameObject archetype = getArchetype(); if (objName != null && objName.length() > 0) { return objName; } else if (archetype != null && archetype.objName != null && archetype.objName.length() > 0) { @@ -1058,7 +1040,7 @@ clone.script = script.getClone(); // clone scripting data } - clone.archetype = archetype; // default arch + clone.setArchetype(getArchetype()); // default arch clone.noface = noface; // if true, arch has no face as default clone.facenr = facenr; // the index of faceImages[] @@ -1292,7 +1274,7 @@ /** {@inheritDoc} */ public GameObject createArch() { if (!isArchetype()) { - return archetype.createArch(); + return getArchetype().createArch(); } final GameObject arch = new GameObject(); arch.setArchetypeName(archetypeName); Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 14:41:30 UTC (rev 489) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 15:37:20 UTC (rev 490) @@ -94,9 +94,6 @@ */ @Nullable private StringBuffer msgText; - /** The Archetype of this GameObject. */ - @NotNull private GameObject archetype; - /** Map x position if on map. */ private int mapx; @@ -176,46 +173,6 @@ } /** {@inheritDoc} */ - public GameObject getArchetype() { - return archetype; - } - - /** {@inheritDoc} */ - public void setArchetype(final GameObject archetype) { - this.archetype = archetype; - } - - /** Set this to default arch. */ - public void setIsArchetype() { - this.archetype = this; - } - - /** {@inheritDoc} */ - public boolean isArchetype() { - return archetype == this; - } - - /** - * Check whether this GameObject has an Archetype. - * @return <code>true</code> when this GameObject has a default arch or is - * a default arch itself, otherwise <code>false</code> - */ - public boolean hasArchetype() { - return getArchetype() != null; - } - - /** - * Check whether this GameObject has the same default arch as another - * GameObject. - * @param other other GameObject - * @return <code>true</code> when this GameObject has the same default arch - * as the other GameObject, otherwise <code>false</code> - */ - public boolean hasSameArchetype(final GameObject other) { - return getArchetype() == other.getArchetype(); - } - - /** {@inheritDoc} */ public int getEditType() { return editType; } @@ -302,8 +259,8 @@ @NotNull public String getAttributeString(@NotNull final String attributeName, final boolean queryArchetype) { String aText = objectText.toString(); // The "real" Archtext from arch & archetype // Add all attributes from archetype that don't already exist in aText - if (queryArchetype) { - aText += diffArchText(archetype.getObjectText(), true); + if (queryArchetype && hasArchetype()) { + aText += diffArchText(getArchetype().getObjectText(), true); } final String attr2 = attributeName.trim() + ' '; // attributeName must be followed by space String result = ""; // returned String @@ -324,8 +281,8 @@ public int getAttributeInt(@NotNull final String attributeName, final boolean queryArchetype) { String aText = objectText.toString(); // The "real" Archtext from arch & archetype // Add all attributes from archetype that don't already exist in aText - if (archetype != null) { - aText += diffArchText(archetype.getObjectText(), true); + if (queryArchetype && hasArchetype()) { + aText += diffArchText(getArchetype().getObjectText(), true); } assert aText.endsWith("\n"); final String attr2 = attributeName.trim() + ' '; @@ -351,8 +308,8 @@ public long getAttributeLong(@NotNull final String attributeName, final boolean queryArchetype) { String aText = objectText.toString(); // Add all attributes from archetype that don't already exist in aText - if (archetype != null) { - aText += diffArchText(archetype.getObjectText(), true); + if (queryArchetype && hasArchetype()) { + aText += diffArchText(getArchetype().getObjectText(), true); } final String attr2 = attributeName.trim() + ' '; long result = 0; @@ -377,8 +334,8 @@ public double getAttributeDouble(@NotNull final String attributeName, final boolean queryArchetype) { String aText = objectText.toString(); // Add all attributes from archetype that don't already exist in aText - if (archetype != null) { - aText += diffArchText(archetype.getObjectText(), true); + if (queryArchetype && hasArchetype()) { + aText += diffArchText(getArchetype().getObjectText(), true); } final String attr2 = attributeName.trim() + ' '; double result = 0; @@ -681,6 +638,7 @@ * @return best suitable descriptive name */ public String getBestName() { + final GameObject archetype = getArchetype(); if (objName != null && objName.length() > 0) { return objName; } else if (archetype != null && archetype.objName != null && archetype.objName.length() > 0) { @@ -799,7 +757,7 @@ * @param name */ public boolean setRealFace(final String name) { - final String face = archetype.faceRealName; + final String face = getArchetype().faceRealName; /* no name? we always use def arch face */ if (name == null || name.trim().length() == 0) { @@ -826,8 +784,8 @@ // lets check we have in this object or the default arch of it an animation if (effectiveAnimName == null) { faceobjdesc = FaceDesc.DEFARCH_ANIM; - if (archetype != null) { - effectiveAnimName = archetype.animName; + if (hasArchetype()) { + effectiveAnimName = getArchetype().animName; } } @@ -858,8 +816,8 @@ faceobjdesc = FaceDesc.FACE; if (effectiveFaceObjName == null) { faceobjdesc = FaceDesc.DEFARCH_FACE; - if (archetype != null) { - effectiveFaceObjName = archetype.faceRealName; + if (hasArchetype()) { + effectiveFaceObjName = getArchetype().faceRealName; } } } @@ -875,7 +833,7 @@ } else { faceobjdesc = FaceDesc.FACE_NOT_FOUND; } - if (archetype != this) { + if (!isArchetype()) { setFace(); } } @@ -885,7 +843,7 @@ * This method is for speeding up rendering. */ private void setFace() { - if (archetype == null) { + if (!hasArchetype()) { normalFace = CMainControl.noarchTileIcon; transFace = normalFace; } else if (hasFaceObject()) { @@ -1176,7 +1134,7 @@ /** {@inheritDoc} */ public GameObject createArch() { if (!isArchetype()) { - return archetype.createArch(); + return getArchetype().createArch(); } final GameObject arch = new GameObject(); arch.setArchetypeName(archetypeName); Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-07 14:41:30 UTC (rev 489) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-07 15:37:20 UTC (rev 490) @@ -29,6 +29,9 @@ */ @Nullable private GameObjectContainer<G> container; + /** The Archetype of this GameObject. */ + @NotNull protected G archetype; + /** * Count the number of all inventory items (recursively). * The returned value does not include this GameObject. @@ -236,25 +239,31 @@ * @see #isArchetype() * @see #setArchetype(GameObject) */ - @NotNull public abstract G getArchetype(); + @NotNull public G getArchetype() { + return archetype; + } /** - * Get the name of the Archetype this GameObject is based on. - * For an Archetype this method simply returns its name. - * @return the name of the Archetype this GameObject is based on - */ - @NotNull public abstract String getArchetypeName(); - - /** * Returns whether this GameObject is an Archetype. * @return <code>true</code> if this GameObject is an Archetype, otherwise <code>false</code> * @see #getArchetype() * @see #setArchetype(GameObject) * @see #isArtifact() */ - public abstract boolean isArchetype(); + public boolean isArchetype() { + return archetype == this; + } /** + * Check whether this GameObject has an Archetype. + * @return <code>true</code> when this GameObject has a default arch or is + * a default arch itself, otherwise <code>false</code> + */ + public boolean hasArchetype() { + return archetype != null; + } + + /** * Set the Archetype of this GameObject. * @param archetype new Archetype of this GameObject. * @note currently this method takes a GameObject that reflects the Archetype data because there is no separate Archetype class. @@ -262,9 +271,34 @@ * @see #getArchetype() * @see #isArchetype() */ - public abstract void setArchetype(@NotNull final G archetype); + public void setArchetype(@NotNull final G archetype) { + this.archetype = archetype; + } + /** Set that this GameObject is an Archetype. */ + public void setIsArchetype() { + setArchetype((G) this); + } + /** + * Check whether this GameObject has the same default arch as another + * GameObject. + * @param other other GameObject + * @return <code>true</code> when this GameObject has the same default arch + * as the other GameObject, otherwise <code>false</code> + */ + public boolean hasSameArchetype(final G other) { + return archetype == other.archetype; + } + + /** + * Get the name of the Archetype this GameObject is based on. + * For an Archetype this method simply returns its name. + * @return the name of the Archetype this GameObject is based on + */ + @NotNull public abstract String getArchetypeName(); + + /** * Returns whether this GameObject is an Artifact. * Artifacts are special forms of Archetypes, and they are excluded from Archetypes collection. * @return <code>true</code> if this GameObject is an Artifact, otherwise <code>false</code>. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-07 18:58:33
|
Revision: 493 http://svn.sourceforge.net/gridarta/?rev=493&view=rev Author: christianhujer Date: 2006-10-07 11:58:03 -0700 (Sat, 07 Oct 2006) Log Message: ----------- Merged objectext, mapx and mapy of GameObject. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CAttribDialog.java trunk/crossfire/src/cfeditor/CMapFileDecode.java trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/CAttribDialog.java trunk/daimonin/src/daieditor/CMapFileDecode.java trunk/daimonin/src/daieditor/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/map/validation/checks/SysObjectOnLayerZeroError.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gameobject/GameObjectContainer.java trunk/src/app/net/sf/gridarta/map/MapModel.java trunk/src/app/net/sf/gridarta/map/MapSquare.java Modified: trunk/crossfire/src/cfeditor/CAttribDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-10-07 18:58:03 UTC (rev 493) @@ -1402,7 +1402,7 @@ if (typeStruct == typelist.getHead().getNext()) { // for generic (misc) type, all errors are automatically kept. // "misc" is no real type - it is more a default mask for unknown types - gameObject.addArchText(errors.trim() + "\n"); + gameObject.addObjectText(errors.trim() + "\n"); } else { // open a popup dialog and ask user to decide what to do with his errors askConfirmErrors(errors); @@ -1707,7 +1707,7 @@ // the user pressed "keep", so we append the contents // of the textfield to the archtext if (text.getText() != null && text.getText().trim().length() > 0) { - arch.addArchText(text.getText().trim() + "\n"); + arch.addObjectText(text.getText().trim() + "\n"); } } @@ -1722,7 +1722,7 @@ * be assumed that the user did not properly think about them yet. */ public void windowClosing(final WindowEvent e) { - arch.addArchText(allErrors.trim() + "\n"); + arch.addObjectText(allErrors.trim() + "\n"); // nuke the popup dialog dialog.dispose(); Modified: trunk/crossfire/src/cfeditor/CMapFileDecode.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapFileDecode.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/crossfire/src/cfeditor/CMapFileDecode.java 2006-10-07 18:58:03 UTC (rev 493) @@ -212,9 +212,9 @@ msgflag = true; // this is a MUST, because we overrule "anim" test } else if (thisLine.regionMatches(0, "animation", 0, 9)) { - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } else if (thisLine.regionMatches(0, "anim_speed", 0, 10)) { - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } else if (thisLine.regionMatches(0, "anim", 0, 4)) { //arch.addArchText(thisLine + "\n"); animflag = true; @@ -242,7 +242,7 @@ } } else { log.warn("Arch " + arch.getArchetypeName() + " has incorrect event code '" + thisLine + "'"); - arch.addArchText(thisLine + "\n"); // keep line, it might have a meaning after all + arch.addObjectText(thisLine + "\n"); // keep line, it might have a meaning after all } } else if (thisLine.regionMatches(0, "x ", 0, 2)) { final int temp = Integer.parseInt(thisLine.substring(2)); @@ -270,7 +270,7 @@ arch.setFaceFlag(false); arch.setFaceName(thisLine.substring(x, thisLine.length())); } else { - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } } else { // We are in a multipart tail arch ("more"), so we skip it: Modified: trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-07 18:58:03 UTC (rev 493) @@ -199,7 +199,7 @@ } else { arch = defArch.createClone(0, 0); } - arch.resetArchText(); + arch.resetObjectText(); String thisLine2; if (line == null) { @@ -261,7 +261,7 @@ if (thisLine.startsWith("mina")) { mainControl.getAnimationObject().addAnimObject(arch.getArchetypeName(), arch.getAnimText()); - arch.addArchText("animation " + arch.getArchetypeName() + "\n"); + arch.addObjectText("animation " + arch.getArchetypeName() + "\n"); // here we must add this to AnimationObject // and add Animation cmd here! animflag = false; @@ -339,7 +339,7 @@ if (archName != null) { arch.setArtifact(true); // here we add all unchanged arch text lines from defArch back to arch - arch.addArchText(arch.diffArchText(defArch.getObjectText(), true)); + arch.addObjectText(arch.diffArchText(defArch.getObjectText(), true)); return arch; } archlast = arch; @@ -348,9 +348,9 @@ if (thisLine.startsWith("msg")) { msgflag = true; } else if (thisLine.startsWith("animation")) { - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } else if (thisLine.startsWith("anim_speed")) { - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } else if (thisLine.startsWith("anim")) { animflag = true; } else if (thisLine.equals("lore")) { @@ -374,13 +374,13 @@ } else if (thisLine.startsWith("x ")) { if (!archmore && !arch.getArchetypeName().equals(STARTARCH_NAME)) { log.warn("Find x cmd in single tile or head (add it to arch text): " + arch.getArchetypeName()); - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } arch.setMultiX(Integer.parseInt(thisLine.substring(2))); } else if (thisLine.startsWith("y ")) { if (!archmore && !arch.getArchetypeName().equals(STARTARCH_NAME)) { log.warn("Find y cmd in single tile or head (add it to arch text): " + arch.getArchetypeName()); - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } arch.setMultiY(Integer.parseInt(thisLine.substring(2))); } else if (thisLine.startsWith("type ")) { @@ -392,7 +392,7 @@ } } catch (final Exception e) { log.warn("Arch " + arch.getArchetypeName() + " has a invalid type nr. (" + thisLine.substring(5) + ")"); - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } } else if (thisLine.startsWith("face ")) { int x; @@ -410,7 +410,7 @@ isNewCategory = true; // this arch has a new category } } - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); if (log.isDebugEnabled()) { log.debug("add String: " + thisLine); } @@ -431,7 +431,7 @@ */ public static void postParseDefArch(final GameObject arch) { final String text = arch.getObjectText(); - arch.resetArchText(); + arch.resetObjectText(); final int len = text.length(); // if no type was set, zero is taken @@ -445,19 +445,19 @@ if (text.charAt(i) == '\n') { if (i - s > 0) { if (scriptflag) { - arch.addArchText(text.substring(s, i) + "\n"); + arch.addObjectText(text.substring(s, i) + "\n"); if (text.regionMatches(s, "end_script_", 0, 11)) { scriptflag = false; } } else if (text.regionMatches(s, "start_script_", 0, 13)) { - arch.addArchText(text.substring(s, i) + "\n"); + arch.addObjectText(text.substring(s, i) + "\n"); scriptflag = true; } else if (text.regionMatches(s, "editable ", 0, 9)) { arch.setEditType(Integer.parseInt(text.substring(s + 9, i))); } else if (text.regionMatches(s, "name ", 0, 5)) { arch.setObjName(text.substring(s + 5, i)); } else { - arch.addArchText(text.substring(s, i) + "\n"); + arch.addObjectText(text.substring(s, i) + "\n"); } } @@ -498,7 +498,7 @@ final int len = text.length(); final GameObject archetype = mainControl.getArchetype(gameObject.getArchetypeName()); - gameObject.resetArchText(); + gameObject.resetObjectText(); for (int i = 0, s = 0; i < len; i++) { if (text.charAt(i) == '\n') { @@ -507,7 +507,7 @@ gameObject.setObjName(text.substring(s + 5, i)); } else { // this is an unparsed arch attribute, it has to stay in the archtext - gameObject.addArchText(text.substring(s, i) + "\n"); + gameObject.addObjectText(text.substring(s, i) + "\n"); } } s = i + 1; @@ -535,9 +535,9 @@ // we don't handle anim yet, so attach then back to archtext if (gameObject.getAnimText() != null) { - gameObject.addArchText("anim\n"); - gameObject.addArchText(gameObject.getAnimText()); - gameObject.addArchText("mina\n"); + gameObject.addObjectText("anim\n"); + gameObject.addObjectText(gameObject.getAnimText()); + gameObject.addObjectText("mina\n"); } // Finally, we calculate the desired editType of the arch Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 18:58:03 UTC (rev 493) @@ -51,9 +51,6 @@ private static final Logger log = Logger.getLogger(GameObject.class); - /** Special constant that's used if an arch has no arch type set. */ - public static final int TYPE_UNSET = -666; - /** Static reference to the typeList (find syntax errors). */ private static CFArchTypeList typeList; @@ -71,12 +68,6 @@ private String objName; /** - * The objectText with the differences from the Archetype. - * @note Every line in the objectText must end on '\n', including the last line. - */ - @NotNull private StringBuffer objectText; - - /** * The msgText. * @note Every line in msgText must end on '\n', including the last line. * @note If the value is <code>null</code>, the arch has no message text, @@ -90,12 +81,6 @@ private int archTextCount; // lines inserted in ArchText - /** Map x position if on map. */ - private int mapx; - - /** Map y position if on map. */ - private int mapy; - /** * Data for multitile-arches. * Stays null for singlesquare-arches. @@ -148,7 +133,6 @@ myId = myIdCounter++; // increase ID counter for every new arch created - objectText = new StringBuffer(""); msgText = animText = loreText = null; archTextCount = 0; // lines inserted in objectText @@ -163,8 +147,6 @@ editflag = false; join = null; // no autojoin list per default archType = TYPE_UNSET; // type must be set - mapx = 0; - mapy = 0; editType = 0; } @@ -255,7 +237,7 @@ /** {@inheritDoc} */ @NotNull public String getAttributeString(@NotNull String attributeName, final boolean queryArchetype) { - String aText = objectText.toString(); // The "real" Archtext from arch & archetype + String aText = getObjectText(); int j; attributeName = attributeName.trim() + " "; // attributeName must be followed by space String result = ""; @@ -303,7 +285,7 @@ /** {@inheritDoc} */ public int getAttributeInt(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = objectText.toString(); // The "real" Archtext from arch & archetype + String aText = getObjectText(); // Add all attributes from archetype that don't already exist in aText if (queryArchetype && hasArchetype()) { aText += diffArchText(getArchetype().getObjectText(), true); @@ -330,7 +312,7 @@ /** {@inheritDoc} */ public long getAttributeLong(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = objectText.toString(); + String aText = getObjectText(); // Add all attributes from archetype that don't already exist in aText if (queryArchetype && hasArchetype()) { aText += diffArchText(getArchetype().getObjectText(), true); @@ -356,7 +338,7 @@ /** {@inheritDoc} */ public double getAttributeDouble(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = objectText.toString(); + String aText = getObjectText(); // Add all attributes from archetype that don't already exist in aText if (queryArchetype && hasArchetype()) { aText += diffArchText(getArchetype().getObjectText(), true); @@ -386,7 +368,7 @@ * @param value value to set */ public void setAttributeString(String attributeName, final String value) { - String aText = objectText.toString(); // The "real" Archtext from arch + String aText = getObjectText(); // The "real" Archtext from arch int j; attributeName = attributeName.trim() + " "; // attributeName must be followed by space @@ -430,7 +412,7 @@ * @param attributeName search for "attributeName <string>" */ public void removeAttribute(String attributeName) { - String aText = objectText.toString(); // The "real" Archtext from arch + String aText = getObjectText(); int j; attributeName = attributeName.trim() + " "; // attributeName must be followed by space @@ -669,42 +651,6 @@ archType = type; } - public void setMapX(final int mapx) { - this.mapx = mapx; - } - - public void setMapY(final int mapy) { - this.mapy = mapy; - } - - /** {@inheritDoc} */ - public int getMapX() { - return mapx; - } - - /** {@inheritDoc} */ - public int getMapY() { - return mapy; - } - - /** {@inheritDoc} */ - @Override public void addLast(final GameObject arch) { - super.addLast(arch); - // force type change when a MONSTER is put in a spawn point - if (typeList.getTypeOfArch(this) != null && typeList.getTypeOfArch(this).getTypeNr() == 81 && typeList.getTypeOfArch(arch).getTypeNr() == 80) { - arch.archType = 83; // change to SPAWN_POINT_MOB - } - } - - /** {@inheritDoc} */ - @Override public void addFirst(final GameObject arch) { - super.addFirst(arch); - // force type change when a MONSTER is put in a spawn point - if (typeList.getTypeOfArch(this).getTypeNr() == 81 && typeList.getTypeOfArch(arch).getTypeNr() == 80) { - arch.archType = 83; // change to SPAWN_POINT_MOB - } - } - /* Set the default face. Number is index of face list */ public void setFaceNr(final int nr) { facenr = nr; @@ -781,34 +727,12 @@ return faceName; } - /** - * Append <var>text</var> to the arch text of this arch. - * @param text text to add - */ - public void addArchText(final String text) { - objectText.append(text); - } - - /** - * Set <var>text</var> as arch text of this arch. - * @param objectText text to set as arch text - */ + /** {@inheritDoc} */ public void setObjectText(final String objectText) { - this.objectText.delete(0, this.objectText.length()); - this.objectText.append(objectText); + super.setObjectText(objectText); clearCachedAttributeValue(); } - /** {@inheritDoc} */ - @NotNull public String getObjectText() { - return objectText.toString(); - } - - /** Clears the arch text of this arch. */ - public void resetArchText() { - objectText.delete(0, objectText.length()); - } - /** * Get all entries from the given archtext 'atxt' that don't exist in * 'this' archtext. @@ -1009,11 +933,7 @@ clone.objName = objName; // the arch text (contains only the differences from default arch) - if (objectText != null) { - clone.objectText = new StringBuffer(objectText.toString()); - } else { - clone.objectText = null; - } + clone.objectText = new StringBuffer(getObjectText()); clone.archTextCount = archTextCount; // lines of text in objectText // msg text buffer @@ -1050,8 +970,8 @@ clone.archType = archType; // type attribute of the arch // set coords: - clone.mapx = posx; - clone.mapy = posy; + clone.setMapX(posx); + clone.setMapY(posy); // If 'this' arch is a container, we have to create clones // of the whole inventory (recursively) and link them in: @@ -1186,11 +1106,11 @@ */ @Nullable public String getSyntaxErrors(CFArchType type) { - if (typeList != null && objectText != null && objectText.length() > 0) { + if (typeList != null && hasObjectText()) { String errors = ""; // return value: all error lines // open a reading stream for the objectText - final StringReader sread = new StringReader(objectText.toString()); + final StringReader sread = new StringReader(getObjectText()); final BufferedReader sstream = new BufferedReader(sread); try { Modified: trunk/daimonin/src/daieditor/CAttribDialog.java =================================================================== --- trunk/daimonin/src/daieditor/CAttribDialog.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/daimonin/src/daieditor/CAttribDialog.java 2006-10-07 18:58:03 UTC (rev 493) @@ -1268,7 +1268,7 @@ if (typeStruct == typelist.getArchType(0)) { // for generic (misc) type, all errors are automatically kept. // "misc" is no real type - it is more a default mask for unknown types - gameObject.addArchText(errors.trim() + '\n'); + gameObject.addObjectText(errors.trim() + '\n'); } else { // open a popup dialog and ask user to decide what to do with his errors askConfirmErrors(errors); @@ -1555,7 +1555,7 @@ // the user pressed "keep", so we append the contents // of the textfield to the archtext if (text.getText() != null && text.getText().trim().length() > 0) { - arch.addArchText(text.getText().trim() + '\n'); + arch.addObjectText(text.getText().trim() + '\n'); } } @@ -1566,7 +1566,7 @@ /** {@inheritDoc} */ @Override public void windowClosing(final WindowEvent e) { - arch.addArchText(allErrors.trim() + '\n'); + arch.addObjectText(allErrors.trim() + '\n'); // nuke the popup dialog dialog.dispose(); Modified: trunk/daimonin/src/daieditor/CMapFileDecode.java =================================================================== --- trunk/daimonin/src/daieditor/CMapFileDecode.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/daimonin/src/daieditor/CMapFileDecode.java 2006-10-07 18:58:03 UTC (rev 493) @@ -172,12 +172,12 @@ // don't load it into the archtext! (why?) } else if (thisLine.startsWith("direction ")) { arch.setDirection(Integer.parseInt(thisLine.substring(10))); - arch.addArchText(thisLine + '\n'); + arch.addObjectText(thisLine + '\n'); } else if (thisLine.startsWith("face ")) { arch.setFaceRealName(thisLine.substring("face ".length()).trim()); - arch.addArchText(thisLine + '\n'); + arch.addObjectText(thisLine + '\n'); } else { - arch.addArchText(thisLine + '\n'); + arch.addObjectText(thisLine + '\n'); } } } while ((thisLine = myInput.readLine()) != null); Modified: trunk/daimonin/src/daieditor/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/ScriptArchData.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/daimonin/src/daieditor/ScriptArchData.java 2006-10-07 18:58:03 UTC (rev 493) @@ -778,17 +778,17 @@ } private void setEventData(final int eventType, final String pluginName, final String filePath, final String options) { - event.resetArchText(); + event.resetObjectText(); if (pluginName != null && pluginName.length() > 0) { event.setObjName(pluginName); } if (filePath != null && filePath.length() > 0) { - event.addArchText("race " + filePath + '\n'); + event.addObjectText("race " + filePath + '\n'); } if (options != null && options.length() > 0) { - event.addArchText("slaying " + options + '\n'); + event.addObjectText("slaying " + options + '\n'); } - event.addArchText("sub_type " + eventType + '\n'); + event.addObjectText("sub_type " + eventType + '\n'); } } // class ScriptedEvent Modified: trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-07 18:58:03 UTC (rev 493) @@ -135,7 +135,7 @@ path = null; newCat = null; } - arch.resetArchText(); + arch.resetObjectText(); String thisLine2; if (line == null) { @@ -207,7 +207,7 @@ log.log(Level.WARNING, "duplicateAnimation", e); } - arch.addArchText("animation " + arch.getArchetypeName() + "\n"); + arch.addObjectText("animation " + arch.getArchetypeName() + "\n"); arch.setAnimName(arch.getArchetypeName()); // here we must add this to AnimationObject @@ -305,7 +305,7 @@ arch.setArtifact(true); // here we add all unchanged arch text lines from defArch back to arch if (defArch != null) { - arch.addArchText(arch.diffArchText(defArch.getObjectText(), true)); + arch.addObjectText(arch.diffArchText(defArch.getObjectText(), true)); } return arch; } @@ -315,12 +315,12 @@ if (thisLine.startsWith("msg")) { msgflag = true; } else if (thisLine.startsWith("animation ")) { - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); final String animName = thisLine.substring(10).trim(); arch.setAnimName(animName); //arch.setAnimNr(mainControl.animationObjects.findAnimObject(animName)); // probably not needed, but better not delete it yet } else if (thisLine.startsWith("anim_speed ")) { - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } else if (thisLine.startsWith("anim")) { animflag = true; animText = new StringBuilder(); @@ -335,14 +335,14 @@ } else if (thisLine.startsWith("x ")) { if (!archmore && !arch.getArchetypeName().equals(STARTARCH_NAME)) { log.log(Level.WARNING, "foundCoordInDefArchSingleTileOrHead", new Object[]{"x", arch.getArchetypeName()}); - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } else { arch.setMultiX(Integer.parseInt(thisLine.substring(2))); } } else if (thisLine.startsWith("y ")) { if (!archmore && !arch.getArchetypeName().equals(STARTARCH_NAME)) { log.log(Level.WARNING, "foundCoordInDefArchSingleTileOrHead", new Object[]{"y", arch.getArchetypeName()}); - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } else { arch.setMultiY(Integer.parseInt(thisLine.substring(2))); } @@ -355,7 +355,7 @@ } } catch (final NumberFormatException e) { log.log(Level.WARNING, "defArchWithInvalidTypeNr", new Object[]{arch.getArchetypeName(), thisLine.substring(5)}); - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } } else if (thisLine.startsWith("direction ")) { try { @@ -363,7 +363,7 @@ } catch (final NumberFormatException e) { log.log(Level.WARNING, "defArchWithInvalidDirection", new Object[]{arch.getArchetypeName(), thisLine.substring(10)}); } - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } else if (thisLine.startsWith("face ")) { int x; for (x = 4; x < thisLine.length(); x++) { @@ -372,7 +372,7 @@ } } arch.setFaceRealName(thisLine.substring(x, thisLine.length())); - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } else if (thisLine.startsWith("editor_folder ")) { // the display category (= "folder" the arch belongs to) newCat = thisLine.substring(14).trim(); @@ -389,7 +389,7 @@ } } catch (final NumberFormatException e) { System.err.println("WARNING: Arch " + arch.getArchetypeName() + " has a invalid mpart_id (" + thisLine.substring(9) + ')'); - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } } else if (thisLine.startsWith("mpart_nr ")) { // part nr for multiparts @@ -398,10 +398,10 @@ arch.setMultiPartNr(i); } catch (final NumberFormatException e) { System.err.println("WARNING: Arch " + arch.getArchetypeName() + " has a invalid mpart_nr (" + thisLine.substring(9) + ')'); - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } } else { - arch.addArchText(thisLine + "\n"); + arch.addObjectText(thisLine + "\n"); } //System.err.println("add String: "+thisLine); } @@ -418,7 +418,7 @@ */ public static void postParseDefArch(final GameObject arch) { final String text = arch.getObjectText(); - arch.resetArchText(); + arch.resetObjectText(); final int len = text.length(); // if no type was set, zero is taken @@ -432,19 +432,19 @@ if (text.charAt(i) == '\n') { if (i - s > 0) { if (scriptflag) { - arch.addArchText(text.substring(s, i) + "\n"); + arch.addObjectText(text.substring(s, i) + "\n"); if (text.regionMatches(s, "end_script_", 0, 11)) { scriptflag = false; } } else if (text.regionMatches(s, "start_script_", 0, 13)) { - arch.addArchText(text.substring(s, i) + "\n"); + arch.addObjectText(text.substring(s, i) + "\n"); scriptflag = true; } else if (text.regionMatches(s, "editable ", 0, 9)) { arch.setEditType(Integer.parseInt(text.substring(s + 9, i))); } else if (text.regionMatches(s, "name ", 0, 5)) { arch.setObjName(text.substring(s + 5, i)); } else { - arch.addArchText(text.substring(s, i) + "\n"); + arch.addObjectText(text.substring(s, i) + "\n"); } } @@ -486,7 +486,7 @@ final int len = text.length(); final GameObject defarch = arch.getArchetype(); - arch.resetArchText(); + arch.resetObjectText(); // so, lets check the stuff a last time for (int i = 0, s = 0; i < len; i++) { @@ -494,12 +494,12 @@ if (i - s > 0) { if (text.regionMatches(s, "animation ", 0, 9)) { arch.setAnimName(text.substring(s + 10, i)); - arch.addArchText(text.substring(s, i) + "\n"); + arch.addObjectText(text.substring(s, i) + "\n"); } else if (text.regionMatches(s, "name ", 0, 5)) { arch.setObjName(text.substring(s + 5, i)); } else { // this is an unparsed arch attribute, it has to stay in the archtext - arch.addArchText(text.substring(s, i) + "\n"); + arch.addObjectText(text.substring(s, i) + "\n"); } } s = i + 1; Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 18:58:03 UTC (rev 493) @@ -59,9 +59,6 @@ /** Serial Version. */ private static final long serialVersionUID = 1L; - /** Special constant that's used if an arch has no arch type set. */ - public static final int TYPE_UNSET = -666; - /** Static reference to the typeList (find syntax errors). */ private static CFArchTypeList typeList; @@ -81,12 +78,6 @@ private String animName; /** - * The objectText with the differences from the Archetype. - * @note Every line in the objectText must end on '\n', including the last line. - */ - @NotNull private StringBuffer objectText; - - /** * The msgText. * @note Every line in msgText must end on '\n', including the last line. * @note If the value is <code>null</code>, the arch has no message text, @@ -94,12 +85,6 @@ */ @Nullable private StringBuffer msgText; - /** Map x position if on map. */ - private int mapx; - - /** Map y position if on map. */ - private int mapy; - /** * Data for multitile-arches. * Stays null for singlesquare-arches. @@ -162,7 +147,6 @@ /** Create an GameObject. */ public GameObject() { - objectText = new StringBuffer(); faceobjdesc = FaceDesc.FACE_NOT_FOUND; archType = TYPE_UNSET; // type must be set script = new ScriptArchData(this); @@ -257,7 +241,7 @@ /** {@inheritDoc} */ @NotNull public String getAttributeString(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = objectText.toString(); // The "real" Archtext from arch & archetype + String aText = getObjectText(); // The "real" Archtext from arch & archetype // Add all attributes from archetype that don't already exist in aText if (queryArchetype && hasArchetype()) { aText += diffArchText(getArchetype().getObjectText(), true); @@ -279,7 +263,7 @@ /** {@inheritDoc} */ public int getAttributeInt(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = objectText.toString(); // The "real" Archtext from arch & archetype + String aText = getObjectText(); // The "real" Archtext from arch & archetype // Add all attributes from archetype that don't already exist in aText if (queryArchetype && hasArchetype()) { aText += diffArchText(getArchetype().getObjectText(), true); @@ -306,7 +290,7 @@ /** {@inheritDoc} */ public long getAttributeLong(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = objectText.toString(); + String aText = getObjectText(); // Add all attributes from archetype that don't already exist in aText if (queryArchetype && hasArchetype()) { aText += diffArchText(getArchetype().getObjectText(), true); @@ -332,7 +316,7 @@ /** {@inheritDoc} */ public double getAttributeDouble(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = objectText.toString(); + String aText = getObjectText(); // Add all attributes from archetype that don't already exist in aText if (queryArchetype && hasArchetype()) { aText += diffArchText(getArchetype().getObjectText(), true); @@ -567,39 +551,21 @@ archType = type; } - public void setMapX(final int mapx) { - this.mapx = mapx; - } - - public void setMapY(final int mapy) { - this.mapy = mapy; - } - /** {@inheritDoc} */ - @Override public int getMapX() { - return mapx; - } - - /** {@inheritDoc} */ - @Override public int getMapY() { - return mapy; - } - - /** {@inheritDoc} */ - @Override public void addLast(final GameObject arch) { - super.addLast(arch); + @Override public void addLast(@NotNull final GameObject gameObject) { + super.addLast(gameObject); // force type change when a MONSTER is put in a spawn point - if (typeList.getTypeOfArch(this) != null && typeList.getTypeOfArch(this).getTypeNr() == 81 && typeList.getTypeOfArch(arch).getTypeNr() == 80) { - arch.archType = 83; // change to SPAWN_POINT_MOB + if (typeList.getTypeOfArch(this) != null && typeList.getTypeOfArch(this).getTypeNr() == 81 && typeList.getTypeOfArch(gameObject).getTypeNr() == 80) { + gameObject.archType = 83; // change to SPAWN_POINT_MOB } } /** {@inheritDoc} */ - @Override public void addFirst(final GameObject arch) { - super.addFirst(arch); + @Override public void addFirst(@NotNull final GameObject gameObject) { + super.addFirst(gameObject); // force type change when a MONSTER is put in a spawn point - if (typeList.getTypeOfArch(this).getTypeNr() == 81 && typeList.getTypeOfArch(arch).getTypeNr() == 80) { - arch.archType = 83; // change to SPAWN_POINT_MOB + if (typeList.getTypeOfArch(this).getTypeNr() == 81 && typeList.getTypeOfArch(gameObject).getTypeNr() == 80) { + gameObject.archType = 83; // change to SPAWN_POINT_MOB } } @@ -691,33 +657,6 @@ } /** - * Append <var>text</var> to the arch text of this arch. - * @param text text to add - */ - public void addArchText(final String text) { - objectText.append(text); - } - - /** - * Set <var>text</var> as arch text of this arch. - * @param objectText text to set as arch text - */ - public void setObjectText(final String objectText) { - resetArchText(); - this.objectText.append(objectText); - } - - /** {@inheritDoc} */ - @NotNull public String getObjectText() { - return objectText.toString(); - } - - /** Clears the arch text of this arch. */ - public void resetArchText() { - objectText.delete(0, objectText.length()); - } - - /** * Get all entries from the given archtext 'atxt' that don't exist in * 'this' archtext. * @param atxt archtext to compare 'this'-arch with @@ -728,7 +667,7 @@ */ public String diffArchText(final String atxt, final boolean ignoreValues) { final StringBuilder result = new StringBuilder(); - for (String line : atxt.split("\\s*\n")) { + for (final String line : atxt.split("\\s*\n")) { if (ignoreValues) { final int spaceIndex = line.indexOf(" "); if (line.length() > 0 && spaceIndex > 0 && diffTextString(getObjectText(), line.substring(0, spaceIndex + 1), ignoreValues) == null) { @@ -943,11 +882,12 @@ } /** {@inheritDoc} */ - @Override protected GameObject clone() { + @Override @NotNull protected GameObject clone() { try { final GameObject clone = (GameObject) super.clone(); - clone.mapx = -1; - clone.mapy = -1; + clone.objectText = new StringBuffer(getObjectText()); + clone.setMapX(-1); + clone.setMapY(-1); clone.multi = null; clone.setContainer(null); return clone; @@ -969,9 +909,6 @@ final GameObject clone = clone(); // The clone is a new object! // Clone Recursion for complex types - if (objectText != null) { // Arch Text differences - clone.objectText = new StringBuffer(objectText); - } if (msgText != null) { // Message text clone.msgText = new StringBuffer(msgText); } @@ -983,8 +920,8 @@ clone.multiY = multiY; clone.script = new ScriptArchData(clone); // Script data - clone.mapx = posx; - clone.mapy = posy; + clone.setMapX(posx); + clone.setMapY(posy); for (final GameObject tmp : this) { // Inventory clone.addLast(tmp.createClone(-1, -1)); } @@ -1083,9 +1020,9 @@ final CFArchType type = archType != null ? archType : typeList.getTypeOfArch(this); - if (typeList != null && objectText != null && objectText.length() > 0) { + if (typeList != null && hasObjectText()) { final StringBuilder errors = new StringBuilder(); // return value: all error lines - for (String rawLine : objectText.toString().split("\n")) { + for (String rawLine : getObjectText().split("\n")) { final String line = rawLine.trim(); // get only the key-part of the attribute. final String attrKey = line.contains(" ") ? line.substring(0, line.indexOf(" ")) : line; Modified: trunk/daimonin/src/daieditor/map/validation/checks/SysObjectOnLayerZeroError.java =================================================================== --- trunk/daimonin/src/daieditor/map/validation/checks/SysObjectOnLayerZeroError.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/daimonin/src/daieditor/map/validation/checks/SysObjectOnLayerZeroError.java 2006-10-07 18:58:03 UTC (rev 493) @@ -43,7 +43,7 @@ /** {@inheritDoc} */ public void correct(final Component parentComponent) { // TODO: Ask user - getGameObject().addArchText("layer 0"); + getGameObject().addObjectText("layer 0"); } } // class SysObjectOnLayerZeroError Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-07 18:58:03 UTC (rev 493) @@ -11,8 +11,11 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ @SuppressWarnings({"ClassReferencesSubclass"}) -public abstract class GameObject<G extends GameObject> extends GameObjectContainer<G> { +public abstract class GameObject<G extends GameObject<G>> extends GameObjectContainer<G> { + /** Special constant that's used if an arch has no arch type set. */ + public static final int TYPE_UNSET = -666; + /** * If this flag is set, this Archetype is not a "real" Archetype but comes from the artifacts file. * Such Archetypes instances are not included in the Archetype collection process, since the artifacts file is the same for editor and server. @@ -30,9 +33,28 @@ @Nullable private GameObjectContainer<G> container; /** The Archetype of this GameObject. */ - @NotNull protected G archetype; + @NotNull private G archetype; /** + * The objectText with the differences from the Archetype. + * @note Every line in the objectText must end on '\n', including the last line. + * @note This field only is protected until the subclasses do not need it in createClone() any longer. + */ + @NotNull protected StringBuffer objectText = new StringBuffer(); + + /** Map x position if on map. */ + private int mapx; + + /** Map y position if on map. */ + private int mapy; + + /** + * Constructor. + */ + protected GameObject() { + } + + /** * Count the number of all inventory items (recursively). * The returned value does not include this GameObject. * @return number of objects in the inventory (recursively) @@ -47,12 +69,6 @@ } /** - * Returns the object text of this game object as String. - * @return the object text - */ - @NotNull public abstract String getObjectText(); - - /** * Get the requested attribute value of this GameObject as {@link String}. * The attribute value is first searched in this GameObject. * If <code>queryArchetype == true</code>, additional search is done: @@ -172,8 +188,12 @@ * <li>A MapSquare, which means that this GameObject is top level on that MapSquare.</li> * </ul> * @param container container of this GameObject. + * @throws IllegalStateException in case this GameObject is an Archetype (Archetypes must not be added to a map). */ public void setContainer(@Nullable final GameObjectContainer<G> container) { + if (isArchetype()) { + throw new IllegalStateException("Trying to set the container of an Archetype!"); + } this.container = container; } @@ -219,8 +239,8 @@ * This method also takes perfectly well care of multihead arches. */ public void remove() { - final GameObject head = getHead(); - for (GameObject tail = head.getMultiNext(); tail != null; tail = tail.getMultiNext()) { + final G head = getHead(); + for (G tail = head.getMultiNext(); tail != null; tail = tail.getMultiNext()) { if (tail.container != null) { tail.container.remove(tail); } @@ -352,7 +372,9 @@ * @return X coordinate on map * @see #getMapY() */ - public abstract int getMapX(); + public int getMapX() { + return mapx; + } /** * Get the Y coordinate of this GameObject on its map. @@ -361,9 +383,29 @@ * @return Y coordinate on map * @see #getMapX() */ - public abstract int getMapY(); + public int getMapY() { + return mapy; + } /** + * Set the X coordinate of this GameObject on its map. + * @warning Only use this method during the load process. + * @param mapx x coordinate + */ + public void setMapX(final int mapx) { + this.mapx = mapx; + } + + /** + * Set the Y coordinate of this GameObject on its map. + * @warning Only use this method during the load process. + * @param mapy y coordinate + */ + public void setMapY(final int mapy) { + this.mapy = mapy; + } + + /** * Create a new GameObject from this Archetype. * If this GameObject is not an Archetype, this method recursively forwards to its Archetype. * This means that the newly created GameObject will not reflect any differences / attributes specific to this GameObject. @@ -382,4 +424,54 @@ @Nullable public abstract G getMultiNext(); + /** {@inheritDoc} */ + @Override @NotNull protected GameObject<G> clone() throws CloneNotSupportedException { + try { + final GameObject<G> clone = (GameObject<G>) super.clone(); + clone.objectText = new StringBuffer(getObjectText()); + return clone; + } catch (final CloneNotSupportedException e) { + assert false; + throw new AssertionError(); + } + } + + /** + * Returns the object text of this GameObject as String. + * @return the object text + */ + @NotNull public String getObjectText() { + return objectText.toString(); + } + + /** + * Returns whether this GameObject has a set object text. + * @return <code>true</code> if this GameObject has a set object text, otherwise <code>false</code>. + */ + public boolean hasObjectText() { + return objectText.length() > 0; + } + + /** + * Append <var>text</var> to the object text of this GameObject. + * @param text text to add + */ + public void addObjectText(final String text) { + objectText.append(text); + } + + /** Clears the object text of this GameObject. */ + public void resetObjectText() { + objectText.delete(0, objectText.length()); + } + + /** + * Set <var>objectText</var> as object text of this GameObject. + * @param objectText text to set as object text + */ + public void setObjectText(final String objectText) { + resetObjectText(); + this.objectText.append(objectText); + } + } // interface GameObject Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObjectContainer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObjectContainer.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObjectContainer.java 2006-10-07 18:58:03 UTC (rev 493) @@ -43,7 +43,7 @@ * @todo: In case of MapSquares, this class is most likely bogus regarding multipart objects. This needs to be fixed. */ @SuppressWarnings({"ClassReferencesSubclass"}) -public abstract class GameObjectContainer<G extends GameObject> implements Iterable<G>, Serializable { +public abstract class GameObjectContainer<G extends GameObject<G>> implements Iterable<G>, Serializable { /** Serial Version. */ private static final long serialVersionUID = 1L; Modified: trunk/src/app/net/sf/gridarta/map/MapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapModel.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/src/app/net/sf/gridarta/map/MapModel.java 2006-10-07 18:58:03 UTC (rev 493) @@ -10,7 +10,7 @@ * A MapModel reflects the data of a map. * This MapModel interface covers the similarities between the current CFEditor and DaiEditor implementations. */ -public interface MapModel<G extends GameObject> extends Iterable<MapSquare<G>> { +public interface MapModel<G extends GameObject<G>> extends Iterable<MapSquare<G>> { /** * Return the map size of this level. Modified: trunk/src/app/net/sf/gridarta/map/MapSquare.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapSquare.java 2006-10-07 17:25:26 UTC (rev 492) +++ trunk/src/app/net/sf/gridarta/map/MapSquare.java 2006-10-07 18:58:03 UTC (rev 493) @@ -40,7 +40,7 @@ * * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public class MapSquare<G extends GameObject> extends GameObjectContainer<G> { +public class MapSquare<G extends GameObject<G>> extends GameObjectContainer<G> { /** The MaoModel this square is associated with. */ @NotNull private final MapModel model; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-08 15:22:27
|
Revision: 494 http://svn.sourceforge.net/gridarta/?rev=494&view=rev Author: christianhujer Date: 2006-10-08 08:22:05 -0700 (Sun, 08 Oct 2006) Log Message: ----------- Unified GameObject regarding attribute cache, multiX and multiY. Added exceptions that are thrown in case of wrong GameObject usage. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gameobject/IsArchetypeException.java trunk/src/app/net/sf/gridarta/gameobject/NotInsideContainerException.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-07 18:58:03 UTC (rev 493) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-08 15:22:05 UTC (rev 494) @@ -35,7 +35,6 @@ import java.io.IOException; import java.io.StringReader; import java.util.Collections; -import java.util.HashMap; import java.util.List; import javax.swing.JList; import org.apache.log4j.Logger; @@ -88,18 +87,6 @@ @Nullable private MultiArchData multi = null; /** - * The x-distance of this part to the head part. Set to zero for - * single-part objects. - */ - private int multiX = 0; - - /** - * The y-distance of this part to the head part. Set to zero for - * single-part objects. - */ - private int multiY = 0; - - /** * Data for scripted events. * Stays null if no events defined. */ @@ -124,8 +111,6 @@ private AutojoinList join; // if nonzero, pointing to the list of autojoining archetypes - private final HashMap<String, String> cachedAttribute = new HashMap<String, String>(); - /** Create an GameObject. */ public GameObject() { setArchetype(this); @@ -235,133 +220,6 @@ return editType; } - /** {@inheritDoc} */ - @NotNull public String getAttributeString(@NotNull String attributeName, final boolean queryArchetype) { - String aText = getObjectText(); - int j; - attributeName = attributeName.trim() + " "; // attributeName must be followed by space - String result = ""; - if (queryArchetype) { - result = getCachedAttributeValue(attributeName); - if (result != null) { - return result; - } - result = ""; - } - // Add all attributes from archetype that don't already exist in aText - if (queryArchetype && hasArchetype()) { - aText = aText + diffArchText(getArchetype().getObjectText(), true); - } - - if (!aText.endsWith("\n")) { - aText = aText.concat("\n"); // string should end with '\n', see below - } - - // Check line by line for the string 'attributeName' - int i; - for (i = 0, j = 0; i < aText.length(); i++) { - if (aText.charAt(i) == '\n') { - final String line = aText.substring(j, i).trim(); - - // take the String behind 'attributeName' - if (line.startsWith(attributeName)) { - result = line.substring(attributeName.length()).trim(); - } - - j = i + 1; - } - } - if (queryArchetype) { - setCachedAttributeValue(attributeName, result); - } - - return result; - } - - /** {@inheritDoc} */ - @NotNull public String getAttributeString(@NotNull final String attributeName) { - return getAttributeString(attributeName, true); - } - - /** {@inheritDoc} */ - public int getAttributeInt(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = getObjectText(); - // Add all attributes from archetype that don't already exist in aText - if (queryArchetype && hasArchetype()) { - aText += diffArchText(getArchetype().getObjectText(), true); - } - assert aText.endsWith("\n"); - final String attr2 = attributeName.trim() + ' '; - int result = 0; - for (final String line : aText.split("\\s*\n")) { - if (line.startsWith(attr2)) { - try { - result = Integer.parseInt(line.substring(attr2.length()).trim()); - } catch (final NumberFormatException e) { - result = 0; - } - } - } - return result; - } - - /** {@inheritDoc} */ - public int getAttributeInt(@NotNull final String attributeName) { - return getAttributeInt(attributeName, true); - } - - /** {@inheritDoc} */ - public long getAttributeLong(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = getObjectText(); - // Add all attributes from archetype that don't already exist in aText - if (queryArchetype && hasArchetype()) { - aText += diffArchText(getArchetype().getObjectText(), true); - } - final String attr2 = attributeName.trim() + ' '; - long result = 0; - for (final String line : aText.split("\\s*\n")) { - if (line.startsWith(attr2)) { - try { - result = Long.parseLong(line.substring(attr2.length())); - } catch (final NumberFormatException e) { - result = 0; - } - } - } - return result; - } - - /** {@inheritDoc} */ - public long getAttributeLong(@NotNull final String attributeName) { - return getAttributeLong(attributeName, true); - } - - /** {@inheritDoc} */ - public double getAttributeDouble(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = getObjectText(); - // Add all attributes from archetype that don't already exist in aText - if (queryArchetype && hasArchetype()) { - aText += diffArchText(getArchetype().getObjectText(), true); - } - final String attr2 = attributeName.trim() + ' '; - double result = 0; - for (String line : aText.split("\\s*\n")) { - if (line.startsWith(attr2)) { - try { - result = Double.parseDouble(line.substring(attr2.length())); - } catch (final NumberFormatException e) { - result = 0; - } - } - } - return result; - } - - /** {@inheritDoc} */ - public double getAttributeDouble(@NotNull final String attributeName) { - return getAttributeDouble(attributeName, true); - } - /** * Set the String of an arch attribute in the objectText. * @param attributeName search for "attributeName <string>" @@ -584,46 +442,6 @@ } /** - * Set the x-position of this part of a multi-part object. The x-position - * is relative to the head part. - * - * @param multiX the x-distance of this part to the head part - */ - public void setMultiX(final int multiX) { - this.multiX = multiX; - } - - /** - * Set the y-position of this part of a multi-part object. The y-position - * is relative to the head part. - * - * @param multiY the y-distance of this part to the head part - */ - public void setMultiY(final int multiY) { - this.multiY = multiY; - } - - /** - * Get the x-distance of this part to the head part. For single-part - * objects this is always zero. - * - * @return the x-distance of this part to the head part - */ - public int getMultiX() { - return multiX; - } - - /** - * Get the y-distance of this part to the head part. For single-part - * objects this is always zero. - * - * @return the y-distance of this part to the head part - */ - public int getMultiY() { - return multiY; - } - - /** * Returns number of parts for multipart heads. (*.getMultiRefCount() > 0) * is often used as way to find multi-heads. * @return number of parts @@ -727,22 +545,11 @@ return faceName; } - /** {@inheritDoc} */ - public void setObjectText(final String objectText) { - super.setObjectText(objectText); - clearCachedAttributeValue(); - } - /** - * Get all entries from the given archtext 'atxt' that don't exist in - * 'this' archtext. - * @param atxt archtext to compare 'this'-arch with - * @param ignoreValues if true: the values in the archtext-entries are - * ignored at the comparison - * @return all lines from 'atxt' that don't occur in 'this' arch + * {@inheritDoc} * @todo this method is too slow - find a faster way */ - public String diffArchText(String atxt, final boolean ignoreValues) { + @NotNull public String diffArchText(@NotNull String atxt, final boolean ignoreValues) { int j; if (!atxt.endsWith("\n")) { @@ -1207,20 +1014,4 @@ return arch; } - private void setCachedAttributeValue(final String name, final String value) { - cachedAttribute.put(name, value); - } - - private void unSetCachedAttributeValue(final String name) { - cachedAttribute.remove(name); - } - - private void clearCachedAttributeValue() { - cachedAttribute.clear(); - } - - private String getCachedAttributeValue(final String name) { - return cachedAttribute.get(name); - } - } // class GameObject Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-07 18:58:03 UTC (rev 493) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-08 15:22:05 UTC (rev 494) @@ -91,18 +91,6 @@ */ @Nullable private MultiArchData multi = null; - /** - * The x-distance of this part to the head part. Set to zero for - * single-part objects. - */ - private int multiX = 0; - - /** - * The y-distance of this part to the head part. Set to zero for - * single-part objects. - */ - private int multiY = 0; - private int multiPartNr = 0; /** @@ -239,107 +227,6 @@ return editType; } - /** {@inheritDoc} */ - @NotNull public String getAttributeString(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = getObjectText(); // The "real" Archtext from arch & archetype - // Add all attributes from archetype that don't already exist in aText - if (queryArchetype && hasArchetype()) { - aText += diffArchText(getArchetype().getObjectText(), true); - } - final String attr2 = attributeName.trim() + ' '; // attributeName must be followed by space - String result = ""; // returned String - for (final String line : aText.split("\\s*\n")) { - if (line.startsWith(attr2)) { - result = line.substring(attr2.length()); - } - } - return result; - } - - /** {@inheritDoc} */ - @NotNull public String getAttributeString(@NotNull final String attributeName) { - return getAttributeString(attributeName, true); - } - - /** {@inheritDoc} */ - public int getAttributeInt(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = getObjectText(); // The "real" Archtext from arch & archetype - // Add all attributes from archetype that don't already exist in aText - if (queryArchetype && hasArchetype()) { - aText += diffArchText(getArchetype().getObjectText(), true); - } - assert aText.endsWith("\n"); - final String attr2 = attributeName.trim() + ' '; - int result = 0; - for (final String line : aText.split("\\s*\n")) { - if (line.startsWith(attr2)) { - try { - result = Integer.parseInt(line.substring(attr2.length()).trim()); - } catch (final NumberFormatException e) { - result = 0; - } - } - } - return result; - } - - /** {@inheritDoc} */ - public int getAttributeInt(@NotNull final String attributeName) { - return getAttributeInt(attributeName, true); - } - - /** {@inheritDoc} */ - public long getAttributeLong(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = getObjectText(); - // Add all attributes from archetype that don't already exist in aText - if (queryArchetype && hasArchetype()) { - aText += diffArchText(getArchetype().getObjectText(), true); - } - final String attr2 = attributeName.trim() + ' '; - long result = 0; - for (final String line : aText.split("\\s*\n")) { - if (line.startsWith(attr2)) { - try { - result = Long.parseLong(line.substring(attr2.length())); - } catch (final NumberFormatException e) { - result = 0; - } - } - } - return result; - } - - /** {@inheritDoc} */ - public long getAttributeLong(@NotNull final String attributeName) { - return getAttributeLong(attributeName, true); - } - - /** {@inheritDoc} */ - public double getAttributeDouble(@NotNull final String attributeName, final boolean queryArchetype) { - String aText = getObjectText(); - // Add all attributes from archetype that don't already exist in aText - if (queryArchetype && hasArchetype()) { - aText += diffArchText(getArchetype().getObjectText(), true); - } - final String attr2 = attributeName.trim() + ' '; - double result = 0; - for (String line : aText.split("\\s*\n")) { - if (line.startsWith(attr2)) { - try { - result = Double.parseDouble(line.substring(attr2.length())); - } catch (final NumberFormatException e) { - result = 0; - } - } - } - return result; - } - - /** {@inheritDoc} */ - public double getAttributeDouble(@NotNull final String attributeName) { - return getAttributeDouble(attributeName, true); - } - /** * Insert a GameObject before this GameObject. * @param node GameObject to append @@ -456,26 +343,6 @@ return multi != null ? multi.getNext(this) : null; } - /** - * Set the x-position of this part of a multi-part object. The x-position - * is relative to the head part. - * - * @param multiX the x-distance of this part to the head part - */ - public void setMultiX(final int multiX) { - this.multiX = multiX; - } - - /** - * Set the y-position of this part of a multi-part object. The y-position - * is relative to the head part. - * - * @param multiY the y-distance of this part to the head part - */ - public void setMultiY(final int multiY) { - this.multiY = multiY; - } - public int getMultiShapeID() { return multi != null ? multi.getMultiShapeID() : 0; } @@ -502,26 +369,6 @@ } /** - * Get the x-distance of this part to the head part. For single-part - * objects this is always zero. - * - * @return the x-distance of this part to the head part - */ - public int getMultiX() { - return multiX; - } - - /** - * Get the y-distance of this part to the head part. For single-part - * objects this is always zero. - * - * @return the y-distance of this part to the head part - */ - public int getMultiY() { - return multiY; - } - - /** * Returns number of parts for multipart heads. (*.getMultiRefCount() > 0) * is often used as way to find multi-heads. * @return number of parts @@ -657,15 +504,10 @@ } /** - * Get all entries from the given archtext 'atxt' that don't exist in - * 'this' archtext. - * @param atxt archtext to compare 'this'-arch with - * @param ignoreValues if true: the values in the archtext-entries are - * ignored at the comparison - * @return all lines from 'atxt' that don't occur in 'this' arch + * {@inheritDoc} * @todo this method is too slow - find a faster way */ - public String diffArchText(final String atxt, final boolean ignoreValues) { + @NotNull public String diffArchText(@NotNull final String atxt, final boolean ignoreValues) { final StringBuilder result = new StringBuilder(); for (final String line : atxt.split("\\s*\n")) { if (ignoreValues) { @@ -1076,11 +918,11 @@ final GameObject arch = new GameObject(); arch.setArchetypeName(archetypeName); arch.setArchetype(this); - arch.setObjectFace(); arch.setMultiX(multiX); arch.setMultiY(multiY); - arch.setMultiPartNr(multiPartNr); arch.setLowestPart(isLowestPart); + arch.setMultiPartNr(multiPartNr); + arch.setObjectFace(); return arch; } Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-07 18:58:03 UTC (rev 493) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-08 15:22:05 UTC (rev 494) @@ -3,6 +3,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import net.sf.gridarta.map.MapSquare; +import java.util.HashMap; +import java.util.Map; /** * A GameObject instance reflects a GameObject (object on a map) or an Archetype. @@ -13,7 +15,7 @@ @SuppressWarnings({"ClassReferencesSubclass"}) public abstract class GameObject<G extends GameObject<G>> extends GameObjectContainer<G> { - /** Special constant that's used if an arch has no arch type set. */ + /** Special constant that's used if a GameObject has no arch type set. */ public static final int TYPE_UNSET = -666; /** @@ -49,6 +51,25 @@ private int mapy; /** + * Map which caches attributes for faster access. + * Key: attribute name + * value: attribute value + */ + protected Map<String, String> attributeCache = new HashMap<String, String>(); + + /** + * The x-distance of this part to the head part. Set to zero for + * single-part objects. + */ + protected int multiX = 0; + + /** + * The y-distance of this part to the head part. Set to zero for + * single-part objects. + */ + protected int multiY = 0; + + /** * Constructor. */ protected GameObject() { @@ -61,14 +82,55 @@ */ public int countInvObjects() { int count = 0; - for (final GameObject arch : this) { + for (final GameObject gameObject : this) { count++; - count += arch.countInvObjects(); + count += gameObject.countInvObjects(); } return count; } /** + * Get the requested attribute value from the cache. + * @param attributeName Name of the attribute to search. + * @return cached attribute value from the cache or <code>null</code> if not found + */ + @Nullable private String getCachedAttributeValue(@NotNull final String attributeName) { + return attributeCache.get(attributeName); + } + + /** + * Puts an attribute name / value pair in the cache. + * @param attributeName Name of the attribute to cache. + * @param value Value of the attribute to cache + */ + private void cacheAttributeValue(@NotNull final String attributeName, @NotNull final String value) { + attributeCache.put(attributeName, value); + } + + /** + * Clears the attribute cache. + */ + private void clearAttributeCache() { + attributeCache.clear(); + } + + /** + * Get the requested attribute value from the objectText. + * @param attributeName Name of the attribute to search. + * @return attribute value from the objectText or <code>null</code> if not found + */ + @Nullable private String getAttributeValue(@NotNull final String attributeName) { + final String attr2 = attributeName.trim() + ' '; + String result = null; + for (final String line : getObjectText().split("\\s*\n")) { + if (line.startsWith(attr2)) { + result = line.substring(attr2.length()); + break; + } + } + return result; + } + /** * Get the requested attribute value of this GameObject as {@link String}. * The attribute value is first searched in this GameObject. * If <code>queryArchetype == true</code>, additional search is done: @@ -83,7 +145,22 @@ * @return Attribute value or empty String ("") if no such attribute * @see #getAttributeString(String) */ - @NotNull public abstract String getAttributeString(@NotNull String attributeName, boolean queryArchetype); + @NotNull public String getAttributeString(@NotNull final String attributeName, final boolean queryArchetype) { + String result = getCachedAttributeValue(attributeName); + if (result == null) { + result = getAttributeValue(attributeName); + } + if (result == null) { + if (!queryArchetype || isArchetype() || !hasArchetype()) { + result = ""; + } else { + result = getArchetype().getAttributeString(attributeName); + } + } else { + cacheAttributeValue(attributeName, result); + } + return result; + } /** * Get the requested attribute value of this GameObject as {@link String}. @@ -96,7 +173,9 @@ * @return Attribute value or empty String ("") if no such attribute * @see #getAttributeString(String, boolean) */ - @NotNull public abstract String getAttributeString(@NotNull String attributeName); + @NotNull public String getAttributeString(@NotNull final String attributeName) { + return getAttributeString(attributeName, true); + } /** * Get the requested attribute value of this GameObject as <code>int</code>. @@ -106,7 +185,15 @@ * @see #getAttributeInt(String) * @see #getAttributeString(String, boolean) */ - public abstract int getAttributeInt(@NotNull String attributeName, boolean queryArchetype); + public int getAttributeInt(@NotNull final String attributeName, final boolean queryArchetype) { + int result = 0; + try { + result = Integer.parseInt(getAttributeString(attributeName, queryArchetype)); + } catch (final NumberFormatException ignore) { + // ignore + } + return result; + } /** * Get the requested attribute value of this GameObject as <code>int</code>. @@ -115,7 +202,9 @@ * @see #getAttributeInt(String, boolean) * @see #getAttributeString(String) */ - public abstract int getAttributeInt(@NotNull String attributeName); + public int getAttributeInt(@NotNull final String attributeName) { + return getAttributeInt(attributeName, true); + } /** * Get the requested attribute value of this GameObject as <code>long</code>. @@ -125,7 +214,15 @@ * @see #getAttributeLong(String) * @see #getAttributeString(String, boolean) */ - public abstract long getAttributeLong(@NotNull String attributeName, boolean queryArchetype); + public long getAttributeLong(@NotNull final String attributeName, final boolean queryArchetype) { + long result = 0; + try { + result = Long.parseLong(getAttributeString(attributeName, queryArchetype)); + } catch (final NumberFormatException ignore) { + // ignore + } + return result; + } /** * Get the requested attribute value of this GameObject as <code>long</code>. @@ -134,7 +231,9 @@ * @see #getAttributeLong(String, boolean) * @see #getAttributeString(String) */ - public abstract long getAttributeLong(@NotNull String attributeName); + public long getAttributeLong(@NotNull final String attributeName) { + return getAttributeLong(attributeName, true); + } /** * Get the requested attribute value of this GameObject as <code>double</code>. @@ -144,7 +243,15 @@ * @see #getAttributeDouble(String) * @see #getAttributeString(String, boolean) */ - public abstract double getAttributeDouble(@NotNull String attributeName, boolean queryArchetype); + public double getAttributeDouble(@NotNull final String attributeName, final boolean queryArchetype) { + double result = 0; + try { + result = Double.parseDouble(getAttributeString(attributeName, queryArchetype)); + } catch (final NumberFormatException ignore) { + // ignore + } + return result; + } /** * Get the requested attribute value of this GameObject as <code>double</code>. @@ -153,9 +260,21 @@ * @see #getAttributeDouble(String, boolean) * @see #getAttributeString(String) */ - public abstract double getAttributeDouble(@NotNull String attributeName); + public double getAttributeDouble(@NotNull final String attributeName) { + return getAttributeDouble(attributeName, true); + } /** + * Get all entries from the given archtext 'atxt' that don't exist in + * 'this' archtext. + * @param atxt archtext to compare 'this'-arch with + * @param ignoreValues if true: the values in the archtext-entries are + * ignored at the comparison + * @return all lines from 'atxt' that don't occur in 'this' arch + */ + @NotNull public abstract String diffArchText(@NotNull String atxt, boolean ignoreValues); + + /** * Returns container of this GameObject. * There are two possibilities for the container: * <ul> @@ -213,41 +332,88 @@ return container != null ? container.getMapSquare() : null; } - /** Move this GameObject top. */ + // TODO: For the following set of methods add logging that it was tried to move a GameObject without container. + // TODO (continued): Eventually think about using an Exception for that case. + // TODO (continued): Or two: + // TODO (continued): * One in case a non-Archetype method was invoked on an Archetype. + // TODO (continued): * The other in case a method that requires a container was invoked on a GameObject without container. + + /** + * Move this GameObject top. + * Does nothing if the object has no container. + */ public void moveTop() { + if (isArchetype()) { + throw new IsArchetypeException(this); + } + if (container == null) { + throw new NotInsideContainerException(this); + } container.moveTop((G) this); } - /** Move this GameObject up. */ + /** + * Move this GameObject up. + * Does nothing if the object has no container. + */ public void moveUp() { + if (isArchetype()) { + throw new IsArchetypeException(this); + } + if (container == null) { + throw new NotInsideContainerException(this); + } container.moveUp((G) this); } - /** Move this GameObject down. */ + /** + * Move this GameObject down. + * Does nothing if the object has no container. + */ public void moveDown() { + if (isArchetype()) { + throw new IsArchetypeException(this); + } + if (container == null) { + throw new NotInsideContainerException(this); + } container.moveDown((G) this); } - /** Move this GameObject bottom. */ + /** + * Move this GameObject bottom. + * Does nothing if the object has no container. + */ public void moveBottom() { + if (isArchetype()) { + throw new IsArchetypeException(this); + } + if (container == null) { + throw new NotInsideContainerException(this); + } container.moveBottom((G) this); } /** - * Remove this GameObject from its container. Do nothing if the object is - * not inside a container. - * This method also takes perfectly well care of multihead arches. + * Remove this GameObject from its container. + * Does nothing if the object has no container. + * This method also takes perfectly well care of multihead GameObjects. */ public void remove() { + if (isArchetype()) { + throw new IsArchetypeException(this); + } final G head = getHead(); for (G tail = head.getMultiNext(); tail != null; tail = tail.getMultiNext()) { - if (tail.container != null) { - tail.container.remove(tail); + if (tail.container == null) { + throw new NotInsideContainerException(this); } + tail.container.remove(tail); } - if (head.container != null) { - head.container.remove(head); + if (head.container == null) { + throw new NotInsideContainerException(this); } + head.container.remove(head); } /** @@ -276,8 +442,8 @@ /** * Check whether this GameObject has an Archetype. - * @return <code>true</code> when this GameObject has a default arch or is - * a default arch itself, otherwise <code>false</code> + * @return <code>true</code> when this GameObject has an Archetype or is + * an Archetype itself, otherwise <code>false</code> */ public boolean hasArchetype() { return archetype != null; @@ -301,10 +467,10 @@ } /** - * Check whether this GameObject has the same default arch as another + * Check whether this GameObject has the same Archetype as another * GameObject. * @param other other GameObject - * @return <code>true</code> when this GameObject has the same default arch + * @return <code>true</code> when this GameObject has the same Archetype * as the other GameObject, otherwise <code>false</code> */ public boolean hasSameArchetype(final G other) { @@ -424,11 +590,17 @@ @Nullable public abstract G getMultiNext(); - /** {@inheritDoc} */ + /** + * {@inheritDoc} + * Implementations must not provide substitute clones of a different class. + * I.e. implementations MUST return an object created by super.clone() or their own constructor. + * Implementations MUST NOT return an object created from a different class. + */ @Override @NotNull protected GameObject<G> clone() throws CloneNotSupportedException { try { final GameObject<G> clone = (GameObject<G>) super.clone(); clone.objectText = new StringBuffer(getObjectText()); + clone.attributeCache = new HashMap<String, String>(attributeCache); return clone; } catch (final CloneNotSupportedException e) { assert false; @@ -472,6 +644,47 @@ public void setObjectText(final String objectText) { resetObjectText(); this.objectText.append(objectText); + clearAttributeCache(); } + /** + * Set the x-position of this part of a multi-part object. The x-position + * is relative to the head part. + * + * @param multiX the x-distance of this part to the head part + */ + public void setMultiX(final int multiX) { + this.multiX = multiX; + } + + /** + * Set the y-position of this part of a multi-part object. The y-position + * is relative to the head part. + * + * @param multiY the y-distance of this part to the head part + */ + public void setMultiY(final int multiY) { + this.multiY = multiY; + } + + /** + * Get the x-distance of this part to the head part. For single-part + * objects this is always zero. + * + * @return the x-distance of this part to the head part + */ + public int getMultiX() { + return multiX; + } + + /** + * Get the y-distance of this part to the head part. For single-part + * objects this is always zero. + * + * @return the y-distance of this part to the head part + */ + public int getMultiY() { + return multiY; + } + } // interface GameObject Added: trunk/src/app/net/sf/gridarta/gameobject/IsArchetypeException.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/IsArchetypeException.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/IsArchetypeException.java 2006-10-08 15:22:05 UTC (rev 494) @@ -0,0 +1,33 @@ +package net.sf.gridarta.gameobject; + +import org.jetbrains.annotations.NotNull; + +/** + * This exception is thrown in case a method of {@link GameObject} was invoked that must not be used for GameObjects which are Archetypes. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class IsArchetypeException extends IllegalStateException { + + /** + * The GameObject that is an Archetype. + */ + @NotNull private final GameObject archetype; + + /** + * Create an IsArchetypeException. + * @param archetype The GameObject that is an Archetype. + */ + public IsArchetypeException(@NotNull final GameObject archetype) { + super(archetype.toString()); + this.archetype = archetype; + } + + /** + * Returns the GameObject that is an Archetype. + * @return The GameObject that is an Archetype. + */ + @NotNull public GameObject getArchetype() { + return archetype; + } + +} // class IsArchetypeException Property changes on: trunk/src/app/net/sf/gridarta/gameobject/IsArchetypeException.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: trunk/src/app/net/sf/gridarta/gameobject/NotInsideContainerException.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/NotInsideContainerException.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/NotInsideContainerException.java 2006-10-08 15:22:05 UTC (rev 494) @@ -0,0 +1,33 @@ +package net.sf.gridarta.gameobject; + +import org.jetbrains.annotations.NotNull; + +/** + * This exception is thrown in case a method of a {@link GameObject} without a container was invoked when a GameObject requires a container. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class NotInsideContainerException extends IllegalStateException { + + /** + * The GameObject that was not inside a container but should have been. + */ + @NotNull private final GameObject gameObject; + + /** + * Create a NotInsideContainerException. + * @param gameObject GameObject that was not inside a container but should have been. + */ + public NotInsideContainerException(@NotNull final GameObject gameObject) { + super(gameObject.toString()); + this.gameObject = gameObject; + } + + /** + * Returns the GameObject that was not inside a container but should have been. + * @return The GameObject that was not inside a container but should have been. + */ + @NotNull public GameObject getGameObject() { + return gameObject; + } + +} // class NotInsideContainerException Property changes on: trunk/src/app/net/sf/gridarta/gameobject/NotInsideContainerException.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-08 19:26:32
|
Revision: 499 http://svn.sourceforge.net/gridarta/?rev=499&view=rev Author: christianhujer Date: 2006-10-08 12:26:22 -0700 (Sun, 08 Oct 2006) Log Message: ----------- Minor improvements on ArchetypeSet implementations: No need to redirect Archetype queries to CMainControl - we ARE the ArchetypeSet. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-08 19:04:27 UTC (rev 498) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-08 19:26:22 UTC (rev 499) @@ -534,7 +534,7 @@ CMainStatusbar.getInstance().setText("Collect Archfile: write archetypes"); // open the process bar - final CollectProgressBar pbar = new CollectProgressBar(mainControl.getArchetypeSet().getArchetypeCount(), + final CollectProgressBar pbar = new CollectProgressBar(getArchetypeCount(), "Collecting Archetypes..."); File dfile; @@ -570,7 +570,7 @@ // process every arch in this panel for (int i = 0; i < numList.length; i++) { - archetype = mainControl.getArchetype(numList[i]); + archetype = getArchetype(numList[i]); if (archetype.isTail()) { log.error("Collect Error: Multipart Tail in Panel found!"); @@ -648,7 +648,7 @@ } // finally we need to get the "map"-arch, which is not in the panels - final GameObject maparch = mainControl.getArchetype(ArchObjectParser.STARTARCH_NAME); + final GameObject maparch = getArchetype(ArchObjectParser.STARTARCH_NAME); if (maparch != null) { count++; Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-08 19:04:27 UTC (rev 498) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-08 19:26:22 UTC (rev 499) @@ -473,7 +473,7 @@ */ /** {@inheritDoc} */ public void run() { - final Progress pbar = new ProgressDisplay(mainControl.getMainView(), ""/*FIXME*/, mainControl.getArchetypeSet().getArchetypeCount(), ACTION_FACTORY.getString("archCollectArches")); + final Progress pbar = new ProgressDisplay(mainControl.getMainView(), ""/*FIXME*/, getArchetypeCount(), ACTION_FACTORY.getString("archCollectArches")); collectDaimoninArchetypes(pbar); collectDaimoninAnimations(pbar); collectDaimoninAnimationTree(pbar); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-08 19:45:39
|
Revision: 501 http://svn.sourceforge.net/gridarta/?rev=501&view=rev Author: christianhujer Date: 2006-10-08 12:45:30 -0700 (Sun, 08 Oct 2006) Log Message: ----------- Cosmetic. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainView.java trunk/daimonin/src/daieditor/CMainView.java Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-10-08 19:40:41 UTC (rev 500) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-10-08 19:45:30 UTC (rev 501) @@ -359,7 +359,6 @@ public void disableTabPane() { archPanel.disableTabPane(); - } public void enableTabPane() { Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-10-08 19:40:41 UTC (rev 500) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-10-08 19:45:30 UTC (rev 501) @@ -24,7 +24,6 @@ package daieditor; -import daieditor.gameobject.ArchetypeSet; import daieditor.gameobject.GameObject; import daieditor.gui.AboutDialog; import daieditor.map.MapControl; @@ -366,7 +365,6 @@ public void disableTabPane() { archPanel.disableTabPane(); - } public void enableTabPane() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-08 21:50:26
|
Revision: 502 http://svn.sourceforge.net/gridarta/?rev=502&view=rev Author: christianhujer Date: 2006-10-08 14:50:03 -0700 (Sun, 08 Oct 2006) Log Message: ----------- Some MainControl unification regarding arch/gui handling. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CArchPanel.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/CArchPanel.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/src/app/net/sf/gridarta/MainControl.java Modified: trunk/crossfire/src/cfeditor/CArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanel.java 2006-10-08 19:45:30 UTC (rev 501) +++ trunk/crossfire/src/cfeditor/CArchPanel.java 2006-10-08 21:50:03 UTC (rev 502) @@ -163,13 +163,13 @@ selectedPanel.addArchPanelArch(archname, index); } - public void disableTabPane() { - tabDesktop.setEnabled(false); - } - - public void enableTabPane() { - tabDesktop.setEnabled(true); - if (selectedPanel != null) { + /** + * Sets the enabled state of the tab pane for Archetypes. + * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it. + */ + public void setTabPaneEnabled(final boolean tabPaneEnabled) { + tabDesktop.setEnabled(tabPaneEnabled); + if (tabPaneEnabled && selectedPanel != null) { selectedPanel.showArchList(); } } Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-08 19:45:30 UTC (rev 501) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-08 21:50:03 UTC (rev 502) @@ -521,18 +521,17 @@ return mainView; } + /** {@inheritDoc} */ + @Deprecated public void setTabPaneEnabled(final boolean tabPaneEnabled) { + mainView.setTabPaneEnabled(tabPaneEnabled); + } + + /** {@inheritDoc} */ public void addArchPanel(final String name) { mainView.addArchPanel(name); } - public void disableTabPane() { - mainView.disableTabPane(); - } - - public void enableTabPane() { - mainView.enableTabPane(); - } - + /** {@inheritDoc} */ public int addArchPanelCombo(final String name) { return mainView.addArchPanelCombo(name); } Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-10-08 19:45:30 UTC (rev 501) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-10-08 21:50:03 UTC (rev 502) @@ -357,14 +357,14 @@ archPanel.addPanel(name); } - public void disableTabPane() { - archPanel.disableTabPane(); + /** + * Sets the enabled state of the tab pane for Archetypes. + * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it. + */ + public void setTabPaneEnabled(final boolean tabPaneEnabled) { + archPanel.setTabPaneEnabled(tabPaneEnabled); } - public void enableTabPane() { - archPanel.enableTabPane(); - } - public int addArchPanelCombo(final String name) { return archPanel.addArchPanelCombo(name); } Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-08 19:45:30 UTC (rev 501) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-08 21:50:03 UTC (rev 502) @@ -137,7 +137,7 @@ // load object from a arch file you found final File f = new File(mainControl.getArchDefaultFolder()); folderLevel = 0; - mainControl.disableTabPane(); + mainControl.setTabPaneEnabled(false); // here we go... if (mainControl.isArchLoadedFromCollection()) { @@ -148,7 +148,7 @@ CMainStatusbar.getInstance().setText(" Sorting..."); connectFaces(); // attach faces to arches - mainControl.enableTabPane(); + mainControl.setTabPaneEnabled(true); mainControl.getMainView().finishArchPanelBuildProccess(); System.gc(); Modified: trunk/daimonin/src/daieditor/CArchPanel.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanel.java 2006-10-08 19:45:30 UTC (rev 501) +++ trunk/daimonin/src/daieditor/CArchPanel.java 2006-10-08 21:50:03 UTC (rev 502) @@ -148,13 +148,13 @@ selectedPanel.addArchPanelArch(archname, index); } - public void disableTabPane() { - tabDesktop.setEnabled(false); - } - - public void enableTabPane() { - tabDesktop.setEnabled(true); - if (selectedPanel != null) { + /** + * Sets the enabled state of the tab pane for Archetypes. + * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it. + */ + public void setTabPaneEnabled(final boolean tabPaneEnabled) { + tabDesktop.setEnabled(tabPaneEnabled); + if (tabPaneEnabled && selectedPanel != null) { selectedPanel.showArchList(); } } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-10-08 19:45:30 UTC (rev 501) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-10-08 21:50:03 UTC (rev 502) @@ -795,18 +795,17 @@ return mainView; } + /** {@inheritDoc} */ + @Deprecated public void setTabPaneEnabled(final boolean tabPaneEnabled) { + mainView.setTabPaneEnabled(tabPaneEnabled); + } + + /** {@inheritDoc} */ public void addArchPanel(final String name) { mainView.addArchPanel(name); } - public void disableTabPane() { - mainView.disableTabPane(); - } - - public void enableTabPane() { - mainView.enableTabPane(); - } - + /** {@inheritDoc} */ public int addArchPanelCombo(final String name) { return mainView.addArchPanelCombo(name); } Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-10-08 19:45:30 UTC (rev 501) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-10-08 21:50:03 UTC (rev 502) @@ -363,14 +363,14 @@ archPanel.addPanel(name); } - public void disableTabPane() { - archPanel.disableTabPane(); + /** + * Sets the enabled state of the tab pane for Archetypes. + * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it. + */ + public void setTabPaneEnabled(final boolean tabPaneEnabled) { + archPanel.setTabPaneEnabled(tabPaneEnabled); } - public void enableTabPane() { - archPanel.enableTabPane(); - } - public int addArchPanelCombo(final String name) { return archPanel.addArchPanelCombo(name); } Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-08 19:45:30 UTC (rev 501) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-08 21:50:03 UTC (rev 502) @@ -138,7 +138,7 @@ // browse arch archive // load object from a arch file you found folderLevel = 0; - mainControl.disableTabPane(); + mainControl.setTabPaneEnabled(false); // here we go... if (mainControl.isArchLoadedFromCollection()) { @@ -156,7 +156,7 @@ loadArchesFromArtifacts(mainControl.getArchDefaultFolder() + File.separator + IGUIConstants.ARTIFACTS_FILE); loadArchesFromArtifacts(mainControl.getMapDefaultFolder()); - mainControl.enableTabPane(); + mainControl.setTabPaneEnabled(true); mainControl.setStatusText(" Sorting..."); connectFaces(); // attach faces to arches Modified: trunk/src/app/net/sf/gridarta/MainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/MainControl.java 2006-10-08 19:45:30 UTC (rev 501) +++ trunk/src/app/net/sf/gridarta/MainControl.java 2006-10-08 21:50:03 UTC (rev 502) @@ -2,6 +2,7 @@ import javax.swing.filechooser.FileFilter; import net.sf.gridarta.gameobject.ArchetypeSet; +import org.jetbrains.annotations.NotNull; /** * This interface is only for unification. @@ -43,4 +44,38 @@ */ ArchetypeSet getArchetypeSet(); + /** + * Get the ArchObjectParser that parsers Archetypes. + * @return ArchObjectParser + */ + Object getArchObjectParser(); + + /** + * Returns the MainView of this MainControl. + * @return The MainView of this MainControl. + */ + Object getMainView(); + + /** + * Sets the enabled state of the tab pane for Archetypes. + * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it. + * @deprecated this should be done via MVC instead. + */ + @Deprecated void setTabPaneEnabled(boolean tabPaneEnabled); + + /** + * Add a new ArchPanel. + * @param name Name of the new ArchPanel. + * @deprecated this has nothing to do with MainControl and should be refactored + */ + @Deprecated void addArchPanel(@NotNull String name); + + /** + * Add a new ArchPanelCombo. + * @param name Name of the new Combo. + * @return some index TODO document this + * @deprecated this has nothing to do with MainControl and should be refactored + */ + @Deprecated int addArchPanelCombo(@NotNull String name); + } // interface MainControl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-08 22:39:40
|
Revision: 504 http://svn.sourceforge.net/gridarta/?rev=504&view=rev Author: christianhujer Date: 2006-10-08 15:39:14 -0700 (Sun, 08 Oct 2006) Log Message: ----------- Captured ArchObjectParser similarities in a common interface. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CPickmapPanel.java trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMapArchPanel.java trunk/daimonin/src/daieditor/CMapFileDecode.java trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gameobject/ArchObjectParser.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-08 21:52:21 UTC (rev 503) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-08 22:39:14 UTC (rev 504) @@ -896,7 +896,7 @@ return null; } - ArchObjectParser.sortTempList(objects); // sort the list (put multiparts at the end) + archObjectParser.sortTempList(objects); // sort the list (put multiparts at the end) control = newLevel(objects, maparch, show, initial); // init the map if (show) { Modified: trunk/crossfire/src/cfeditor/CPickmapPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-10-08 21:52:21 UTC (rev 503) +++ trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-10-08 22:39:14 UTC (rev 504) @@ -24,7 +24,6 @@ package cfeditor; -import cfeditor.gameobject.ArchObjectParser; import cfeditor.gameobject.GameObject; import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; @@ -146,7 +145,7 @@ if (!mainControl.collectTempList(objects, mapFile)) { // get face names, face id, etc. return false; } - ArchObjectParser.sortTempList(objects); // sort the list (put multiparts at the end) + mainControl.getArchObjectParser().sortTempList(objects); // sort the list (put multiparts at the end) bmapview = newPickmap(objects, maparch, mapFile); // init the map } Modified: trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-08 21:52:21 UTC (rev 503) +++ trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-08 22:39:14 UTC (rev 504) @@ -52,7 +52,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class ArchObjectParser { +public final class ArchObjectParser implements net.sf.gridarta.gameobject.ArchObjectParser<GameObject> { /** Logger. */ private static final Logger log = Logger.getLogger(ArchObjectParser.class); @@ -156,12 +156,12 @@ * @param fname filename of the arch definition file (*.arc) * @param index current subdirectory-index on the ArchPanel (-> ComboBoxes) */ - public void parseDefArch(final String fname, final int index) { + public void parseArchetype(final String fname, final int index) { //Open the file for reading try { final BufferedReader in = new BufferedReader(new FileReader(fname)); try { - parseDefArchFromStream(in, index); + parseArchetypeFromStream(in, index, fname); } finally { in.close(); } @@ -172,21 +172,13 @@ } } - public void parseDefArchFromStream(final BufferedReader in, final int index) { - parseDefArchFromStream(in, null, null, null, index); + public void parseArchetypeFromStream(final BufferedReader in, final int index, final String fname) { + parseArchetypeFromStream(in, null, null, null, index, fname); } - /** - * Here we take a default arch from a filestream, parses the data and - * put the result on the arch stack in CMainControl. - * @param in <code>BufferedReader</code> file stream of arch data - * @param defArch default arch (only for artifacts) - * @param line first line, pre-parsed (only for artifacts) - * @param archName arch-object name (only for artifacts) - * @param index current index on the ArchPanel - */ + /** {@inheritDoc} */ @Nullable - public GameObject parseDefArchFromStream(final BufferedReader in, final GameObject defArch, final String line, final String archName, int index) { + public GameObject parseArchetypeFromStream(final BufferedReader in, @Nullable final GameObject archetype, final String line, final String archName, int index, final String fname) { //Open the file for reading try { @@ -194,10 +186,10 @@ // start with new clean GameObject instance GameObject arch; GameObject archlast = null; - if (defArch == null) { + if (archetype == null) { arch = new GameObject(); } else { - arch = defArch.createClone(0, 0); + arch = archetype.createClone(0, 0); } arch.resetObjectText(); @@ -339,7 +331,7 @@ if (archName != null) { arch.setArtifact(true); // here we add all unchanged arch text lines from defArch back to arch - arch.addObjectText(arch.diffArchText(defArch.getObjectText(), true)); + arch.addObjectText(arch.diffArchText(archetype.getObjectText(), true)); return arch; } archlast = arch; @@ -429,7 +421,7 @@ * cut off from load parsing * @param arch default arch to be parsed */ - public static void postParseDefArch(final GameObject arch) { + public void postParseDefArch(final GameObject arch) { final String text = arch.getObjectText(); arch.resetObjectText(); final int len = text.length(); @@ -470,25 +462,7 @@ arch.setEditType(IGUIConstants.TILE_EDIT_NONE); } - /** - * Here we go... thats the hard one - * we copy the needed values from default arch to map arch - * we setup the panels to show the right values - * <p/> - * first: the anim list... we want handle this later so we ignore this yet - * and let it in the arch text windows for handwork - * <p/> - * 2nd: msg/msgend - * we had in the map a msg/msgend cmd or not - * because we init our msg buffer only when one cmd come in - * we have a null-ptr or a text - * if text, this will overrule ALWAYS the default text - * if null, copy the default text in arch, so the user can see and edit it - * if at save time msg-maparch == msg-default, we ignore it - * in every other case (even "" text) we save - * @param gameObject map arch to be parsed - * @param editType edit type(s) to be calculated for the arch - */ + /** {@inheritDoc} */ public void postParseMapArch(final GameObject gameObject, final int editType) { if (gameObject.getArchetypeName() == null) { return; @@ -548,16 +522,10 @@ } } - /** - * If the given arch is a multipart head, we generate the appropriate - * tail (from the arch stack) and attach it. The new arches get added - * to the temp list, not a map. This method should only be called - * after map-loading. - * The ArchetypeSet should be fully initialized at this point. - * @param gameObject multipart head that needs tail attached - */ + /** {@inheritDoc} */ public void expandMulti(final GameObject gameObject, final List<GameObject> objects) { - final GameObject archetype = mainControl.getArchetype(gameObject.getArchetypeName()); // default arch + // TODO: Couldn't we simply invoke archetype = gameObject.getArchetype() here? + final GameObject archetype = mainControl.getArchetype(gameObject.getArchetypeName()); // is it a multi head? if (archetype != null && archetype.isMulti() && gameObject.getMultiRefCount() <= 1) { @@ -581,15 +549,10 @@ } } - /** - * Sort the temp list of arches, placing all multiparts at the end. - * This is neccessary to assure multiparts are always on top. - * @param objects list of objects - * @note This method assumes that all pieces of one multipart are listed in - * a row, which is okay as long as the loader puts it that way. - */ - public static void sortTempList(final List<GameObject> objects) { + /** {@inheritDoc} */ + public void sortTempList(final List<GameObject> objects) { final Comparator<GameObject> sorter = new Comparator<GameObject>() { + /** {@inheritDoc} */ public int compare(final GameObject o1, final GameObject o2) { final boolean b1 = o1.isMulti(); final boolean b2 = o2.isMulti(); Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-08 21:52:21 UTC (rev 503) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-08 22:39:14 UTC (rev 504) @@ -193,7 +193,7 @@ final BufferedReader stream = IOUtils.createReader(IGUIConstants.CONFIG_DIR, IGUIConstants.ARCH_FILE); try { // load all arches - mainControl.getArchObjectParser().parseDefArchFromStream(stream, 0); + mainControl.getArchObjectParser().parseArchetypeFromStream(stream, 0, null); } finally { // close filestream stream.close(); @@ -251,7 +251,7 @@ if ((len = name.length()) >= 4) { if (name.regionMatches(len - 4, ".arc", 0, 4)) { //CMainStatusbar.getInstance().setText(" Loading Arch: "+name); - mainControl.getArchObjectParser().parseDefArch(f.getAbsolutePath(), index); + mainControl.getArchObjectParser().parseArchetype(f.getAbsolutePath(), index); } else if (name.regionMatches(len - 4, ".png", 0, 4)) { //CMainStatusbar.getInstance().setText(" Loading PNG: "+name); if (mainControl.getImageSet() == null || name.indexOf("." + mainControl.getImageSet() + ".") != -1) { Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-10-08 21:52:21 UTC (rev 503) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-10-08 22:39:14 UTC (rev 504) @@ -1275,7 +1275,7 @@ // Ok, now is attached to default arch and loaded png // NOW we post parse the object... // (We calculate only edit types that are active, to save time) - ArchObjectParser.postParseMapArch(gameObject, tileEdit); + archObjectParser.postParseMapArch(gameObject, tileEdit); // now lets assign the visible face - perhaps we have still a anim gameObject.setObjectFace(); Modified: trunk/daimonin/src/daieditor/CMapArchPanel.java =================================================================== --- trunk/daimonin/src/daieditor/CMapArchPanel.java 2006-10-08 21:52:21 UTC (rev 503) +++ trunk/daimonin/src/daieditor/CMapArchPanel.java 2006-10-08 22:39:14 UTC (rev 504) @@ -24,7 +24,6 @@ package daieditor; -import daieditor.gameobject.ArchObjectParser; import daieditor.gameobject.GameObject; import daieditor.gui.ConnectionView; import daieditor.gui.ErrorListView; @@ -303,7 +302,7 @@ } invnew.setDirection(invnew.getArchetype().getDirection()); - ArchObjectParser.postParseMapArch(invnew, 0); + mainControl.getArchObjectParser().postParseMapArch(invnew, 0); inv.addLast(invnew); invnew.setObjectFace(); mainControl.getMainView().setMapTileList(mainControl.getCurrentMap(), inv); Modified: trunk/daimonin/src/daieditor/CMapFileDecode.java =================================================================== --- trunk/daimonin/src/daieditor/CMapFileDecode.java 2006-10-08 21:52:21 UTC (rev 503) +++ trunk/daimonin/src/daieditor/CMapFileDecode.java 2006-10-08 22:39:14 UTC (rev 504) @@ -24,7 +24,6 @@ package daieditor; -import daieditor.gameobject.ArchObjectParser; import daieditor.gameobject.GameObject; import daieditor.map.MapArchObject; import java.io.BufferedReader; @@ -97,7 +96,7 @@ readArch(myInput, thisLine); // all these are map arches } CMainControl.getInstance().collectTempList(objects, file); - ArchObjectParser.sortTempList(objects); + CMainControl.getInstance().getArchObjectParser().sortTempList(objects); return objects; // return first arch of the list } finally { objects = null; Modified: trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-08 21:52:21 UTC (rev 503) +++ trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-08 22:39:14 UTC (rev 504) @@ -50,7 +50,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class ArchObjectParser { +public final class ArchObjectParser implements net.sf.gridarta.gameobject.ArchObjectParser<GameObject> { /** Logger. */ private static final Logger log = Logger.getLogger("daieditor"); @@ -73,13 +73,13 @@ * @param fname filename of the arch definition file (*.arc) * @param index current subdirectory-index on the ArchPanel (-> ComboBoxes) */ - public void parseDefArch(final String fname, final int index) { + public void parseArchetype(final String fname, final int index) { //Open the file for reading try { final BufferedReader in = new BufferedReader(new FileReader(fname)); try { // do the actual parsing - parseDefArchFromStream(in, index, fname); + parseArchetypeFromStream(in, index, fname); } finally { in.close(); } @@ -90,30 +90,20 @@ } } - public void parseDefArchFromStream(final BufferedReader in, final int index, final String fname) throws IOException { - parseDefArchFromStream(in, null, null, null, index, fname); + public void parseArchetypeFromStream(final BufferedReader in, final int index, final String fname) throws IOException { + parseArchetypeFromStream(in, null, null, null, index, fname); } - /** - * Here we take a default arch from a filestream, parses the data and - * put the result on the arch stack in CMainControl. - * @param in <code>BufferedReader</code> file stream of arch data - * @param defArch default arch (only for artifacts) - * @param line first line, pre-parsed (only for artifacts) - * @param archName arch-object name (only for artifacts) - * @param index current index on the ArchPanel - * @return TODO - * @throws IOException in case of I/O problems - */ + /** {@inheritDoc} */ @Nullable @SuppressWarnings({"StringContatenationInLoop", "ObjectAllocationInLoop"}) - public GameObject parseDefArchFromStream(final BufferedReader in, @Nullable final GameObject defArch, @Nullable final String line, @Nullable final String archName, /* TODO: final*/ int index, final String fname) throws IOException { + public GameObject parseArchetypeFromStream(final BufferedReader in, @Nullable final GameObject archetype, @Nullable final String line, @Nullable final String archName, /* TODO: final*/ int index, final String fname) throws IOException { // start with new clean GameObject instance GameObject arch; GameObject archlast = null; - if (defArch == null) { + if (archetype == null) { arch = new GameObject(); } else { - arch = defArch.createClone(0, 0); + arch = archetype.createClone(0, 0); } String newCat; final boolean isInternPath; @@ -304,8 +294,8 @@ if (archName != null) { arch.setArtifact(true); // here we add all unchanged arch text lines from defArch back to arch - if (defArch != null) { - arch.addObjectText(arch.diffArchText(defArch.getObjectText(), true)); + if (archetype != null) { + arch.addObjectText(arch.diffArchText(archetype.getObjectText(), true)); } return arch; } @@ -416,7 +406,7 @@ * cut off from load parsing * @param arch default arch to be parsed */ - public static void postParseDefArch(final GameObject arch) { + public void postParseDefArch(final GameObject arch) { final String text = arch.getObjectText(); arch.resetObjectText(); final int len = text.length(); @@ -458,119 +448,94 @@ arch.setEditType(IGUIConstants.TILE_EDIT_NONE); } - /** - * Here we go... thats the hard one - * we copy the needed values from default arch to map arch - * we setup the panels to show the right values - * <p/> - * first: the anim list... we want handle this later so we ignore this yet - * and let it in the arch text windows for handwork - * <p/> - * 2nd: msg/msgend - * we had in the map a msg/msgend cmd or not - * because we init our msg buffer only when one cmd come in - * we have a null-ptr or a text - * if text, this will overrule ALWAYS the default text - * if null, copy the default text in arch, so the user can see and edit it - * if at save time msg-maparch == msg-default, we ignore it - * in every other case (even "" text) we save - * @param arch map arch to be parsed - * @param editType edit type(s) to be calculated for the arch - */ - public static void postParseMapArch(final GameObject arch, final int editType) { - if (!arch.hasArchetype()) { + /** {@inheritDoc} */ + public void postParseMapArch(final GameObject gameObject, final int editType) { + if (!gameObject.hasArchetype()) { return; } - final String text = arch.getObjectText(); + final String text = gameObject.getObjectText(); final int len = text.length(); - final GameObject defarch = arch.getArchetype(); + final GameObject defarch = gameObject.getArchetype(); - arch.resetObjectText(); + gameObject.resetObjectText(); // so, lets check the stuff a last time for (int i = 0, s = 0; i < len; i++) { if (text.charAt(i) == '\n') { if (i - s > 0) { if (text.regionMatches(s, "animation ", 0, 9)) { - arch.setAnimName(text.substring(s + 10, i)); - arch.addObjectText(text.substring(s, i) + "\n"); + gameObject.setAnimName(text.substring(s + 10, i)); + gameObject.addObjectText(text.substring(s, i) + "\n"); } else if (text.regionMatches(s, "name ", 0, 5)) { - arch.setObjName(text.substring(s + 5, i)); + gameObject.setObjName(text.substring(s + 5, i)); } else { // this is an unparsed arch attribute, it has to stay in the archtext - arch.addObjectText(text.substring(s, i) + "\n"); + gameObject.addObjectText(text.substring(s, i) + "\n"); } } s = i + 1; } } - if (arch.getDirection() == -1) { // still the invalid direction! - arch.setDirection(defarch.getDirection()); + if (gameObject.getDirection() == -1) { // still the invalid direction! + gameObject.setDirection(defarch.getDirection()); } - arch.setRealFace(arch.getFaceRealName()); + gameObject.setRealFace(gameObject.getFaceRealName()); // if the type is still unset, then we take the default one - if (arch.getArchTypNr() == GameObject.TYPE_UNSET) { - arch.setArchTypNr(defarch.getArchTypNr()); + if (gameObject.getArchTypNr() == GameObject.TYPE_UNSET) { + gameObject.setArchTypNr(defarch.getArchTypNr()); } // if the type is still unset, then we take the default one - if (defarch.getMultiShapeID() > 0 && arch.getMultiShapeID() == 0) { - arch.setMultiShapeID(defarch.getMultiShapeID()); + if (defarch.getMultiShapeID() > 0 && gameObject.getMultiShapeID() == 0) { + gameObject.setMultiShapeID(defarch.getMultiShapeID()); } - if (defarch.getMultiPartNr() > 0 && arch.getMultiPartNr() == 0) { - arch.setMultiPartNr(defarch.getMultiPartNr()); + if (defarch.getMultiPartNr() > 0 && gameObject.getMultiPartNr() == 0) { + gameObject.setMultiPartNr(defarch.getMultiPartNr()); } if (defarch.isLowestPart()) { - arch.setLowestPart(true); + gameObject.setLowestPart(true); } - arch.setMultiX(defarch.getMultiX()); - arch.setMultiY(defarch.getMultiY()); + gameObject.setMultiX(defarch.getMultiX()); + gameObject.setMultiY(defarch.getMultiY()); // arch.setEditType(defarch.getEditType()); // validate the ScriptedEvents - arch.validateAllEvents(); + gameObject.validateAllEvents(); // Finally, we calculate the desired editType of the arch - if (arch.isTail()) { - arch.setEditType(arch.getHead().getEditType()); // copy from head + if (gameObject.isTail()) { + gameObject.setEditType(gameObject.getHead().getEditType()); // copy from head } else if (editType != 0) { - arch.setEditType(arch.calculateEditType(editType)); // calculate new + gameObject.setEditType(gameObject.calculateEditType(editType)); // calculate new } } - /** - * If the given arch is a multipart head, we generate the appropriate - * tail (from the arch stack) and attach it. The new arches get added - * to the temp list, not a map. This method should only be called - * after map-loading. - * The ArchetypeSet should be fully initialized at this point. - * @param arch multipart head that needs tail attached - */ - public void expandMulti(final GameObject arch, final List<GameObject> objects) { + /** {@inheritDoc} */ + public void expandMulti(final GameObject gameObject, final List<GameObject> objects) { - if (arch.isInContainer()) { + if (gameObject.isInContainer()) { return; } - final GameObject defarch = arch.getArchetype(); // default arch + final GameObject archetype = gameObject.getArchetype(); // default arch // is it a multi head? - if (defarch != null && defarch.isMulti() && arch.getMultiRefCount() <= 1) { + if (archetype != null && archetype.isMulti() && gameObject.getMultiRefCount() <= 1) { // we have a multi head and need to insert his tail now // do insertion for all non-head parts of the multi - for (GameObject oldPart = defarch.getMultiNext(); oldPart != null; oldPart = oldPart.getMultiNext()) { + for (GameObject oldPart = archetype.getMultiNext(); oldPart != null; oldPart = oldPart.getMultiNext()) { final GameObject newarch = oldPart.createArch(); - arch.addTailPart(newarch); + gameObject.addTailPart(newarch); objects.add(newarch); // set map position (x, y) - newarch.setMapX(arch.getMapX() + newarch.getMultiX()); - newarch.setMapY(arch.getMapY() + newarch.getMultiY()); + newarch.setMapX(gameObject.getMapX() + newarch.getMultiX()); + newarch.setMapY(gameObject.getMapY() + newarch.getMultiY()); // now attach the default arch and stuff // (don't need edit type as we copy from head) @@ -579,15 +544,10 @@ } } - /** - * Sort the temp list of arches, placing all multiparts at the end. - * This is neccessary to assure multiparts are always on top. - * @param objects list of objects - * @note This method assumes that all pieces of one multipart are listed in - * a row, which is okay as long as the loader puts it that way. - */ - public static void sortTempList(final List<GameObject> objects) { + /** {@inheritDoc} */ + public void sortTempList(final List<GameObject> objects) { final Comparator<GameObject> sorter = new Comparator<GameObject>() { + /** {@inheritDoc} */ public int compare(final GameObject o1, final GameObject o2) { final boolean b1 = o1.isMulti(); final boolean b2 = o2.isMulti(); Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-08 21:52:21 UTC (rev 503) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-10-08 22:39:14 UTC (rev 504) @@ -263,7 +263,7 @@ // now the editor will do the same as the real server: // get the default arch as base and parse the new values over it // the extended functions of the artifacts file can be ignored here. - mainControl.getArchObjectParser().parseDefArchFromStream(myInput, editorCode == 2 ? null : archetype, thisLine, name, 0, fname); + mainControl.getArchObjectParser().parseArchetypeFromStream(myInput, editorCode == 2 ? null : archetype, thisLine, name, 0, fname); // note: in the parser is a small part where we handle the title setting // and the reverse type setting for type == -1 (unique items marker in artifacts file) } else { @@ -300,7 +300,7 @@ final BufferedReader stream = IOUtils.createReader(baseDir, IGUIConstants.ARCH_FILE); try { // load all arches - mainControl.getArchObjectParser().parseDefArchFromStream(stream, 0, IGUIConstants.ARCH_FILE); + mainControl.getArchObjectParser().parseArchetypeFromStream(stream, 0, IGUIConstants.ARCH_FILE); mainControl.getFaceObjects().loadFacesCollection( new File(mainControl.getArchDefaultFolder(), IGUIConstants.PNG_FILE), new File(new File(mainControl.getArchDefaultFolder(), IGUIConstants.CONFIG_DIR), IGUIConstants.FACETREE_FILE) @@ -372,7 +372,7 @@ if (name.endsWith(".arc")) { //CMainStatusbar.getInstance().setText(" Loading Arch: "+ name); currentFile = f; - mainControl.getArchObjectParser().parseDefArch(f.getPath(), index); + mainControl.getArchObjectParser().parseArchetype(f.getPath(), index); } else if (name.endsWith(".png")) { //CMainStatusbar.getInstance().setText(" Loading PNG: "+ name); addPNGFace(f.getAbsolutePath(), name); Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-10-08 21:52:21 UTC (rev 503) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-10-08 22:39:14 UTC (rev 504) @@ -28,7 +28,6 @@ import daieditor.CFArchTypeList; import daieditor.CMainControl; import daieditor.IGUIConstants; -import daieditor.gameobject.ArchObjectParser; import daieditor.gameobject.GameObject; import java.awt.Point; import java.awt.Toolkit; @@ -271,7 +270,7 @@ mapGrid[pos.x][pos.y].addLast(head); } head.setDirection(defaultArch.getDirection()); - ArchObjectParser.postParseMapArch(head, mapControl.getActiveEditType()); + mainControl.getArchObjectParser().postParseMapArch(head, mapControl.getActiveEditType()); head.setObjectFace(); for (GameObject tailArch = defaultArch.getMultiNext(); tailArch != null; tailArch = tailArch.getMultiNext()) { final Point posT = new Point(tailArch.getMultiX(), tailArch.getMultiY()); @@ -287,7 +286,7 @@ mapGrid[posT.x][posT.y].addLast(tail); } tail.setDirection(tailArch.getDirection()); - ArchObjectParser.postParseMapArch(tail, mapControl.getActiveEditType()); + mainControl.getArchObjectParser().postParseMapArch(tail, mapControl.getActiveEditType()); tail.setObjectFace(); } return true; @@ -357,7 +356,7 @@ next.getContainer().addLast(invnew); invnew.setObjectFace(); - ArchObjectParser.postParseMapArch(invnew, mapControl.getActiveEditType()); + mainControl.getArchObjectParser().postParseMapArch(invnew, mapControl.getActiveEditType()); mainControl.getMainView().setMapTileList(mainControl.getCurrentMap(), invnew); return true; } Added: trunk/src/app/net/sf/gridarta/gameobject/ArchObjectParser.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/ArchObjectParser.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/ArchObjectParser.java 2006-10-08 22:39:14 UTC (rev 504) @@ -0,0 +1,95 @@ +package net.sf.gridarta.gameobject; + +import java.util.List; +import java.io.BufferedReader; +import java.io.IOException; +import org.jetbrains.annotations.Nullable; + +/** + * Common interface for ArchObjectParsers. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public interface ArchObjectParser<G extends GameObject<G>> { + + /** + * If the given arch is a multipart head, we generate the appropriate + * tail (from the arch stack) and attach it. The new arches get added + * to the temp list, not a map. This method should only be called + * after map-loading. + * The ArchetypeSet should be fully initialized at this point. + * @param gameObject multipart head that needs tail attached + * @param objects list with objects that should get the tails attached + * @todo think whether expanding multiparts here is a good idea, maybe MapModel is a better place. + */ + void expandMulti(G gameObject, List<G> objects); + + /** + * Read an Archetype from a file. + * @param fname filename of the arch definition file (*.arc) + * @param index current subdirectory-index on the ArchPanel (-> ComboBoxes) + */ + void parseArchetype(String fname, int index); + + /** + * Here we read an Archetype from a filestream, parse the data and + * put the result in the ArchetypeSet in CMainControl. + * @param in <code>BufferedReader</code> file stream of arch data + * @param archetype Archetype (only for artifacts) + * @param line first line, pre-parsed (only for artifacts) + * @param archName arch-object name (only for artifacts) + * @param index current index on the ArchPanel + * @param fname filename of the Archetype + * @return TODO + * @throws IOException in case of I/O problems + */ + GameObject parseArchetypeFromStream(BufferedReader in, @Nullable G archetype, @Nullable String line, @Nullable String archName, int index, String fname) throws IOException; + + /** + * Short form of {@link #parseArchetypeFromStream(BufferedReader, GameObject, String, String, int, String)}. + * @param in <code>BufferedReader</code> file stream of arch data + * @param index current index on the ArchPanel + * @param fname filename of the Archetype + * @throws IOException in case of I/O problems + */ + void parseArchetypeFromStream(BufferedReader in, int index, String fname) throws IOException; + + /** + * I drop this here ... we got 2 functions now but i want the hardcore parsing + * cut off from load parsing + * @param arch default arch to be parsed + * @todo improve this stupid comment + */ + void postParseDefArch(G arch); + + /** + * Here we go... thats the hard one + * we copy the needed values from default arch to map arch + * we setup the panels to show the right values + * <p/> + * first: the anim list... we want handle this later so we ignore this yet + * and let it in the arch text windows for handwork + * <p/> + * 2nd: msg/msgend + * we had in the map a msg/msgend cmd or not + * because we init our msg buffer only when one cmd come in + * we have a null-ptr or a text + * if text, this will overrule ALWAYS the default text + * if null, copy the default text in arch, so the user can see and edit it + * if at save time msg-maparch == msg-default, we ignore it + * in every other case (even "" text) we save + * @param gameObject map arch to be parsed + * @param editType edit type(s) to be calculated for the arch + * @todo improve this stupid comment + */ + void postParseMapArch(G gameObject, int editType); + + /** + * Sort the temp list of arches, placing all multiparts at the end. + * This is neccessary to assure multiparts are always on top. + * @param objects list of objects + * @note This method assumes that all pieces of one multipart are listed in + * a row, which is okay as long as the loader puts it that way. + */ + void sortTempList(List<G> objects); + +} // interface ArchObjectParser Property changes on: trunk/src/app/net/sf/gridarta/gameobject/ArchObjectParser.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-08 22:53:33
|
Revision: 505 http://svn.sourceforge.net/gridarta/?rev=505&view=rev Author: christianhujer Date: 2006-10-08 15:53:19 -0700 (Sun, 08 Oct 2006) Log Message: ----------- Fixed some documentation bugs. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java Modified: trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-08 22:39:14 UTC (rev 504) +++ trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-08 22:53:19 UTC (rev 505) @@ -151,11 +151,7 @@ return "*UNKNOWN" + index + "*"; // this type is unknown } - /** - * Read a default arch from a file. - * @param fname filename of the arch definition file (*.arc) - * @param index current subdirectory-index on the ArchPanel (-> ComboBoxes) - */ + /** {@inheritDoc} */ public void parseArchetype(final String fname, final int index) { //Open the file for reading try { @@ -172,6 +168,7 @@ } } + /** {@inheritDoc} */ public void parseArchetypeFromStream(final BufferedReader in, final int index, final String fname) { parseArchetypeFromStream(in, null, null, null, index, fname); } @@ -416,11 +413,7 @@ return null; } - /** - * I drop this here ... we got 2 functions now but i want the hardcore parsing - * cut off from load parsing - * @param arch default arch to be parsed - */ + /** {@inheritDoc} */ public void postParseDefArch(final GameObject arch) { final String text = arch.getObjectText(); arch.resetObjectText(); Modified: trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-08 22:39:14 UTC (rev 504) +++ trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java 2006-10-08 22:53:19 UTC (rev 505) @@ -68,11 +68,7 @@ this.mainControl = mainControl; } - /** - * Read a default arch from a file. - * @param fname filename of the arch definition file (*.arc) - * @param index current subdirectory-index on the ArchPanel (-> ComboBoxes) - */ + /** {@inheritDoc} */ public void parseArchetype(final String fname, final int index) { //Open the file for reading try { @@ -90,6 +86,7 @@ } } + /** {@inheritDoc} */ public void parseArchetypeFromStream(final BufferedReader in, final int index, final String fname) throws IOException { parseArchetypeFromStream(in, null, null, null, index, fname); } @@ -401,11 +398,7 @@ return null; } - /** - * I drop this here ... we got 2 functions now but i want the hardcore parsing - * cut off from load parsing - * @param arch default arch to be parsed - */ + /** {@inheritDoc} */ public void postParseDefArch(final GameObject arch) { final String text = arch.getObjectText(); arch.resetObjectText(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-08 22:59:41
|
Revision: 506 http://svn.sourceforge.net/gridarta/?rev=506&view=rev Author: christianhujer Date: 2006-10-08 15:58:58 -0700 (Sun, 08 Oct 2006) Log Message: ----------- Renamed ArchObjectParser to ArchetypeParser. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CArchQuickView.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/crossfire/src/cfeditor/CPickmapPanel.java trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMapArchPanel.java trunk/daimonin/src/daieditor/CMapFileDecode.java trunk/daimonin/src/daieditor/CPickmapPanel.java trunk/daimonin/src/daieditor/CopyBuffer.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java trunk/src/app/net/sf/gridarta/MainControl.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java trunk/src/app/net/sf/gridarta/gameobject/ArchetypeParser.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java trunk/daimonin/src/daieditor/gameobject/ArchObjectParser.java trunk/src/app/net/sf/gridarta/gameobject/ArchObjectParser.java Modified: trunk/crossfire/src/cfeditor/CArchQuickView.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchQuickView.java 2006-10-08 22:53:19 UTC (rev 505) +++ trunk/crossfire/src/cfeditor/CArchQuickView.java 2006-10-08 22:58:58 UTC (rev 506) @@ -137,7 +137,7 @@ archObjNameText.setText("<html><font color=black>Name: " + arch.getObjName() + "</font></html>"); } - archTypeText.setText("<html><font color=black>Type: " + mainControl.getArchObjectParser().getArchTypeName(arch.getArchTypNr()) + " (" + arch.getArchTypNr() + ") </font></html>"); + archTypeText.setText("<html><font color=black>Type: " + mainControl.getArchetypeParser().getArchTypeName(arch.getArchTypNr()) + " (" + arch.getArchTypNr() + ") </font></html>"); if (arch.isMulti()) { archTileText.setText("<html><font color=black>Tile: </font><font color=green> multi</font><font color=black> (" + arch.getMultiRefCount() + " parts) (" + arch.getSizeX() + "," + arch.getSizeY() + ")</font></html>"); Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-08 22:53:19 UTC (rev 505) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-08 22:58:58 UTC (rev 506) @@ -24,7 +24,7 @@ package cfeditor; -import cfeditor.gameobject.ArchObjectParser; +import cfeditor.gameobject.ArchetypeParser; import cfeditor.gameobject.ArchetypeSet; import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObjects; @@ -113,7 +113,7 @@ private CMapFileEncode mapFileEncoder; - private ArchObjectParser archObjectParser; + private ArchetypeParser archetypeParser; /** The Animation Objects. */ private AnimationObjects animationObjects; @@ -244,11 +244,11 @@ mapFileEncoder = new CMapFileEncode(this); // our global object parser - archObjectParser = new ArchObjectParser(this); + archetypeParser = new ArchetypeParser(this); animationObjects = new AnimationObjects(); // read in the type & type field definitions - archObjectParser.loadTypeNumbers(); + archetypeParser.loadTypeNumbers(); //loadTypeDef(); // load the list with archtype-data from "types.txt" @@ -891,12 +891,12 @@ // ok, we have it all!! final MapControl control; - // go to ArchObjectParser and add the default arch list information to them + // go to ArchetypeParser and add the default arch list information to them if (!collectTempList(objects, file)) { // get face names, face id, etc. return null; } - archObjectParser.sortTempList(objects); // sort the list (put multiparts at the end) + archetypeParser.sortTempList(objects); // sort the list (put multiparts at the end) control = newLevel(objects, maparch, show, initial); // init the map if (show) { @@ -971,9 +971,9 @@ // Ok, now is attached to default arch and loaded png // NOW we post parse the object... // (We calculate only edit types that are active, to save time) - archObjectParser.postParseMapArch(gameObject, tileEdit); + archetypeParser.postParseMapArch(gameObject, tileEdit); - archObjectParser.expandMulti(gameObject, tailList); + archetypeParser.expandMulti(gameObject, tailList); } for (final GameObject tail : tailList) { @@ -1722,8 +1722,8 @@ return currentMap; } - public ArchObjectParser getArchObjectParser() { - return archObjectParser; + public ArchetypeParser getArchetypeParser() { + return archetypeParser; } public AnimationObjects getAnimationObject() { Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-10-08 22:53:19 UTC (rev 505) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-10-08 22:58:58 UTC (rev 506) @@ -285,7 +285,7 @@ } inv.addLast(invnew); - mainControl.getArchObjectParser().postParseMapArch(invnew, 0); + mainControl.getArchetypeParser().postParseMapArch(invnew, 0); mainControl.getMainView().setMapTileList(mainControl.getCurrentMap(), inv.getMyID()); mainControl.getCurrentMap().setLevelChangedFlag(); // the map has been modified } @@ -729,7 +729,7 @@ archMapPos.setText("Map: " + gameObject.getMapX() + ", " + gameObject.getMapY()); if (gameObject.getArchetypeName() != null) { - archTypeText.setText("Type: " + mainControl.getArchObjectParser().getArchTypeName(gameObject.getArchTypNr()) + archTypeText.setText("Type: " + mainControl.getArchetypeParser().getArchTypeName(gameObject.getArchTypNr()) + " (" + gameObject.getArchTypNr() + ") [" + gameObject.getArchetypeName() + "]"); } else { archTypeText.setText("Type: <unknown>"); Modified: trunk/crossfire/src/cfeditor/CPickmapPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-10-08 22:53:19 UTC (rev 505) +++ trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-10-08 22:58:58 UTC (rev 506) @@ -141,11 +141,11 @@ // The map is totally empty bmapview = newPickmap(null, maparch, mapFile); // init the map } else { - // go to ArchObjectParser and add the default arch list information to them + // go to ArchetypeParser and add the default arch list information to them if (!mainControl.collectTempList(objects, mapFile)) { // get face names, face id, etc. return false; } - mainControl.getArchObjectParser().sortTempList(objects); // sort the list (put multiparts at the end) + mainControl.getArchetypeParser().sortTempList(objects); // sort the list (put multiparts at the end) bmapview = newPickmap(objects, maparch, mapFile); // init the map } Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-10-08 22:53:19 UTC (rev 505) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-10-08 22:58:58 UTC (rev 506) @@ -383,7 +383,7 @@ mapControl.addArchObjectToMap(newHead, fillBelow); for (GameObject tmp = newHead.getMultiNext(); tmp != null; tmp = tmp.getMultiNext()) { mapControl.addArchObjectToMap(tmp, fillBelow); - mainControl.getArchObjectParser().postParseMapArch(tmp, mapControl.getActiveEditType()); + mainControl.getArchetypeParser().postParseMapArch(tmp, mapControl.getActiveEditType()); } } } Deleted: trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-08 22:53:19 UTC (rev 505) +++ trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-10-08 22:58:58 UTC (rev 506) @@ -1,558 +0,0 @@ -/* - * Crossfire Java Editor. - * Copyright (C) 2000 Michael Toennies - * Copyright (C) 2001 Andreas Vogl - * - * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package cfeditor.gameobject; - -import cfeditor.CMainControl; -import cfeditor.IGUIConstants; -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import net.sf.gridarta.io.IOUtils; -import org.apache.log4j.Logger; -import org.jdom.DataConversionException; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.JDOMException; -import org.jdom.input.SAXBuilder; -import org.jetbrains.annotations.Nullable; - -/** - * The <code>ArchObjectParser</code> class handles the parsing of arches. It is - * a class separated from ArchetypeSet because it is also involved in - * loading arches in map files. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public final class ArchObjectParser implements net.sf.gridarta.gameobject.ArchObjectParser<GameObject> { - - /** Logger. */ - private static final Logger log = Logger.getLogger(ArchObjectParser.class); - - // name of the system-arch containing path of starting map - public static final String STARTARCH_NAME = "map"; - - // table with type numbers as keys (Integer), and type names as values (String) - private Map<Integer,String> archTypeNumbers; - - private final CMainControl mainControl; - - /** - * Constructor - * @param mainControl main control - */ - public ArchObjectParser(final CMainControl mainControl) { - this.mainControl = mainControl; - archTypeNumbers = null; - } - - /** - * Parse the typenumbers file (associate names with type numbers) - * Type numbers and names are stored as key-value pairs in the - * Hashtable 'archTypeNumbers'. - */ - public void loadTypeNumbers() { - archTypeNumbers = new HashMap<Integer,String>(); - - try { - // open reading stream to the spells xml file - final String baseDir = IGUIConstants.CONFIG_DIR; - final BufferedReader reader = IOUtils.createReader(baseDir, IGUIConstants.TYPENR_FILE); - try { - - // parse xml document - final SAXBuilder builder = new SAXBuilder(); - builder.setValidation(true); - final Document doc = builder.build(reader); - - // retrieve the spell data from the xml - final Element root = doc.getRootElement(); - if (root == null || !"typenumbers".equalsIgnoreCase(root.getName())) { - log.warn("File '" + IGUIConstants.TYPENR_FILE + "' lacks root element 'typenumbers'."); - } else { - final List types = root.getChildren("type"); - if (types == null || types.size() == 0) { - log.warn("File '" + IGUIConstants.TYPENR_FILE + "' has no content."); - } else { - // process all 'type' elements from the xml file - int i; - for (i = 0; i < types.size(); i++) { - final Element typeElem = (Element) types.get(i); - - if (typeElem.getAttribute("number") == null) { - log.warn("In File '" + IGUIConstants.TYPENR_FILE + "': Found 'type' element without 'number'"); - } else if (typeElem.getAttribute("name") == null) { - log.warn("In File '" + IGUIConstants.TYPENR_FILE + "': Found 'type' element without 'name'"); - } else { - try { - // parse type number and -name, then add it to the table 'archTypeNumbers' - archTypeNumbers.put(typeElem.getAttribute("number").getIntValue(), typeElem.getAttribute("name").getValue()); - } catch (final DataConversionException de) { - log.error("In '" + IGUIConstants.TYPENR_FILE + "':\n type number '" + typeElem.getAttribute("number").getValue() + "' is not an integer."); - } - } - } - - // loading successful - if (log.isInfoEnabled()) { - log.info("" + i + " typenumbers loaded."); - } - } - } - } finally { - reader.close(); - } - } catch (final JDOMException e) { - log.error("Parsing error in '" + IGUIConstants.TYPENR_FILE + "'", e); - } catch (final FileNotFoundException e) { - log.error("Cannot read file '" + IGUIConstants.TYPENR_FILE + "'!", e); - } catch (final IOException e) { - log.error("Error while reading file '" + IGUIConstants.TYPENR_FILE + "'!", e); - } - } - - /** - * Lookup the name of an archtype. - * @param index type number - * @return name of this type, as defined in "typenumbers.xml" - */ - public String getArchTypeName(final int index) { - if (archTypeNumbers != null && archTypeNumbers.containsKey(index)) { - return archTypeNumbers.get(index); - } - return "*UNKNOWN" + index + "*"; // this type is unknown - } - - /** {@inheritDoc} */ - public void parseArchetype(final String fname, final int index) { - //Open the file for reading - try { - final BufferedReader in = new BufferedReader(new FileReader(fname)); - try { - parseArchetypeFromStream(in, index, fname); - } finally { - in.close(); - } - } catch (final FileNotFoundException e) { - log.error("Archfile " + fname + " could not be found"); - } catch (final IOException e) { - log.error("IOException in parseDefArch!"); - } - } - - /** {@inheritDoc} */ - public void parseArchetypeFromStream(final BufferedReader in, final int index, final String fname) { - parseArchetypeFromStream(in, null, null, null, index, fname); - } - - /** {@inheritDoc} */ - @Nullable - public GameObject parseArchetypeFromStream(final BufferedReader in, @Nullable final GameObject archetype, final String line, final String archName, int index, final String fname) { - - //Open the file for reading - try { - - // start with new clean GameObject instance - GameObject arch; - GameObject archlast = null; - if (archetype == null) { - arch = new GameObject(); - } else { - arch = archetype.createClone(0, 0); - } - arch.resetObjectText(); - - String thisLine2; - if (line == null) { - thisLine2 = in.readLine(); - } else { - thisLine2 = line; // pre read "Object" from artifacts file loader - } - - boolean msgflag = false; - boolean loreflag = false; - boolean animflag = false; - boolean parsearch = false; - boolean archmore = false; - String oldCat = "<xxx>"; - boolean isNewCategory = true; - GameObject firstArch = null; - String newCat = "no category info"; - int archmoreCount = 0; - while (thisLine2 != null) { - final String thisLine = thisLine2.trim(); - - if (thisLine.startsWith("#")) { - // skip comments - thisLine2 = in.readLine(); - continue; - } - - if (!parsearch) { - - if (thisLine.startsWith("More")) { - if (firstArch == null) { - firstArch = archlast; - } - archmore = true; - } else if (thisLine.startsWith("Object")) { - if (arch == null) { - arch = new GameObject(); - } - - parsearch = true; - if (!archmore) { - firstArch = null; - } - - if (archName == null) { - arch.setArchetypeName(thisLine.substring(7)); - } else { - arch.setArchetypeName(archName); - } - } - } else { - if (msgflag) { - if (thisLine.startsWith("endmsg")) { - msgflag = false; - } else { - arch.addMsgText(thisLine2 + "\n"); // thisLine2 allows leading whitespaces - } - } else if (animflag) { - if (thisLine.startsWith("mina")) { - mainControl.getAnimationObject().addAnimObject(arch.getArchetypeName(), arch.getAnimText()); - - arch.addObjectText("animation " + arch.getArchetypeName() + "\n"); - // here we must add this to AnimationObject - // and add Animation cmd here! - animflag = false; - } else { - arch.addAnimText(thisLine + "\n"); - } - } else if (loreflag) { - if (thisLine.startsWith("endlore")) { - loreflag = false; - } else { - arch.addLoreText(thisLine + "\n"); - } - } else if (thisLine.startsWith("Object")) { - log.error("Find inventory Object in def arch: " + thisLine); - } else if (thisLine.startsWith("end")) { - //if (arch.getArchTypNr() == 0) { - if (log.isDebugEnabled()) { - log.debug("Arch " + arch.getArchetypeName() + " has no type info!"); - } - //} - // we got full arch - parsearch = false; // we write this sucker - - if (firstArch != null) { - // add to head our x/y position so he can setup refmax - firstArch.addTailPart(arch); - } else { - // add arch to the archpanel - only if it is not the map arch - if (!arch.getArchetypeName().equals(STARTARCH_NAME)) { - if (!mainControl.getArchetypeSet().isLoadedFromArchive() || archName != null) { - // loading from individual files, so we simply add it to list - // ArchetypeSet.loadArchFromFiles() takes care of the panels - mainControl.addArchPanelArch(arch.getArchetypeName(), index); - } else { - // loading from collected files, so we need process panels here - if (isNewCategory) { - String folder = newCat; // main folder of new category - if (newCat.indexOf("/") > 0) { - folder = newCat.substring(0, newCat.indexOf("/")); - } - - if (!oldCat.startsWith(folder)) { - // an entire new panel must be opened - mainControl.addArchPanel(folder); - mainControl.addArchPanelCombo("show all"); - mainControl.addArchPanelCombo(folder); - index = 1; - } - - if (newCat.indexOf("/") > 0) { - folder = newCat.substring(newCat.indexOf("/") + 1); - if (newCat.startsWith(folder)) { - index = 1; // add to the base folder - } else if (!oldCat.endsWith(folder)) { - // a new JComboBox must be added - index = mainControl.addArchPanelCombo(folder); - } - } else { - index = 1; // add to the base folder - } - - isNewCategory = false; - oldCat = newCat; - } - mainControl.addArchPanelArch(arch.getArchetypeName(), index); - } - } - } - postParseDefArch(arch); - mainControl.getArchetypeSet().addArchetype(arch); - - archmore = false; // we assume this is last... but perhaps.. - - // if this arch was from Artifacts file - return here: - if (archName != null) { - arch.setArtifact(true); - // here we add all unchanged arch text lines from defArch back to arch - arch.addObjectText(arch.diffArchText(archetype.getObjectText(), true)); - return arch; - } - archlast = arch; - arch = null; - } else { - if (thisLine.startsWith("msg")) { - msgflag = true; - } else if (thisLine.startsWith("animation")) { - arch.addObjectText(thisLine + "\n"); - } else if (thisLine.startsWith("anim_speed")) { - arch.addObjectText(thisLine + "\n"); - } else if (thisLine.startsWith("anim")) { - animflag = true; - } else if (thisLine.equals("lore")) { - loreflag = true; - } else if (thisLine.startsWith("visibility ")) { - if (log.isDebugEnabled()) { - log.debug("Remove visibility: " + arch.getArchetypeName()); - } - } else if (thisLine.startsWith("magicmap ")) { - if (log.isDebugEnabled()) { - log.debug("Remove magicmap: " + arch.getArchetypeName()); - } - } else if (thisLine.startsWith("color_fg ")) { - if (log.isDebugEnabled()) { - log.debug("Remove color_fg: " + arch.getArchetypeName()); - } - } else if (thisLine.startsWith("color_bg ")) { - if (log.isDebugEnabled()) { - log.debug("Remove color_bg: " + arch.getArchetypeName()); - } - } else if (thisLine.startsWith("x ")) { - if (!archmore && !arch.getArchetypeName().equals(STARTARCH_NAME)) { - log.warn("Find x cmd in single tile or head (add it to arch text): " + arch.getArchetypeName()); - arch.addObjectText(thisLine + "\n"); - } - arch.setMultiX(Integer.parseInt(thisLine.substring(2))); - } else if (thisLine.startsWith("y ")) { - if (!archmore && !arch.getArchetypeName().equals(STARTARCH_NAME)) { - log.warn("Find y cmd in single tile or head (add it to arch text): " + arch.getArchetypeName()); - arch.addObjectText(thisLine + "\n"); - } - arch.setMultiY(Integer.parseInt(thisLine.substring(2))); - } else if (thisLine.startsWith("type ")) { - try { - final int i = Integer.parseInt(thisLine.substring(5)); - arch.setArchTypNr(i); - if (i == 0) { - log.warn("Arch " + arch.getArchetypeName() + " type number is zero. (" + thisLine.substring(5) + ")"); - } - } catch (final Exception e) { - log.warn("Arch " + arch.getArchetypeName() + " has a invalid type nr. (" + thisLine.substring(5) + ")"); - arch.addObjectText(thisLine + "\n"); - } - } else if (thisLine.startsWith("face ")) { - int x; - for (x = 4; x < thisLine.length(); x++) { - if (thisLine.charAt(x) != ' ') { - break; - } - } - arch.setFaceFlag(false); // we HAVE a face - arch.setFaceName(thisLine.substring(x, thisLine.length())); - } else if (thisLine.startsWith("editor_folder ")) { - // the display category (= "folder" the arch belongs to) - newCat = thisLine.substring(14).trim(); - if (!newCat.equals(oldCat)) { - isNewCategory = true; // this arch has a new category - } - } - arch.addObjectText(thisLine + "\n"); - if (log.isDebugEnabled()) { - log.debug("add String: " + thisLine); - } - } - } - thisLine2 = in.readLine(); - } // while loop ends here - } catch (final IOException e) { - log.error("Error: ", e); - } - return null; - } - - /** {@inheritDoc} */ - public void postParseDefArch(final GameObject arch) { - final String text = arch.getObjectText(); - arch.resetObjectText(); - final int len = text.length(); - - // if no type was set, zero is taken - if (arch.getArchTypNr() == GameObject.TYPE_UNSET) { - arch.setArchTypNr(0); - } - - boolean scriptflag = false; - for (int i = 0, s = 0; i < len; i++) { - - if (text.charAt(i) == '\n') { - if (i - s > 0) { - if (scriptflag) { - arch.addObjectText(text.substring(s, i) + "\n"); - if (text.regionMatches(s, "end_script_", 0, 11)) { - scriptflag = false; - } - } else if (text.regionMatches(s, "start_script_", 0, 13)) { - arch.addObjectText(text.substring(s, i) + "\n"); - scriptflag = true; - } else if (text.regionMatches(s, "editable ", 0, 9)) { - arch.setEditType(Integer.parseInt(text.substring(s + 9, i))); - } else if (text.regionMatches(s, "name ", 0, 5)) { - arch.setObjName(text.substring(s + 5, i)); - } else { - arch.addObjectText(text.substring(s, i) + "\n"); - } - - } - s = i + 1; - } - } - - // default arches don't get an editType (not worth the time) - // they get one assigned as soon as put on a map though. - arch.setEditType(IGUIConstants.TILE_EDIT_NONE); - } - - /** {@inheritDoc} */ - public void postParseMapArch(final GameObject gameObject, final int editType) { - if (gameObject.getArchetypeName() == null) { - return; - } - - final String text = gameObject.getObjectText(); - final int len = text.length(); - final GameObject archetype = mainControl.getArchetype(gameObject.getArchetypeName()); - - gameObject.resetObjectText(); - for (int i = 0, s = 0; i < len; i++) { - - if (text.charAt(i) == '\n') { - if (i - s > 0) { - if (text.regionMatches(s, "name ", 0, 5)) { - gameObject.setObjName(text.substring(s + 5, i)); - } else { - // this is an unparsed arch attribute, it has to stay in the archtext - gameObject.addObjectText(text.substring(s, i) + "\n"); - } - } - s = i + 1; - } - } - // so, lets check the stuff a last time - - if (gameObject.getFaceName() == null) { - gameObject.setFaceNr(archetype.getFaceNr()); - gameObject.setFaceFlag(archetype.getFaceFlag()); - } - - // if the type is still unset, then we take the default one - if (gameObject.getArchTypNr() == GameObject.TYPE_UNSET) { - gameObject.setArchTypNr(archetype.getArchTypNr()); - } - - gameObject.setMultiX(archetype.getMultiX()); - gameObject.setMultiY(archetype.getMultiY()); - - // arch.setEditType(defarch.getEditType()); - - // validate the ScriptedEvents - gameObject.validateAllEvents(); - - // we don't handle anim yet, so attach then back to archtext - if (gameObject.getAnimText() != null) { - gameObject.addObjectText("anim\n"); - gameObject.addObjectText(gameObject.getAnimText()); - gameObject.addObjectText("mina\n"); - } - - // Finally, we calculate the desired editType of the arch - if (gameObject.isTail()) { - gameObject.setEditType(gameObject.getHead().getEditType()); // copy from head - } else if (editType != 0) { - gameObject.setEditType(gameObject.calculateEditType(editType)); // calculate new - } - } - - /** {@inheritDoc} */ - public void expandMulti(final GameObject gameObject, final List<GameObject> objects) { - // TODO: Couldn't we simply invoke archetype = gameObject.getArchetype() here? - final GameObject archetype = mainControl.getArchetype(gameObject.getArchetypeName()); - - // is it a multi head? - if (archetype != null && archetype.isMulti() && gameObject.getMultiRefCount() <= 1) { - // we have a multi head and need to insert his tail now - - // do insertion for all non-head parts of the multi - for (GameObject oldPart = archetype.getMultiNext(); oldPart != null; oldPart = oldPart.getMultiNext()) { - final GameObject newarch = oldPart.createArch(); - - gameObject.addTailPart(newarch); - objects.add(newarch); - - // set map position (x, y) - newarch.setMapX(gameObject.getMapX() + newarch.getMultiX()); - newarch.setMapY(gameObject.getMapY() + newarch.getMultiY()); - - // now attach the default arch and stuff - // (don't need edit type as we copy from head) - mainControl.getArchObjectParser().postParseMapArch(newarch, 0); - } - } - } - - /** {@inheritDoc} */ - public void sortTempList(final List<GameObject> objects) { - final Comparator<GameObject> sorter = new Comparator<GameObject>() { - /** {@inheritDoc} */ - public int compare(final GameObject o1, final GameObject o2) { - final boolean b1 = o1.isMulti(); - final boolean b2 = o2.isMulti(); - return b1 == b2 ? 0 : b2 ? -1 : 1; - } - }; - Collections.sort(objects, sorter); - } - -} // class ArchObjectParser Copied: trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java (from rev 505, trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java) =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java 2006-10-08 22:58:58 UTC (rev 506) @@ -0,0 +1,558 @@ +/* + * Crossfire Java Editor. + * Copyright (C) 2000 Michael Toennies + * Copyright (C) 2001 Andreas Vogl + * + * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + */ + +package cfeditor.gameobject; + +import cfeditor.CMainControl; +import cfeditor.IGUIConstants; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import net.sf.gridarta.io.IOUtils; +import org.apache.log4j.Logger; +import org.jdom.DataConversionException; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; +import org.jetbrains.annotations.Nullable; + +/** + * The <code>ArchetypeParser</code> class handles the parsing of arches. It is + * a class separated from ArchetypeSet because it is also involved in + * loading arches in map files. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public final class ArchetypeParser implements net.sf.gridarta.gameobject.ArchetypeParser<GameObject> { + + /** Logger. */ + private static final Logger log = Logger.getLogger(ArchetypeParser.class); + + // name of the system-arch containing path of starting map + public static final String STARTARCH_NAME = "map"; + + // table with type numbers as keys (Integer), and type names as values (String) + private Map<Integer,String> archTypeNumbers; + + private final CMainControl mainControl; + + /** + * Constructor + * @param mainControl main control + */ + public ArchetypeParser(final CMainControl mainControl) { + this.mainControl = mainControl; + archTypeNumbers = null; + } + + /** + * Parse the typenumbers file (associate names with type numbers) + * Type numbers and names are stored as key-value pairs in the + * Hashtable 'archTypeNumbers'. + */ + public void loadTypeNumbers() { + archTypeNumbers = new HashMap<Integer,String>(); + + try { + // open reading stream to the spells xml file + final String baseDir = IGUIConstants.CONFIG_DIR; + final BufferedReader reader = IOUtils.createReader(baseDir, IGUIConstants.TYPENR_FILE); + try { + + // parse xml document + final SAXBuilder builder = new SAXBuilder(); + builder.setValidation(true); + final Document doc = builder.build(reader); + + // retrieve the spell data from the xml + final Element root = doc.getRootElement(); + if (root == null || !"typenumbers".equalsIgnoreCase(root.getName())) { + log.warn("File '" + IGUIConstants.TYPENR_FILE + "' lacks root element 'typenumbers'."); + } else { + final List types = root.getChildren("type"); + if (types == null || types.size() == 0) { + log.warn("File '" + IGUIConstants.TYPENR_FILE + "' has no content."); + } else { + // process all 'type' elements from the xml file + int i; + for (i = 0; i < types.size(); i++) { + final Element typeElem = (Element) types.get(i); + + if (typeElem.getAttribute("number") == null) { + log.warn("In File '" + IGUIConstants.TYPENR_FILE + "': Found 'type' element without 'number'"); + } else if (typeElem.getAttribute("name") == null) { + log.warn("In File '" + IGUIConstants.TYPENR_FILE + "': Found 'type' element without 'name'"); + } else { + try { + // parse type number and -name, then add it to the table 'archTypeNumbers' + archTypeNumbers.put(typeElem.getAttribute("number").getIntValue(), typeElem.getAttribute("name").getValue()); + } catch (final DataConversionException de) { + log.error("In '" + IGUIConstants.TYPENR_FILE + "':\n type number '" + typeElem.getAttribute("number").getValue() + "' is not an integer."); + } + } + } + + // loading successful + if (log.isInfoEnabled()) { + log.info("" + i + " typenumbers loaded."); + } + } + } + } finally { + reader.close(); + } + } catch (final JDOMException e) { + log.error("Parsing error in '" + IGUIConstants.TYPENR_FILE + "'", e); + } catch (final FileNotFoundException e) { + log.error("Cannot read file '" + IGUIConstants.TYPENR_FILE + "'!", e); + } catch (final IOException e) { + log.error("Error while reading file '" + IGUIConstants.TYPENR_FILE + "'!", e); + } + } + + /** + * Lookup the name of an archtype. + * @param index type number + * @return name of this type, as defined in "typenumbers.xml" + */ + public String getArchTypeName(final int index) { + if (archTypeNumbers != null && archTypeNumbers.containsKey(index)) { + return archTypeNumbers.get(index); + } + return "*UNKNOWN" + index + "*"; // this type is unknown + } + + /** {@inheritDoc} */ + public void parseArchetype(final String fname, final int index) { + //Open the file for reading + try { + final BufferedReader in = new BufferedReader(new FileReader(fname)); + try { + parseArchetypeFromStream(in, index, fname); + } finally { + in.close(); + } + } catch (final FileNotFoundException e) { + log.error("Archfile " + fname + " could not be found"); + } catch (final IOException e) { + log.error("IOException in parseDefArch!"); + } + } + + /** {@inheritDoc} */ + public void parseArchetypeFromStream(final BufferedReader in, final int index, final String fname) { + parseArchetypeFromStream(in, null, null, null, index, fname); + } + + /** {@inheritDoc} */ + @Nullable + public GameObject parseArchetypeFromStream(final BufferedReader in, @Nullable final GameObject archetype, final String line, final String archName, int index, final String fname) { + + //Open the file for reading + try { + + // start with new clean GameObject instance + GameObject arch; + GameObject archlast = null; + if (archetype == null) { + arch = new GameObject(); + } else { + arch = archetype.createClone(0, 0); + } + arch.resetObjectText(); + + String thisLine2; + if (line == null) { + thisLine2 = in.readLine(); + } else { + thisLine2 = line; // pre read "Object" from artifacts file loader + } + + boolean msgflag = false; + boolean loreflag = false; + boolean animflag = false; + boolean parsearch = false; + boolean archmore = false; + String oldCat = "<xxx>"; + boolean isNewCategory = true; + GameObject firstArch = null; + String newCat = "no category info"; + int archmoreCount = 0; + while (thisLine2 != null) { + final String thisLine = thisLine2.trim(); + + if (thisLine.startsWith("#")) { + // skip comments + thisLine2 = in.readLine(); + continue; + } + + if (!parsearch) { + + if (thisLine.startsWith("More")) { + if (firstArch == null) { + firstArch = archlast; + } + archmore = true; + } else if (thisLine.startsWith("Object")) { + if (arch == null) { + arch = new GameObject(); + } + + parsearch = true; + if (!archmore) { + firstArch = null; + } + + if (archName == null) { + arch.setArchetypeName(thisLine.substring(7)); + } else { + arch.setArchetypeName(archName); + } + } + } else { + if (msgflag) { + if (thisLine.startsWith("endmsg")) { + msgflag = false; + } else { + arch.addMsgText(thisLine2 + "\n"); // thisLine2 allows leading whitespaces + } + } else if (animflag) { + if (thisLine.startsWith("mina")) { + mainControl.getAnimationObject().addAnimObject(arch.getArchetypeName(), arch.getAnimText()); + + arch.addObjectText("animation " + arch.getArchetypeName() + "\n"); + // here we must add this to AnimationObject + // and add Animation cmd here! + animflag = false; + } else { + arch.addAnimText(thisLine + "\n"); + } + } else if (loreflag) { + if (thisLine.startsWith("endlore")) { + loreflag = false; + } else { + arch.addLoreText(thisLine + "\n"); + } + } else if (thisLine.startsWith("Object")) { + log.error("Find inventory Object in def arch: " + thisLine); + } else if (thisLine.startsWith("end")) { + //if (arch.getArchTypNr() == 0) { + if (log.isDebugEnabled()) { + log.debug("Arch " + arch.getArchetypeName() + " has no type info!"); + } + //} + // we got full arch + parsearch = false; // we write this sucker + + if (firstArch != null) { + // add to head our x/y position so he can setup refmax + firstArch.addTailPart(arch); + } else { + // add arch to the archpanel - only if it is not the map arch + if (!arch.getArchetypeName().equals(STARTARCH_NAME)) { + if (!mainControl.getArchetypeSet().isLoadedFromArchive() || archName != null) { + // loading from individual files, so we simply add it to list + // ArchetypeSet.loadArchFromFiles() takes care of the panels + mainControl.addArchPanelArch(arch.getArchetypeName(), index); + } else { + // loading from collected files, so we need process panels here + if (isNewCategory) { + String folder = newCat; // main folder of new category + if (newCat.indexOf("/") > 0) { + folder = newCat.substring(0, newCat.indexOf("/")); + } + + if (!oldCat.startsWith(folder)) { + // an entire new panel must be opened + mainControl.addArchPanel(folder); + mainControl.addArchPanelCombo("show all"); + mainControl.addArchPanelCombo(folder); + index = 1; + } + + if (newCat.indexOf("/") > 0) { + folder = newCat.substring(newCat.indexOf("/") + 1); + if (newCat.startsWith(folder)) { + index = 1; // add to the base folder + } else if (!oldCat.endsWith(folder)) { + // a new JComboBox must be added + index = mainControl.addArchPanelCombo(folder); + } + } else { + index = 1; // add to the base folder + } + + isNewCategory = false; + oldCat = newCat; + } + mainControl.addArchPanelArch(arch.getArchetypeName(), index); + } + } + } + postParseDefArch(arch); + mainControl.getArchetypeSet().addArchetype(arch); + + archmore = false; // we assume this is last... but perhaps.. + + // if this arch was from Artifacts file - return here: + if (archName != null) { + arch.setArtifact(true); + // here we add all unchanged arch text lines from defArch back to arch + arch.addObjectText(arch.diffArchText(archetype.getObjectText(), true)); + return arch; + } + archlast = arch; + arch = null; + } else { + if (thisLine.startsWith("msg")) { + msgflag = true; + } else if (thisLine.startsWith("animation")) { + arch.addObjectText(thisLine + "\n"); + } else if (thisLine.startsWith("anim_speed")) { + arch.addObjectText(thisLine + "\n"); + } else if (thisLine.startsWith("anim")) { + animflag = true; + } else if (thisLine.equals("lore")) { + loreflag = true; + } else if (thisLine.startsWith("visibility ")) { + if (log.isDebugEnabled()) { + log.debug("Remove visibility: " + arch.getArchetypeName()); + } + } else if (thisLine.startsWith("magicmap ")) { + if (log.isDebugEnabled()) { + log.debug("Remove magicmap: " + arch.getArchetypeName()); + } + } else if (thisLine.startsWith("color_fg ")) { + if (log.isDebugEnabled()) { + log.debug("Remove color_fg: " + arch.getArchetypeName()); + } + } else if (thisLine.startsWith("color_bg ")) { + if (log.isDebugEnabled()) { + log.debug("Remove color_bg: " + arch.getArchetypeName()); + } + } else if (thisLine.startsWith("x ")) { + if (!archmore && !arch.getArchetypeName().equals(STARTARCH_NAME)) { + log.warn("Find x cmd in single tile or head (add it to arch text): " + arch.getArchetypeName()); + arch.addObjectText(thisLine + "\n"); + } + arch.setMultiX(Integer.parseInt(thisLine.substring(2))); + } else if (thisLine.startsWith("y ")) { + if (!archmore && !arch.getArchetypeName().equals(STARTARCH_NAME)) { + log.warn("Find y cmd in single tile or head (add it to arch text): " + arch.getArchetypeName()); + arch.addObjectText(thisLine + "\n"); + } + arch.setMultiY(Integer.parseInt(thisLine.substring(2))); + } else if (thisLine.startsWith("type ")) { + try { + final int i = Integer.parseInt(thisLine.substring(5)); + arch.setArchTypNr(i); + if (i == 0) { + log.warn("Arch " + arch.getArchetypeName() + " type number is zero. (" + thisLine.substring(5) + ")"); + } + } catch (final Exception e) { + log.warn("Arch " + arch.getArchetypeName() + " has a invalid type nr. (" + thisLine.substring(5) + ")"); + arch.addObjectText(thisLine + "\n"); + } + } else if (thisLine.startsWith("face ")) { + int x; + for (x = 4; x < thisLine.length(); x++) { + if (thisLine.charAt(x) != ' ') { + break; + } + } + arch.setFaceFlag(false); // we HAVE a face + arch.setFaceName(thisLine.substring(x, thisLine.length())); + } else if (thisLine.startsWith("editor_folder ")) { + // the display category (= "folder" the arch belongs to) + newCat = thisLine.substring(14).trim(); + if (!newCat.equals(oldCat)) { + isNewCategory = true; // this arch has a new category + } + } + arch.addObjectText(thisLine + "\n"); + if (log.isDebugEnabled()) { + log.debug("add String: " + thisLine); + } + } + } + thisLine2 = in.readLine(); + } // while loop ends here + } catch (final IOException e) { + log.error("Error: ", e); + } + return null; + } + + /** {@inheritDoc} */ + public void postParseDefArch(final GameObject arch) { + final String text = arch.getObjectText(); + arch.resetObjectText(); + final int len = text.length(); + + // if no type was set, zero is taken + if (arch.getArchTypNr() == GameObject.TYPE_UNSET) { + arch.setArchTypNr(0); + } + + boolean scriptflag = false; + for (int i = 0, s = 0; i < len; i++) { + + if (text.charAt(i) == '\n') { + if (i - s > 0) { + if (scriptflag) { + arch.addObjectText(text.substring(s, i) + "\n"); + if (text.regionMatches(s, "end_script_", 0, 11)) { + scriptflag = false; + } + } else if (text.regionMatches(s, "start_script_", 0, 13)) { + arch.addObjectText(text.substring(s, i) + "\n"); + scriptflag = true; + } else if (text.regionMatches(s, "editable ", 0, 9)) { + arch.setEditType(Integer.parseInt(text.substring(s + 9, i))); + } else if (text.regionMatches(s, "name ", 0, 5)) { + arch.setObjName(text.substring(s + 5, i)); + } else { + arch.addObjectText(text.substring(s, i) + "\n"); + } + + } + s = i + 1; + } + } + + // default arches don't get an editType (not worth the time) + // they get one assigned as soon as put on a map though. + arch.setEditType(IGUIConstants.TILE_EDIT_NONE); + } + + /** {@inheritDoc} */ + public void postParseMapArch(final GameObject gameObject, final int editType) { + if (gameObject.getArchetypeName() == null) { + return; + } + + final String text = gameObject.getObjectText(); + final int len = text.length(); + final GameObject archetype = mainControl.getArchetype(gameObject.getArchetypeName()); + + gameObject.resetObjectText(); + for (int i = 0, s = 0; i < len; i++) { + + if (text.charAt(i) == '\n') { + if (i - s > 0) { + if (text.regionMatches(s, "name ", 0, 5)) { + gameObject.setObjName(text.substring(s + 5, i)); + } else { + // this is an unparsed arch attribute, it has to stay in the archtext + gameObject.addObjectText(text.substring(s, i) + "\n"); + } + } + s = i + 1; + } + } + // so, lets check the stuff a last time + + if (gameObject.getFaceName() == null) { + gameObject.setFaceNr(archetype.getFaceNr()); + gameObject.setFaceFlag(archetype.getFaceFlag()); + } + + // if the type is still unset, then we take the default one + if (gameObject.getArchTypNr() == GameObject.TYPE_UNSET) { + gameObject.setArchTypNr(archetype.getArchTypNr()); + } + + gameObject.setMultiX(archetype.getMultiX()); + gameObject.setMultiY(archetype.getMultiY()); + + // arch.setEditType(defarch.getEditType()); + + // validate the ScriptedEvents + gameObject.validateAllEvents(); + + // we don't handle anim yet, so attach then back to archtext + if (gameObject.getAnimText() != null) { + gameObject.addObjectText("anim\n"); + gameObject.addObjectText(gameObject.getAnimText()); + gameObject.addObjectText("mina\n"); + } + + // Finally, we calculate the desired editType of the arch + if (gameObject.isTail()) { + gameObject.setEditType(gameObject.getHead().getEditType()); // copy from head + } else if (editType != 0) { + gameObject.setEditType(gameObject.calculateEditType(editType)); // calculate new + } + } + + /** {@inheritDoc} */ + public void expandMulti(final GameObject gameObject, final List<GameObject> objects) { + // TODO: Couldn't we simply invoke archetype = gameObject.getArchetype() here? + final GameObject archetype = mainControl.getArchetype(gameObject.getArchetypeName()); + + // is it a multi head? + if (archetype != null && archetype.isMulti() && gameObject.getMultiRefCount() <= 1) { + // we have a multi head and need to insert his tail now + + // do insertion for all non-head parts of the multi + for (GameObject oldPart = archetype.getMultiNext(); oldPart != null; oldPart = oldPart.getMultiNext()) { + final GameObject newarch = oldPart.createArch(); + + gameObject.addTailPart(newarch); + objects.add(newarch); +... [truncated message content] |
From: <chr...@us...> - 2006-10-08 23:31:55
|
Revision: 508 http://svn.sourceforge.net/gridarta/?rev=508&view=rev Author: christianhujer Date: 2006-10-08 16:31:45 -0700 (Sun, 08 Oct 2006) Log Message: ----------- Fixed bogus naming of GameObject and Archetype variables. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CAttribDialog.java trunk/daimonin/src/daieditor/CAttribDialog.java Modified: trunk/crossfire/src/cfeditor/CAttribDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-10-08 23:18:57 UTC (rev 507) +++ trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-10-08 23:31:45 UTC (rev 508) @@ -116,7 +116,7 @@ private JTextField nameTF; // textfield for gameObject name - private JTextField defarchTF; // textfield for name of default gameObject + private JTextField archetypeTF; // textfield for name of the Archetype private JLabel imagePanel; // panel for object's face (png) @@ -337,7 +337,7 @@ typesel.setName("Types"); // the listener: - typesel.addItemListener(new TypesBoxAL(this, gameObject, archetype)); + typesel.addItemListener(new TypesBoxAL(this, gameObject)); lineLayout.add(typesel); return lineLayout; @@ -484,9 +484,9 @@ final JPanel layout4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); layout4.add(new JLabel("Archetype: ")); // create label - defarchTF = new JTextField(archetype.getArchetypeName(), 16); - defarchTF.setEditable(false); - layout4.add(defarchTF); + archetypeTF = new JTextField(archetype.getArchetypeName(), 16); + archetypeTF.setEditable(false); + layout4.add(archetypeTF); final JPanel layout5 = new JPanel(); layout5.add(layout4); @@ -1761,10 +1761,8 @@ final CAttribDialog frame; // the entire frame - final GameObject arch; // the according gameObject + final GameObject gameObject; // the according gameObject - final GameObject defarch; // default gameObject of 'gameObject' - String deselected; // the latest deselected item public boolean ignoreEvent; // while true, this listener ignores all events @@ -1772,13 +1770,11 @@ /** * Constructor. * @param frameNew the attribute-dialog mainframe - * @param archNew the gameObject which has the error to be added - * @param defarchNew the default gameObject of 'gameObject' + * @param gameObject the gameObject which has the error to be added */ - public TypesBoxAL(final CAttribDialog frameNew, final GameObject archNew, final GameObject defarchNew) { + public TypesBoxAL(final CAttribDialog frameNew, final GameObject gameObject ) { frame = frameNew; - arch = archNew; - defarch = defarchNew; + this.gameObject = gameObject; ignoreEvent = false; } @@ -1808,7 +1804,7 @@ frame.type = newType; // set new type structure // change the gameObject to be of the new type: - arch.setArchTypNr(newType.getTypeNr()); + gameObject.setArchTypNr(newType.getTypeNr()); attrHead = null; // clear list of attributes listNr = frame.typesel.getSelectedIndex(); @@ -1820,7 +1816,7 @@ frame.update(frame.getGraphics()); // recalculate the editType value - arch.calculateEditType(mainControl.getCurrentMap().getActiveEditType()); + gameObject.calculateEditType(mainControl.getCurrentMap().getActiveEditType()); // also update the gameObject panel (bottom) mainControl.getMainView().refreshMapArchPanel(); // map content has changed Modified: trunk/daimonin/src/daieditor/CAttribDialog.java =================================================================== --- trunk/daimonin/src/daieditor/CAttribDialog.java 2006-10-08 23:18:57 UTC (rev 507) +++ trunk/daimonin/src/daieditor/CAttribDialog.java 2006-10-08 23:31:45 UTC (rev 508) @@ -138,7 +138,7 @@ private JTextField nameTF; // textfield for gameObject name - private JTextField defarchTF; // textfield for name of default gameObject + private JTextField archetypeTF; // textfield for name of the Archetype private JLabel imagePanel; // panel for object's face (png) @@ -460,9 +460,9 @@ gbc.gridy++; header.add(buildTypesBox(), gbc); // build type-selection box gbc.gridy++; - defarchTF = new JTextField(archetype.getArchetypeName(), 16); - defarchTF.setEditable(false); - header.add(defarchTF, gbc); + archetypeTF = new JTextField(archetype.getArchetypeName(), 16); + archetypeTF.setEditable(false); + header.add(archetypeTF, gbc); return header; } @@ -1248,7 +1248,7 @@ imagePanel.setIcon(mainControl.getArchetypeSet().getFace(gameObject.getFaceObjName())); if (newMsg != null) { - // set new msg text only when it is not equal to default gameObject + // set new msg text only when it is not equal to Archetype if (!newMsg.trim().equals(archetype.getMsgText() == null ? "" : archetype.getMsgText().trim())) { gameObject.deleteMsgText(); gameObject.addMsgText(newMsg); @@ -1581,7 +1581,7 @@ private final CAttribDialog frame; // the entire frame - private final GameObject arch; // the according gameObject + private final GameObject gameObject; // the according gameObject private String deselected; // the latest deselected item @@ -1594,7 +1594,7 @@ */ TypesBoxAL(final CAttribDialog frameNew, final GameObject archNew) { frame = frameNew; - arch = archNew; + gameObject = archNew; ignoreEvent = false; } @@ -1624,7 +1624,7 @@ frame.type = newType; // set new type structure // change the gameObject to be of the new type: - arch.setArchTypNr(newType.getTypeNr()); + gameObject.setArchTypNr(newType.getTypeNr()); dialogAttribs.clear(); listNr = frame.typesel.getSelectedIndex(); @@ -1636,7 +1636,7 @@ frame.update(frame.getGraphics()); // recalculate the editType value - arch.calculateEditType(mainControl.getCurrentMap().getActiveEditType()); + gameObject.calculateEditType(mainControl.getCurrentMap().getActiveEditType()); // also update the gameObject panel (bottom) mainControl.getMainView().refreshMapArchPanel(); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-08 23:38:27
|
Revision: 509 http://svn.sourceforge.net/gridarta/?rev=509&view=rev Author: christianhujer Date: 2006-10-08 16:38:11 -0700 (Sun, 08 Oct 2006) Log Message: ----------- Merged common msgText property of GameObjects. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-08 23:31:45 UTC (rev 508) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-08 23:38:11 UTC (rev 509) @@ -66,14 +66,6 @@ /** The name of this object. */ private String objName; - /** - * The msgText. - * @note Every line in msgText must end on '\n', including the last line. - * @note If the value is <code>null</code>, the arch has no message text, - * if the value exists but is empty, the arch has an empty message text (unconfirmed). - */ - @Nullable private StringBuffer msgText; - private StringBuffer animText; // anim text buffer private StringBuffer loreText; // lore text buffer @@ -118,7 +110,7 @@ myId = myIdCounter++; // increase ID counter for every new arch created - msgText = animText = loreText = null; + animText = loreText = null; archTextCount = 0; // lines inserted in objectText objName = null; @@ -638,48 +630,6 @@ return null; } - /** Delete message text by nullification. */ - public void deleteMsgText() { - msgText = null; - } - - /** Delete message text by emptying. */ - public void resetMsgText() { - if (msgText == null) { - return; - } - - msgText.delete(0, msgText.length()); - } - - /** - * Add a line of message text. This is used when creating the GameObject - * from the ArchetypeParser. Special: invoking this method with - * <code>null</code> creates an empty string. - * @param text text to append to message text - */ - public void addMsgText(final String text) { - if (msgText == null) { - msgText = new StringBuffer(); - } - - if (text == null) { - // special, this adds a clear string - // That's why it's after checking msgText for null. - return; - } - - msgText.append(text); - } - - /** - * Get the complete message text. - * @return message text - */ - @Nullable public String getMsgText() { - return msgText != null ? msgText.toString() : null; - } - // ANIMText! public void addAnimText(final String text) { if (animText == null) { Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-08 23:31:45 UTC (rev 508) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-10-08 23:38:11 UTC (rev 509) @@ -78,14 +78,6 @@ private String animName; /** - * The msgText. - * @note Every line in msgText must end on '\n', including the last line. - * @note If the value is <code>null</code>, the arch has no message text, - * if the value exists but is empty, the arch has an empty message text (unconfirmed). - */ - @Nullable private StringBuffer msgText; - - /** * Data for multitile-arches. * Stays null for singlesquare-arches. */ @@ -655,49 +647,7 @@ return null; } - /** Delete message text by nullification. */ - public void deleteMsgText() { - msgText = null; - } - - /** Delete message text by emptying. */ - public void resetMsgText() { - if (msgText == null) { - return; - } - - msgText.delete(0, msgText.length()); - } - /** - * Add a line of message text. This is used when creating the GameObject - * from the ArchetypeParser. Special: invoking this method with - * <code>null</code> creates an empty string. - * @param text text to append to message text - */ - public void addMsgText(final String text) { - if (msgText == null) { - msgText = new StringBuffer(); - } - - if (text == null) { - // special, this adds a clear string - // That's why it's after checking msgText for null. - return; - } - - msgText.append(text); - } - - /** - * Get the complete message text. - * @return message text - */ - @Nullable public String getMsgText() { - return msgText != null ? msgText.toString() : null; - } - - /** * Returns whether the direction is set. <code>true</code> if direction is set, * otherwise <code>false</code>. * @return whether the direction is set. Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-08 23:31:45 UTC (rev 508) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-10-08 23:38:11 UTC (rev 509) @@ -44,6 +44,14 @@ */ @NotNull protected StringBuffer objectText = new StringBuffer(); + /** + * The msgText. + * @note Every line in msgText must end on '\n', including the last line. + * @note If the value is <code>null</code>, the arch has no message text, + * if the value exists but is empty, the arch has an empty message text (unconfirmed). + */ + @Nullable protected StringBuffer msgText; + /** Map x position if on map. */ private int mapx; @@ -531,7 +539,48 @@ */ public abstract void setEditType(int editType); + /** Delete message text by nullification. */ + public void deleteMsgText() { + msgText = null; + } + + /** Delete message text by emptying. */ + public void resetMsgText() { + if (msgText == null) { + return; + } + + msgText.delete(0, msgText.length()); + } + /** + * Add a line of message text. This is used when creating the GameObject + * from the ArchetypeParser. Special: invoking this method with + * <code>null</code> creates an empty string. + * @param text text to append to message text + */ + public void addMsgText(final String text) { + if (msgText == null) { + msgText = new StringBuffer(); + } + + if (text == null) { + // special, this adds a clear string + // That's why it's after checking msgText for null. + return; + } + + msgText.append(text); + } + + /** + * Get the complete message text. + * @return message text + */ + @Nullable public String getMsgText() { + return msgText != null ? msgText.toString() : null; + } + /** * Get the X coordinate of this GameObject on its map. * This method only guarantees a reasonable value for GameObjects that are directly bound to a map (i.e. {@link #getTopContainer()} returns <code>null</code>). * Implementations may also return reasonable values for GameObjects inside containers, but they are not required to do so. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |