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. |