From: <aki...@us...> - 2008-10-16 16:47:59
|
Revision: 5538 http://gridarta.svn.sourceforge.net/gridarta/?rev=5538&view=rev Author: akirschbaum Date: 2008-10-16 16:47:53 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Split off AbstractScriptArchData and DefaultScriptArchData from ScriptArchData. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 16:43:03 UTC (rev 5537) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 16:47:53 UTC (rev 5538) @@ -27,7 +27,7 @@ import cfeditor.gameobject.DefaultGameObjectFactory; import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObjects; -import cfeditor.gameobject.scripts.ScriptArchData; +import cfeditor.gameobject.scripts.DefaultScriptArchData; import cfeditor.gameobject.scripts.ScriptArchUtils; import cfeditor.gui.map.CMapViewBasic; import cfeditor.gui.map.DefaultMapPropertiesDialogFactory; @@ -135,8 +135,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptArchData newScriptArchData(@NotNull final net.sf.gridarta.gameobject.scripts.ScriptArchUtils scriptArchUtils) { - return new ScriptArchData(scriptArchUtils, "subtype", Archetype.TYPE_EVENT_CONNECTOR); + protected DefaultScriptArchData newScriptArchData(@NotNull final net.sf.gridarta.gameobject.scripts.ScriptArchUtils scriptArchUtils) { + return new DefaultScriptArchData(scriptArchUtils, "subtype", Archetype.TYPE_EVENT_CONNECTOR); } /** {@inheritDoc} */ Copied: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java (from rev 5534, trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java) =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 16:47:53 UTC (rev 5538) @@ -0,0 +1,76 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package cfeditor.gameobject.scripts; + +import cfeditor.gameobject.GameObject; +import javax.swing.JDialog; +import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; +import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; +import org.jetbrains.annotations.NotNull; + +/** + * Stores and manages information about scripted events. This data is only + * needed for those arches with one or more events defined. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @xxx This class is designed very badly, as it combines model and + * presentation. + */ +public final class DefaultScriptArchData extends AbstractScriptArchData<GameObject> { + + /** Serial Version. */ + private static final long serialVersionUID = 1L; + + /** + * The {@link ScriptArchUtils} instance to use. + */ + @NotNull + private final ScriptArchUtils scriptArchUtils; + + /** + * Create a ScriptArchData. + * @param scriptArchUtils the script arch utils instance to use + * @param subtypeAttribute the attribute name for the subtype field + * @param eventTypeNo the object type for event objects + */ + public DefaultScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final String subtypeAttribute, final int eventTypeNo) { + super(subtypeAttribute, eventTypeNo); + this.scriptArchUtils = scriptArchUtils; + } + + /** {@inheritDoc} */ + @NotNull + @Override + protected ScriptedEvent newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { + return new ScriptedEvent(scriptArchUtils, event, subtypeAttribute); + } + + /** {@inheritDoc} */ + public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { + ScriptArchEditor.createNewEvent(frame, this, gameObject); + } + + /** {@inheritDoc} */ + @NotNull + @Override + protected String typeName(final int attributeInt) { + return scriptArchUtils.typeName(attributeInt); + } + +} // class DefaultScriptArchData Property changes on: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-10-16 16:43:03 UTC (rev 5537) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-10-16 16:47:53 UTC (rev 5538) @@ -1,75 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package cfeditor.gameobject.scripts; - -import cfeditor.gameobject.GameObject; -import javax.swing.JDialog; -import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; -import org.jetbrains.annotations.NotNull; - -/** - * Stores and manages information about scripted events. This data is only - * needed for those arches with one or more events defined. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @xxx This class is designed very badly, as it combines model and - * presentation. - */ -public final class ScriptArchData extends net.sf.gridarta.gameobject.scripts.ScriptArchData<GameObject> { - - /** Serial Version. */ - private static final long serialVersionUID = 1L; - - /** - * The {@link ScriptArchUtils} instance to use. - */ - @NotNull - private final ScriptArchUtils scriptArchUtils; - - /** - * Create a ScriptArchData. - * @param scriptArchUtils the script arch utils instance to use - * @param subtypeAttribute the attribute name for the subtype field - * @param eventTypeNo the object type for event objects - */ - public ScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final String subtypeAttribute, final int eventTypeNo) { - super(subtypeAttribute, eventTypeNo); - this.scriptArchUtils = scriptArchUtils; - } - - /** {@inheritDoc} */ - @NotNull - @Override - protected ScriptedEvent newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { - return new ScriptedEvent(scriptArchUtils, event, subtypeAttribute); - } - - /** {@inheritDoc} */ - public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { - ScriptArchEditor.createNewEvent(frame, this, gameObject); - } - - /** {@inheritDoc} */ - @NotNull - @Override - protected String typeName(final int attributeInt) { - return scriptArchUtils.typeName(attributeInt); - } - -} // class ScriptArchData Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-10-16 16:43:03 UTC (rev 5537) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-10-16 16:47:53 UTC (rev 5538) @@ -35,7 +35,7 @@ /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - public static void createNewEvent(final JDialog frame, final ScriptArchData scriptArchData, @NotNull final GameObject gameObject) { + public static void createNewEvent(final JDialog frame, final DefaultScriptArchData scriptArchData, @NotNull final GameObject gameObject) { String scriptPath = inputScriptPath.getText().trim(); final String options = inputOptions.getText().trim(); final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 16:43:03 UTC (rev 5537) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 16:47:53 UTC (rev 5538) @@ -27,7 +27,7 @@ import daieditor.gameobject.DefaultGameObjectFactory; import daieditor.gameobject.GameObject; import daieditor.gameobject.anim.AnimationObjects; -import daieditor.gameobject.scripts.ScriptArchData; +import daieditor.gameobject.scripts.DefaultScriptArchData; import daieditor.gameobject.scripts.ScriptArchUtils; import daieditor.gui.map.CMapViewBasic; import daieditor.gui.map.DefaultMapPropertiesDialogFactory; @@ -180,8 +180,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptArchData newScriptArchData(@NotNull final net.sf.gridarta.gameobject.scripts.ScriptArchUtils scriptArchUtils) { - return new ScriptArchData(scriptArchUtils, "sub_type", Archetype.TYPE_EVENT_OBJECT); + protected DefaultScriptArchData newScriptArchData(@NotNull final net.sf.gridarta.gameobject.scripts.ScriptArchUtils scriptArchUtils) { + return new DefaultScriptArchData(scriptArchUtils, "sub_type", Archetype.TYPE_EVENT_OBJECT); } /** {@inheritDoc} */ Copied: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java (from rev 5534, trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java) =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java (rev 0) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 16:47:53 UTC (rev 5538) @@ -0,0 +1,76 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package daieditor.gameobject.scripts; + +import daieditor.gameobject.GameObject; +import javax.swing.JDialog; +import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; +import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; +import org.jetbrains.annotations.NotNull; + +/** + * Stores and manages information about scripted events. This data is only + * needed for those arches with one or more events defined. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @xxx This class is designed very badly, as it combines model and + * presentation. + */ +public final class DefaultScriptArchData extends AbstractScriptArchData<GameObject> { + + /** Serial Version. */ + private static final long serialVersionUID = 1L; + + /** + * The {@link ScriptArchUtils} instance to use. + */ + @NotNull + private final ScriptArchUtils scriptArchUtils; + + /** + * Create a ScriptArchData. + * @param scriptArchUtils the script arch utils instance to use + * @param subtypeAttribute the attribute name for the subtype field + * @param eventTypeNo the object type for event objects + */ + public DefaultScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final String subtypeAttribute, final int eventTypeNo) { + super(subtypeAttribute, eventTypeNo); + this.scriptArchUtils = scriptArchUtils; + } + + /** {@inheritDoc} */ + @NotNull + @Override + protected ScriptedEvent newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { + return new ScriptedEvent(scriptArchUtils, event, subtypeAttribute); + } + + /** {@inheritDoc} */ + public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { + ScriptArchEditor.createNewEvent(frame, this, gameObject); + } + + /** {@inheritDoc} */ + @NotNull + @Override + protected String typeName(final int attributeInt) { + return scriptArchUtils.typeName(attributeInt); + } + +} // class DefaultScriptArchData Property changes on: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-10-16 16:43:03 UTC (rev 5537) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-10-16 16:47:53 UTC (rev 5538) @@ -1,75 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor.gameobject.scripts; - -import daieditor.gameobject.GameObject; -import javax.swing.JDialog; -import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; -import org.jetbrains.annotations.NotNull; - -/** - * Stores and manages information about scripted events. This data is only - * needed for those arches with one or more events defined. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @xxx This class is designed very badly, as it combines model and - * presentation. - */ -public final class ScriptArchData extends net.sf.gridarta.gameobject.scripts.ScriptArchData<GameObject> { - - /** Serial Version. */ - private static final long serialVersionUID = 1L; - - /** - * The {@link ScriptArchUtils} instance to use. - */ - @NotNull - private final ScriptArchUtils scriptArchUtils; - - /** - * Create a ScriptArchData. - * @param scriptArchUtils the script arch utils instance to use - * @param subtypeAttribute the attribute name for the subtype field - * @param eventTypeNo the object type for event objects - */ - public ScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final String subtypeAttribute, final int eventTypeNo) { - super(subtypeAttribute, eventTypeNo); - this.scriptArchUtils = scriptArchUtils; - } - - /** {@inheritDoc} */ - @NotNull - @Override - protected ScriptedEvent newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { - return new ScriptedEvent(scriptArchUtils, event, subtypeAttribute); - } - - /** {@inheritDoc} */ - public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { - ScriptArchEditor.createNewEvent(frame, this, gameObject); - } - - /** {@inheritDoc} */ - @NotNull - @Override - protected String typeName(final int attributeInt) { - return scriptArchUtils.typeName(attributeInt); - } - -} // class ScriptArchData Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-10-16 16:43:03 UTC (rev 5537) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-10-16 16:47:53 UTC (rev 5538) @@ -35,7 +35,7 @@ /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - public static void createNewEvent(final JDialog frame, final ScriptArchData scriptArchData, @NotNull final GameObject gameObject) { + public static void createNewEvent(final JDialog frame, final DefaultScriptArchData scriptArchData, @NotNull final GameObject gameObject) { String scriptPath = inputScriptPath.getText().trim(); final String options = inputOptions.getText().trim(); final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); Copied: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java (from rev 5532, trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptArchData.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-16 16:47:53 UTC (rev 5538) @@ -0,0 +1,174 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gameobject.scripts; + +import java.awt.Frame; +import java.io.Serializable; +import java.util.Iterator; +import java.util.Vector; +import javax.swing.JList; +import javax.swing.JOptionPane; +import net.sf.gridarta.MapManager; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gui.gameobjectattributespanel.ScriptTab; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Stores and manages information about scripted events. This data is only + * needed for those arches with one or more events defined. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @xxx This class is designed very badly, as it combines model and + * presentation. + */ +public abstract class AbstractScriptArchData<G extends GameObject<G, ?, ?>> implements ScriptArchData<G>, Serializable { + + /** The serial version UID. */ + private static final long serialVersionUID = 1; + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(AbstractScriptArchData.class); + + /** + * The attribute name for the subtype field. + */ + @NotNull + private final String subtypeAttribute; + + /** + * The object type for event objects. + */ + private final int eventTypeNo; + + /** + * Create a ScriptArchData. + * @param subtypeAttribute the attribute name for the subtype field + * @param eventTypeNo the object type for event objects + */ + protected AbstractScriptArchData(@NotNull final String subtypeAttribute, final int eventTypeNo) { + this.subtypeAttribute = subtypeAttribute; + this.eventTypeNo = eventTypeNo; + } + + /** {@inheritDoc} */ + public void addEventsToJList(final JList list, @NotNull final G gameObject) { + //cher: JList expects Vector, so we MUST use an obsolete concrete collection. + //noinspection CollectionDeclaredAsConcreteClass,UseOfObsoleteCollectionType + final Vector<String> content = new Vector<String>(); + for (final G tmp : gameObject) { + if (tmp.getTypeNo() == eventTypeNo) { + content.add(" " + typeName(tmp.getAttributeInt(subtypeAttribute))); + } + } + + list.setListData(content); + list.setSelectedIndex(0); + } + + /** + * Returns a description for a script type. + * @param attributeInt the script type + * @return the description + */ + @NotNull + protected abstract String typeName(final int attributeInt); + + /** {@inheritDoc} */ + @Nullable + public G getScriptedEvent(final int eventSubtype, @NotNull final G gameObject) { + for (final G tmp : gameObject) { + if (tmp.getTypeNo() == eventTypeNo && tmp.getAttributeInt(subtypeAttribute) == eventSubtype) { + return tmp; + } + } + return null; + } + + /** {@inheritDoc} */ + public void validateAllEvents(@NotNull final G gameObject) { + final Iterator<G> it = gameObject.iterator(); + while (it.hasNext()) { + final G tmp = it.next(); + if (tmp.getTypeNo() == eventTypeNo) { + final ScriptedEvent<G> se = newScriptedEvent(tmp, subtypeAttribute); + // validate this event + if (!se.isValid()) { + // this event is invalid + if (log.isInfoEnabled()) { + log.info("-> Deleting invalid event..."); + } + it.remove(); + } + } + } + } + + /** {@inheritDoc} */ + public boolean isEmpty(@NotNull final G gameObject) { + for (final G tmp : gameObject) { + if (tmp.getTypeNo() == eventTypeNo) { + return false; + } + } + return true; + } + + + /** {@inheritDoc} */ + public void modifyEventScript(int eventIndex, final int task, @NotNull final JList panelList, @NotNull final MapManager<?, ?, ?, ?> mapManager, @NotNull final Frame parent, @NotNull final G gameObject) { + G oldEvent = null; + + /* Find the event object */ + for (final G tmp : gameObject) { + if (tmp.getTypeNo() == eventTypeNo) { + if (eventIndex == 0) { + oldEvent = tmp; + break; + } else { + eventIndex--; + } + } + } + + if (oldEvent != null) { + final ScriptedEvent<G> event = newScriptedEvent(oldEvent, subtypeAttribute); + // now decide what to do: + if (task == ScriptTab.SCRIPT_OPEN) { + ScriptedEventEditor.openScript(mapManager, event.getScriptPath(), parent); + } else if (task == ScriptTab.SCRIPT_EDIT_PATH) { + ScriptedEventEditor.editParameters(event, parent); + } else if (task == ScriptTab.SCRIPT_REMOVE) { + // first ask for confirmation + if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { + // remove this event from the GameObject + oldEvent.remove(); + addEventsToJList(panelList, gameObject); // update panel JList + } + } + } else { + log.error("Error in modifyEventScript(): No event selected?"); + } + } + + @NotNull + protected abstract ScriptedEvent<G> newScriptedEvent(@NotNull final G event, @NotNull final String subtypeAttribute); + +} // class AbstractScriptArchData Property changes on: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-16 16:52:11
|
Revision: 5539 http://gridarta.svn.sourceforge.net/gridarta/?rev=5539&view=rev Author: akirschbaum Date: 2008-10-16 16:52:08 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Rename ScriptArchEditor to DefaultScriptArchEditor. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 16:47:53 UTC (rev 5538) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 16:52:08 UTC (rev 5539) @@ -63,7 +63,7 @@ /** {@inheritDoc} */ public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { - ScriptArchEditor.createNewEvent(frame, this, gameObject); + DefaultScriptArchEditor.createNewEvent(frame, this, gameObject); } /** {@inheritDoc} */ Copied: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java (from rev 5538, trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java) =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 16:52:08 UTC (rev 5539) @@ -0,0 +1,141 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package cfeditor.gameobject.scripts; + +import cfeditor.gameobject.GameObject; +import java.io.File; +import java.io.IOException; +import javax.swing.JDialog; +import javax.swing.JOptionPane; +import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; +import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; + +public class DefaultScriptArchEditor extends AbstractScriptArchEditor { + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + + public static void createNewEvent(final JDialog frame, final DefaultScriptArchData scriptArchData, @NotNull final GameObject gameObject) { + String scriptPath = inputScriptPath.getText().trim(); + final String options = inputOptions.getText().trim(); + final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); + final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); + + final File localMapDir = mapManager.getLocalMapDir(); + + // first check if that event type is not already in use + final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType, gameObject); + if (replaceObject != null) { + // collision with existing event -> ask user: replace? + if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + scriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { + // bail out + return; + } + } + + // convert localized scriptPath into real, absolute path + scriptPath = scriptPath.replace('\\', '/'); + String absScriptPath; + if (scriptPath.startsWith("/")) { + // script path is absolute + final File mapDir = new File(globalSettings.getMapDefaultFolder()); // global map directory + if (!mapDir.exists()) { + // if map dir doesn't exist, this is not going to work + frame.setVisible(false); + ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); + return; + } else { + absScriptPath = mapDir.getAbsolutePath() + scriptPath; + } + } else { + // script path is relative + absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; + } + + // now check if the specified path points to an existing script + File newScriptFile = new File(absScriptPath); + if (!newScriptFile.exists() && !absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; + newScriptFile = new File(absScriptPath); + } + + if (newScriptFile.exists()) { + if (newScriptFile.isFile()) { + // file exists -> link it to the event + final ScriptedEvent event; + try { + event = new ScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); + } catch (final UndefinedEventArchetypeException ex) { + JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); + return; + } + if (replaceObject != null) { + replaceObject.remove(); + } + gameObject.addLast(event.getEventArch()); + frame.setVisible(false); // close dialog + } + } else { + if (!absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; + newScriptFile = new File(absScriptPath); + } + + // file does not exist -> aks user: create new file? + if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { + // okay, create new script file and open it + boolean couldCreateFile = false; // true when file creation successful + try { + // try to create new empty file + couldCreateFile = newScriptFile.createNewFile(); + } catch (final IOException e) { + /* ignore (really?) */ + } + + if (!couldCreateFile) { + JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); + } else { + // file has been created, now link it to the event + final ScriptedEvent event; + try { + event = new ScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); + } catch (final UndefinedEventArchetypeException ex) { + JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); + return; + } + if (replaceObject != null) { + replaceObject.remove(); + } + gameObject.addLast(event.getEventArch()); + frame.setVisible(false); // close dialog + + // open new script file + ScriptEditControlInstance.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); + } + } + } + } + +} // class DefaultScriptArchEditor Property changes on: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-10-16 16:47:53 UTC (rev 5538) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-10-16 16:52:08 UTC (rev 5539) @@ -1,141 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package cfeditor.gameobject.scripts; - -import cfeditor.gameobject.GameObject; -import java.io.File; -import java.io.IOException; -import javax.swing.JDialog; -import javax.swing.JOptionPane; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; -import net.sf.japi.swing.ActionFactory; -import org.jetbrains.annotations.NotNull; - -public class ScriptArchEditor extends AbstractScriptArchEditor { - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - public static void createNewEvent(final JDialog frame, final DefaultScriptArchData scriptArchData, @NotNull final GameObject gameObject) { - String scriptPath = inputScriptPath.getText().trim(); - final String options = inputOptions.getText().trim(); - final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); - final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); - - final File localMapDir = mapManager.getLocalMapDir(); - - // first check if that event type is not already in use - final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType, gameObject); - if (replaceObject != null) { - // collision with existing event -> ask user: replace? - if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + scriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { - // bail out - return; - } - } - - // convert localized scriptPath into real, absolute path - scriptPath = scriptPath.replace('\\', '/'); - String absScriptPath; - if (scriptPath.startsWith("/")) { - // script path is absolute - final File mapDir = new File(globalSettings.getMapDefaultFolder()); // global map directory - if (!mapDir.exists()) { - // if map dir doesn't exist, this is not going to work - frame.setVisible(false); - ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); - return; - } else { - absScriptPath = mapDir.getAbsolutePath() + scriptPath; - } - } else { - // script path is relative - absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; - } - - // now check if the specified path points to an existing script - File newScriptFile = new File(absScriptPath); - if (!newScriptFile.exists() && !absScriptPath.endsWith(scriptEnding)) { - absScriptPath += scriptEnding; - scriptPath += scriptEnding; - newScriptFile = new File(absScriptPath); - } - - if (newScriptFile.exists()) { - if (newScriptFile.isFile()) { - // file exists -> link it to the event - final ScriptedEvent event; - try { - event = new ScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return; - } - if (replaceObject != null) { - replaceObject.remove(); - } - gameObject.addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - } - } else { - if (!absScriptPath.endsWith(scriptEnding)) { - absScriptPath += scriptEnding; - scriptPath += scriptEnding; - newScriptFile = new File(absScriptPath); - } - - // file does not exist -> aks user: create new file? - if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { - // okay, create new script file and open it - boolean couldCreateFile = false; // true when file creation successful - try { - // try to create new empty file - couldCreateFile = newScriptFile.createNewFile(); - } catch (final IOException e) { - /* ignore (really?) */ - } - - if (!couldCreateFile) { - JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); - } else { - // file has been created, now link it to the event - final ScriptedEvent event; - try { - event = new ScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return; - } - if (replaceObject != null) { - replaceObject.remove(); - } - gameObject.addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - - // open new script file - ScriptEditControlInstance.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); - } - } - } - } - -} // class ScriptArchEditor Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 16:47:53 UTC (rev 5538) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 16:52:08 UTC (rev 5539) @@ -63,7 +63,7 @@ /** {@inheritDoc} */ public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { - ScriptArchEditor.createNewEvent(frame, this, gameObject); + DefaultScriptArchEditor.createNewEvent(frame, this, gameObject); } /** {@inheritDoc} */ Copied: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java (from rev 5538, trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java) =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java (rev 0) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 16:52:08 UTC (rev 5539) @@ -0,0 +1,141 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package daieditor.gameobject.scripts; + +import daieditor.gameobject.GameObject; +import java.io.File; +import java.io.IOException; +import javax.swing.JDialog; +import javax.swing.JOptionPane; +import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; +import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; + +public class DefaultScriptArchEditor extends AbstractScriptArchEditor { + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + + public static void createNewEvent(final JDialog frame, final DefaultScriptArchData scriptArchData, @NotNull final GameObject gameObject) { + String scriptPath = inputScriptPath.getText().trim(); + final String options = inputOptions.getText().trim(); + final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); + final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); + + final File localMapDir = mapManager.getLocalMapDir(); + + // first check if that event type is not already in use + final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType, gameObject); + if (replaceObject != null) { + // collision with existing event -> ask user: replace? + if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + scriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { + // bail out + return; + } + } + + // convert localized scriptPath into real, absolute path + scriptPath = scriptPath.replace('\\', '/'); + String absScriptPath; + if (scriptPath.startsWith("/")) { + // script path is absolute + final File mapDir = new File(globalSettings.getMapDefaultFolder()); // global map directory + if (!mapDir.exists()) { + // if map dir doesn't exist, this is not going to work + frame.setVisible(false); + ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); + return; + } else { + absScriptPath = mapDir.getAbsolutePath() + scriptPath; + } + } else { + // script path is relative + absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; + } + + // now check if the specified path points to an existing script + File newScriptFile = new File(absScriptPath); + if (!newScriptFile.exists() && !absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; + newScriptFile = new File(absScriptPath); + } + + if (newScriptFile.exists()) { + if (newScriptFile.isFile()) { + // file exists -> link it to the event + final ScriptedEvent event; + try { + event = new ScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); + } catch (final UndefinedEventArchetypeException ex) { + JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); + return; + } + if (replaceObject != null) { + replaceObject.remove(); + } + gameObject.addLast(event.getEventArch()); + frame.setVisible(false); // close dialog + } + } else { + if (!absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; + newScriptFile = new File(absScriptPath); + } + + // file does not exist -> aks user: create new file? + if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { + // okay, create new script file and open it + boolean couldCreateFile = false; // true when file creation successful + try { + // try to create new empty file + couldCreateFile = newScriptFile.createNewFile(); + } catch (final IOException e) { + /* ignore (really?) */ + } + + if (!couldCreateFile) { + JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); + } else { + // file has been created, now link it to the event + final ScriptedEvent event; + try { + event = new ScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); + } catch (final UndefinedEventArchetypeException ex) { + JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); + return; + } + if (replaceObject != null) { + replaceObject.remove(); + } + gameObject.addLast(event.getEventArch()); + frame.setVisible(false); // close dialog + + // open new script file + ScriptEditControlInstance.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); + } + } + } + } + +} // class DefaultScriptArchEditor Property changes on: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-10-16 16:47:53 UTC (rev 5538) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-10-16 16:52:08 UTC (rev 5539) @@ -1,141 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor.gameobject.scripts; - -import daieditor.gameobject.GameObject; -import java.io.File; -import java.io.IOException; -import javax.swing.JDialog; -import javax.swing.JOptionPane; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; -import net.sf.japi.swing.ActionFactory; -import org.jetbrains.annotations.NotNull; - -public class ScriptArchEditor extends AbstractScriptArchEditor { - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - - public static void createNewEvent(final JDialog frame, final DefaultScriptArchData scriptArchData, @NotNull final GameObject gameObject) { - String scriptPath = inputScriptPath.getText().trim(); - final String options = inputOptions.getText().trim(); - final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); - final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); - - final File localMapDir = mapManager.getLocalMapDir(); - - // first check if that event type is not already in use - final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType, gameObject); - if (replaceObject != null) { - // collision with existing event -> ask user: replace? - if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + scriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { - // bail out - return; - } - } - - // convert localized scriptPath into real, absolute path - scriptPath = scriptPath.replace('\\', '/'); - String absScriptPath; - if (scriptPath.startsWith("/")) { - // script path is absolute - final File mapDir = new File(globalSettings.getMapDefaultFolder()); // global map directory - if (!mapDir.exists()) { - // if map dir doesn't exist, this is not going to work - frame.setVisible(false); - ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); - return; - } else { - absScriptPath = mapDir.getAbsolutePath() + scriptPath; - } - } else { - // script path is relative - absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; - } - - // now check if the specified path points to an existing script - File newScriptFile = new File(absScriptPath); - if (!newScriptFile.exists() && !absScriptPath.endsWith(scriptEnding)) { - absScriptPath += scriptEnding; - scriptPath += scriptEnding; - newScriptFile = new File(absScriptPath); - } - - if (newScriptFile.exists()) { - if (newScriptFile.isFile()) { - // file exists -> link it to the event - final ScriptedEvent event; - try { - event = new ScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return; - } - if (replaceObject != null) { - replaceObject.remove(); - } - gameObject.addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - } - } else { - if (!absScriptPath.endsWith(scriptEnding)) { - absScriptPath += scriptEnding; - scriptPath += scriptEnding; - newScriptFile = new File(absScriptPath); - } - - // file does not exist -> aks user: create new file? - if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { - // okay, create new script file and open it - boolean couldCreateFile = false; // true when file creation successful - try { - // try to create new empty file - couldCreateFile = newScriptFile.createNewFile(); - } catch (final IOException e) { - /* ignore (really?) */ - } - - if (!couldCreateFile) { - JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); - } else { - // file has been created, now link it to the event - final ScriptedEvent event; - try { - event = new ScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return; - } - if (replaceObject != null) { - replaceObject.remove(); - } - gameObject.addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - - // open new script file - ScriptEditControlInstance.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); - } - } - } - } - -} // class ScriptArchEditor This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-16 16:57:46
|
Revision: 5540 http://gridarta.svn.sourceforge.net/gridarta/?rev=5540&view=rev Author: akirschbaum Date: 2008-10-16 16:57:43 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Rename ScriptArchUtils to DefaultScriptArchUtils. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CMainControl.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchUtils.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchUtils.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 16:52:08 UTC (rev 5539) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 16:57:43 UTC (rev 5540) @@ -28,7 +28,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObjects; import cfeditor.gameobject.scripts.DefaultScriptArchData; -import cfeditor.gameobject.scripts.ScriptArchUtils; +import cfeditor.gameobject.scripts.DefaultScriptArchUtils; import cfeditor.gui.map.CMapViewBasic; import cfeditor.gui.map.DefaultMapPropertiesDialogFactory; import cfeditor.gui.map.DefaultMapViewFactory; @@ -128,8 +128,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptArchUtils newScriptArchUtils() { - return new ScriptArchUtils(); + protected DefaultScriptArchUtils newScriptArchUtils() { + return new DefaultScriptArchUtils(); } /** {@inheritDoc} */ Copied: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchUtils.java (from rev 5537, trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java) =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchUtils.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchUtils.java 2008-10-16 16:57:43 UTC (rev 5540) @@ -0,0 +1,55 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package cfeditor.gameobject.scripts; + +import net.sf.gridarta.gameobject.scripts.AbstractScriptArchUtils; +import org.jetbrains.annotations.Nullable; + +public class DefaultScriptArchUtils extends AbstractScriptArchUtils { + + /** + * Creates a new instance. + */ + public DefaultScriptArchUtils() { + // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. + add(1, "apply"); + add(2, "attack"); + add(3, "death"); + add(4, "drop"); + add(5, "pickup"); + add(6, "say"); + add(7, "stop"); + add(8, "time"); + add(9, "throw"); + add(10, "trigger"); + add(11, "close"); + add(12, "timer"); + add(13, "destroy"); + add(31, "user"); + } + + /** {@inheritDoc} */ + @Nullable + public String getArchetypeNameForEventType(final int eventType) { + final String typeName = allEventTypes.get(eventType); + return typeName != null ? "event_" + typeName : null; + } + +} // class DefaultScriptArchUtils Property changes on: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchUtils.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java 2008-10-16 16:52:08 UTC (rev 5539) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java 2008-10-16 16:57:43 UTC (rev 5540) @@ -1,55 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package cfeditor.gameobject.scripts; - -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchUtils; -import org.jetbrains.annotations.Nullable; - -public class ScriptArchUtils extends AbstractScriptArchUtils { - - /** - * Creates a new instance. - */ - public ScriptArchUtils() { - // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. - add(1, "apply"); - add(2, "attack"); - add(3, "death"); - add(4, "drop"); - add(5, "pickup"); - add(6, "say"); - add(7, "stop"); - add(8, "time"); - add(9, "throw"); - add(10, "trigger"); - add(11, "close"); - add(12, "timer"); - add(13, "destroy"); - add(31, "user"); - } - - /** {@inheritDoc} */ - @Nullable - public String getArchetypeNameForEventType(final int eventType) { - final String typeName = allEventTypes.get(eventType); - return typeName != null ? "event_" + typeName : null; - } - -} // class ScriptArchUtils Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 16:52:08 UTC (rev 5539) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 16:57:43 UTC (rev 5540) @@ -28,7 +28,7 @@ import daieditor.gameobject.GameObject; import daieditor.gameobject.anim.AnimationObjects; import daieditor.gameobject.scripts.DefaultScriptArchData; -import daieditor.gameobject.scripts.ScriptArchUtils; +import daieditor.gameobject.scripts.DefaultScriptArchUtils; import daieditor.gui.map.CMapViewBasic; import daieditor.gui.map.DefaultMapPropertiesDialogFactory; import daieditor.gui.map.DefaultMapViewFactory; @@ -173,8 +173,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptArchUtils newScriptArchUtils() { - return new ScriptArchUtils(); + protected DefaultScriptArchUtils newScriptArchUtils() { + return new DefaultScriptArchUtils(); } /** {@inheritDoc} */ Copied: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchUtils.java (from rev 5537, trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java) =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchUtils.java (rev 0) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchUtils.java 2008-10-16 16:57:43 UTC (rev 5540) @@ -0,0 +1,53 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package daieditor.gameobject.scripts; + +import net.sf.gridarta.gameobject.scripts.AbstractScriptArchUtils; +import org.jetbrains.annotations.Nullable; + +public class DefaultScriptArchUtils extends AbstractScriptArchUtils { + + /** + * Creates a new instance. + */ + public DefaultScriptArchUtils() { + // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. + add(1, "apply"); + add(2, "attack"); + add(3, "death"); + add(4, "drop"); + add(5, "pickup"); + add(6, "say"); + add(7, "stop"); + add(8, "time (don't use)"); + add(9, "throw"); + add(10, "trigger"); + add(11, "close"); + add(12, "examine"); + add(13, "talk"); + } + + /** {@inheritDoc} */ + @Nullable + public String getArchetypeNameForEventType(final int eventType) { + return "event_obj"; + } + +} // class DefaultScriptArchUtils Property changes on: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchUtils.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java 2008-10-16 16:52:08 UTC (rev 5539) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java 2008-10-16 16:57:43 UTC (rev 5540) @@ -1,53 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor.gameobject.scripts; - -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchUtils; -import org.jetbrains.annotations.Nullable; - -public class ScriptArchUtils extends AbstractScriptArchUtils { - - /** - * Creates a new instance. - */ - public ScriptArchUtils() { - // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. - add(1, "apply"); - add(2, "attack"); - add(3, "death"); - add(4, "drop"); - add(5, "pickup"); - add(6, "say"); - add(7, "stop"); - add(8, "time (don't use)"); - add(9, "throw"); - add(10, "trigger"); - add(11, "close"); - add(12, "examine"); - add(13, "talk"); - } - - /** {@inheritDoc} */ - @Nullable - public String getArchetypeNameForEventType(final int eventType) { - return "event_obj"; - } - -} // class ScriptArchUtils This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-16 16:59:50
|
Revision: 5541 http://gridarta.svn.sourceforge.net/gridarta/?rev=5541&view=rev Author: akirschbaum Date: 2008-10-16 16:59:48 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Rename ScriptedEvent to DefaultScriptedEvent. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEvent.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 16:57:43 UTC (rev 5540) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 16:59:48 UTC (rev 5541) @@ -57,8 +57,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptedEvent newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { - return new ScriptedEvent(scriptArchUtils, event, subtypeAttribute); + protected DefaultScriptedEvent newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { + return new DefaultScriptedEvent(scriptArchUtils, event, subtypeAttribute); } /** {@inheritDoc} */ Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 16:57:43 UTC (rev 5540) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 16:59:48 UTC (rev 5541) @@ -83,9 +83,9 @@ if (newScriptFile.exists()) { if (newScriptFile.isFile()) { // file exists -> link it to the event - final ScriptedEvent event; + final DefaultScriptedEvent event; try { - event = new ScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); + event = new DefaultScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; @@ -118,9 +118,9 @@ JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); } else { // file has been created, now link it to the event - final ScriptedEvent event; + final DefaultScriptedEvent event; try { - event = new ScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); + event = new DefaultScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; Copied: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEvent.java (from rev 5537, trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java) =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEvent.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEvent.java 2008-10-16 16:59:48 UTC (rev 5541) @@ -0,0 +1,185 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package cfeditor.gameobject.scripts; + +import cfeditor.gameobject.Archetype; +import cfeditor.gameobject.GameObject; +import net.sf.gridarta.gameobject.scripts.AbstractScriptedEvent; +import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; +import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; +import org.jetbrains.annotations.NotNull; + +/** + * Class which stores information about one scripted event. + * @author Andreas Kirschbaum + */ +public final class DefaultScriptedEvent extends AbstractScriptedEvent<GameObject> { + + /** + * The {@link ScriptArchUtils} instance to use. + */ + @NotNull + private final ScriptArchUtils scriptArchUtils; + + /** The underlying game object that represents the event. */ + private final GameObject event; + + /** + * The attribute name for the subtype field. + */ + @NotNull + private final String subtypeAttribute; + + /** + * Creates a fully initialized ScriptedEvent. + * @param scriptArchUtils the script arch utils instance to use + * @param eventType type of the event + * @param subtypeAttribute the attribute name for the subtype field + * @param pluginName name of the plugin + * @param scriptPath path to the file for this event + * @param options the options for this event + * @throws UndefinedEventArchetypeException In case there is no Archetype to + * create a ScriptedEvent. + */ + DefaultScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final int eventType, @NotNull final String subtypeAttribute, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { + this.scriptArchUtils = scriptArchUtils; + this.subtypeAttribute = subtypeAttribute; + event = newEventGameObject(eventType); + setEventData(pluginName, scriptPath, options); + } + + /** + * Create a ScriptedEvent of given type (This is used for map-loading). + * @param scriptArchUtils the script arch utils instance to use + * @param event GameObject that describes the event. + * @param subtypeAttribute the attribute name for the subtype field + */ + DefaultScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final GameObject event, @NotNull final String subtypeAttribute) { + this.scriptArchUtils = scriptArchUtils; + this.event = event; + this.subtypeAttribute = subtypeAttribute; + } + + /** {@inheritDoc} */ + public void modifyEventPath() { + final String newPath = ScriptedEventEditor.inputScriptPath.getText().trim(); + final String newPluginName = ScriptedEventEditor.inputPluginName.getText().trim(); + final String newOptions = ScriptedEventEditor.inputOptions.getText().trim(); + + if (newPath.length() > 0) { + setScriptPath(newPath); + } + if (newPluginName.length() > 0) { + setPluginName(newPluginName); + } + setOptions(newOptions); // unlike the above two, event options can be empty + } + + /** {@inheritDoc} */ + public GameObject getEventArch() { + return event; + } + + /** {@inheritDoc} */ + public int getEventType() { + return event.getAttributeInt(subtypeAttribute); + } + + public String getPluginName() { + return event.getAttributeString("title"); + } + + public String getScriptPath() { + return event.getAttributeString("slaying"); + } + + public String getOptions() { + final String options = event.getObjName(); + return options == null ? "" : options; + } + + public void setPluginName(final String pluginName) { + setEventData(pluginName, getScriptPath(), getOptions()); + } + + public void setScriptPath(final String scriptPath) { + setEventData(getPluginName(), scriptPath, getOptions()); + } + + public void setOptions(final String options) { + setEventData(getPluginName(), getScriptPath(), options); + } + + /** {@inheritDoc} */ + @NotNull + @Override + protected String typeName(final int eventType) { + return scriptArchUtils.typeName(eventType); + } + + /** {@inheritDoc} */ + @Override + protected void setEventData(@NotNull final String pluginName, @NotNull final String scriptPath, @NotNull final String options) { + final int eventType = getEventType(); + event.resetObjectText(); + if (eventType != event.getArchetype().getAttributeInt(subtypeAttribute)) { + event.addObjectText(subtypeAttribute + " " + eventType); + } + if (!pluginName.equals(event.getArchetype().getAttributeString("title"))) { + event.addObjectText("title " + pluginName); + } + if (!scriptPath.equals(event.getArchetype().getAttributeString("slaying"))) { + event.addObjectText("slaying " + scriptPath); + } + final String tmp = event.getObjName(); + final String defaultEventOptions = tmp == null ? "" : tmp; + if (!options.equals(defaultEventOptions)) { + event.setObjName(options.length() > 0 ? options : null); + } + } + + /** + * Return a new event game object for a given event type. + * @param eventType the event type + * @return the new event game object + * @throws UndefinedEventArchetypeException if the event game object cannot + * be created + */ + private GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { + final String eventArchetypeName = scriptArchUtils.getArchetypeNameForEventType(eventType); + if (eventArchetypeName == null) { + throw new UndefinedEventArchetypeTypeException(eventType); + } + if (archetypeSet == null) { + throw new UndefinedEventArchetypeNameException(eventArchetypeName); + } + final Archetype eventArchetype = (Archetype) (Object) archetypeSet.getArchetype(eventArchetypeName); + if (eventArchetype == null) { + throw new UndefinedEventArchetypeNameException(eventArchetypeName); + } + final GameObject event = eventArchetype.createGameObject(); + event.postParseGameObject(0); + return event; + } + +} // class DefaultScriptedEvent Property changes on: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEvent.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-10-16 16:57:43 UTC (rev 5540) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-10-16 16:59:48 UTC (rev 5541) @@ -1,185 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package cfeditor.gameobject.scripts; - -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import net.sf.gridarta.gameobject.scripts.AbstractScriptedEvent; -import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; -import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; -import org.jetbrains.annotations.NotNull; - -/** - * Class which stores information about one scripted event. - * @author Andreas Kirschbaum - */ -public final class ScriptedEvent extends AbstractScriptedEvent<GameObject> { - - /** - * The {@link ScriptArchUtils} instance to use. - */ - @NotNull - private final ScriptArchUtils scriptArchUtils; - - /** The underlying game object that represents the event. */ - private final GameObject event; - - /** - * The attribute name for the subtype field. - */ - @NotNull - private final String subtypeAttribute; - - /** - * Creates a fully initialized ScriptedEvent. - * @param scriptArchUtils the script arch utils instance to use - * @param eventType type of the event - * @param subtypeAttribute the attribute name for the subtype field - * @param pluginName name of the plugin - * @param scriptPath path to the file for this event - * @param options the options for this event - * @throws UndefinedEventArchetypeException In case there is no Archetype to - * create a ScriptedEvent. - */ - ScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final int eventType, @NotNull final String subtypeAttribute, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { - this.scriptArchUtils = scriptArchUtils; - this.subtypeAttribute = subtypeAttribute; - event = newEventGameObject(eventType); - setEventData(pluginName, scriptPath, options); - } - - /** - * Create a ScriptedEvent of given type (This is used for map-loading). - * @param scriptArchUtils the script arch utils instance to use - * @param event GameObject that describes the event. - * @param subtypeAttribute the attribute name for the subtype field - */ - ScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final GameObject event, @NotNull final String subtypeAttribute) { - this.scriptArchUtils = scriptArchUtils; - this.event = event; - this.subtypeAttribute = subtypeAttribute; - } - - /** {@inheritDoc} */ - public void modifyEventPath() { - final String newPath = ScriptedEventEditor.inputScriptPath.getText().trim(); - final String newPluginName = ScriptedEventEditor.inputPluginName.getText().trim(); - final String newOptions = ScriptedEventEditor.inputOptions.getText().trim(); - - if (newPath.length() > 0) { - setScriptPath(newPath); - } - if (newPluginName.length() > 0) { - setPluginName(newPluginName); - } - setOptions(newOptions); // unlike the above two, event options can be empty - } - - /** {@inheritDoc} */ - public GameObject getEventArch() { - return event; - } - - /** {@inheritDoc} */ - public int getEventType() { - return event.getAttributeInt(subtypeAttribute); - } - - public String getPluginName() { - return event.getAttributeString("title"); - } - - public String getScriptPath() { - return event.getAttributeString("slaying"); - } - - public String getOptions() { - final String options = event.getObjName(); - return options == null ? "" : options; - } - - public void setPluginName(final String pluginName) { - setEventData(pluginName, getScriptPath(), getOptions()); - } - - public void setScriptPath(final String scriptPath) { - setEventData(getPluginName(), scriptPath, getOptions()); - } - - public void setOptions(final String options) { - setEventData(getPluginName(), getScriptPath(), options); - } - - /** {@inheritDoc} */ - @NotNull - @Override - protected String typeName(final int eventType) { - return scriptArchUtils.typeName(eventType); - } - - /** {@inheritDoc} */ - @Override - protected void setEventData(@NotNull final String pluginName, @NotNull final String scriptPath, @NotNull final String options) { - final int eventType = getEventType(); - event.resetObjectText(); - if (eventType != event.getArchetype().getAttributeInt(subtypeAttribute)) { - event.addObjectText(subtypeAttribute + " " + eventType); - } - if (!pluginName.equals(event.getArchetype().getAttributeString("title"))) { - event.addObjectText("title " + pluginName); - } - if (!scriptPath.equals(event.getArchetype().getAttributeString("slaying"))) { - event.addObjectText("slaying " + scriptPath); - } - final String tmp = event.getObjName(); - final String defaultEventOptions = tmp == null ? "" : tmp; - if (!options.equals(defaultEventOptions)) { - event.setObjName(options.length() > 0 ? options : null); - } - } - - /** - * Return a new event game object for a given event type. - * @param eventType the event type - * @return the new event game object - * @throws UndefinedEventArchetypeException if the event game object cannot - * be created - */ - private GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { - final String eventArchetypeName = scriptArchUtils.getArchetypeNameForEventType(eventType); - if (eventArchetypeName == null) { - throw new UndefinedEventArchetypeTypeException(eventType); - } - if (archetypeSet == null) { - throw new UndefinedEventArchetypeNameException(eventArchetypeName); - } - final Archetype eventArchetype = (Archetype) (Object) archetypeSet.getArchetype(eventArchetypeName); - if (eventArchetype == null) { - throw new UndefinedEventArchetypeNameException(eventArchetypeName); - } - final GameObject event = eventArchetype.createGameObject(); - event.postParseGameObject(0); - return event; - } - -} // class ScriptedEvent Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 16:57:43 UTC (rev 5540) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 16:59:48 UTC (rev 5541) @@ -57,8 +57,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptedEvent newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { - return new ScriptedEvent(scriptArchUtils, event, subtypeAttribute); + protected DefaultScriptedEvent newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { + return new DefaultScriptedEvent(scriptArchUtils, event, subtypeAttribute); } /** {@inheritDoc} */ Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 16:57:43 UTC (rev 5540) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 16:59:48 UTC (rev 5541) @@ -83,9 +83,9 @@ if (newScriptFile.exists()) { if (newScriptFile.isFile()) { // file exists -> link it to the event - final ScriptedEvent event; + final DefaultScriptedEvent event; try { - event = new ScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); + event = new DefaultScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; @@ -118,9 +118,9 @@ JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); } else { // file has been created, now link it to the event - final ScriptedEvent event; + final DefaultScriptedEvent event; try { - event = new ScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); + event = new DefaultScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; Copied: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEvent.java (from rev 5537, trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java) =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEvent.java (rev 0) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEvent.java 2008-10-16 16:59:48 UTC (rev 5541) @@ -0,0 +1,184 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package daieditor.gameobject.scripts; + +import daieditor.gameobject.Archetype; +import daieditor.gameobject.GameObject; +import net.sf.gridarta.gameobject.scripts.AbstractScriptedEvent; +import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; +import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; +import org.jetbrains.annotations.NotNull; + +/** + * Class which stores information about one scripted event. + * @author Andreas Kirschbaum + */ +public final class DefaultScriptedEvent extends AbstractScriptedEvent<GameObject> { + + /** + * The {@link ScriptArchUtils} instance to use. + */ + @NotNull + private final ScriptArchUtils scriptArchUtils; + + /** The underlying game object that represents the event. */ + private final GameObject event; + + /** + * The attribute name for the subtype field. + */ + @NotNull + private final String subtypeAttribute; + + /** + * Create a ScriptedEvent of given type (This is used for map-loading). + * @param scriptArchUtils the script arch utils instance to use + * @param event GameObject that describes the event. + * @param subtypeAttribute the attribute name for the subtype field + */ + DefaultScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final GameObject event, @NotNull final String subtypeAttribute) { + this.scriptArchUtils = scriptArchUtils; + this.event = event; + this.subtypeAttribute = subtypeAttribute; + } + + /** + * Creates a fully initialized ScriptedEvent. + * @param scriptArchUtils the script arch utils instance to use + * @param eventType type of the event + * @param subtypeAttribute the attribute name for the subtype field + * @param pluginName name of the plugin + * @param scriptPath path to the file for this event + * @param options the options for this event + * @throws UndefinedEventArchetypeException In case there is no Archetype to + * create a ScriptedEvent. + */ + DefaultScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final int eventType, @NotNull final String subtypeAttribute, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { + this.scriptArchUtils = scriptArchUtils; + this.subtypeAttribute = subtypeAttribute; + event = newEventGameObject(eventType); + setEventData(pluginName, scriptPath, options); + } + + /** {@inheritDoc} */ + public void modifyEventPath() { + final String newPath = ScriptedEventEditor.inputScriptPath.getText().trim(); + final String newPluginName = ScriptedEventEditor.inputPluginName.getText().trim(); + final String newOptions = ScriptedEventEditor.inputOptions.getText().trim(); + + if (newPath.length() > 0) { + setScriptPath(newPath); + } + if (newPluginName.length() > 0) { + setPluginName(newPluginName); + } + if (newOptions.length() > 0) { + setOptions(newOptions); + } + } + + /** {@inheritDoc} */ + public GameObject getEventArch() { + return event; + } + + /** {@inheritDoc} */ + public int getEventType() { + return event.getAttributeInt(subtypeAttribute); + } + + public String getPluginName() { + return event.getBestName(); + } + + public String getScriptPath() { + return event.getAttributeString("race"); + } + + public String getOptions() { + return event.getAttributeString("slaying"); + } + + public void setPluginName(final String pluginName) { + setEventData(pluginName, getScriptPath(), getOptions()); + } + + public void setScriptPath(final String scriptPath) { + setEventData(getPluginName(), scriptPath, getOptions()); + } + + public void setOptions(final String options) { + setEventData(getPluginName(), getScriptPath(), options); + } + + /** {@inheritDoc} */ + @NotNull + @Override + protected String typeName(final int eventType) { + return scriptArchUtils.typeName(eventType); + } + + + /** {@inheritDoc} */ + @Override + protected void setEventData(@NotNull final String pluginName, @NotNull final String scriptPath, @NotNull final String options) { + final int eventType = getEventType(); + event.resetObjectText(); + event.addObjectText(subtypeAttribute + " " + eventType); + if (pluginName != null && pluginName.length() > 0) { + event.setObjName(pluginName); + } + if (scriptPath != null && scriptPath.length() > 0) { + event.addObjectText("race " + scriptPath); + } + if (options != null && options.length() > 0) { + event.addObjectText("slaying " + options); + } + } + + /** + * Return a new event game object for a given event type. + * @param eventType the event type + * @return the new event game object + * @throws UndefinedEventArchetypeException if the event game object cannot + * be created + */ + private GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { + final String eventArchetypeName = scriptArchUtils.getArchetypeNameForEventType(eventType); + if (eventArchetypeName == null) { + throw new UndefinedEventArchetypeTypeException(eventType); + } + if (archetypeSet == null) { + throw new UndefinedEventArchetypeNameException(eventArchetypeName); + } + final Archetype eventArchetype = (Archetype) (Object) archetypeSet.getArchetype(eventArchetypeName); + if (eventArchetype == null) { + throw new UndefinedEventArchetypeNameException(eventArchetypeName); + } + final GameObject event = eventArchetype.createGameObject(); + event.addObjectText(subtypeAttribute + " " + eventType); + event.postParseGameObject(0); + return event; + } + +} // class DefaultScriptedEvent Property changes on: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEvent.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-10-16 16:57:43 UTC (rev 5540) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-10-16 16:59:48 UTC (rev 5541) @@ -1,184 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor.gameobject.scripts; - -import daieditor.gameobject.Archetype; -import daieditor.gameobject.GameObject; -import net.sf.gridarta.gameobject.scripts.AbstractScriptedEvent; -import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; -import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; -import org.jetbrains.annotations.NotNull; - -/** - * Class which stores information about one scripted event. - * @author Andreas Kirschbaum - */ -public final class ScriptedEvent extends AbstractScriptedEvent<GameObject> { - - /** - * The {@link ScriptArchUtils} instance to use. - */ - @NotNull - private final ScriptArchUtils scriptArchUtils; - - /** The underlying game object that represents the event. */ - private final GameObject event; - - /** - * The attribute name for the subtype field. - */ - @NotNull - private final String subtypeAttribute; - - /** - * Create a ScriptedEvent of given type (This is used for map-loading). - * @param scriptArchUtils the script arch utils instance to use - * @param event GameObject that describes the event. - * @param subtypeAttribute the attribute name for the subtype field - */ - ScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final GameObject event, @NotNull final String subtypeAttribute) { - this.scriptArchUtils = scriptArchUtils; - this.event = event; - this.subtypeAttribute = subtypeAttribute; - } - - /** - * Creates a fully initialized ScriptedEvent. - * @param scriptArchUtils the script arch utils instance to use - * @param eventType type of the event - * @param subtypeAttribute the attribute name for the subtype field - * @param pluginName name of the plugin - * @param scriptPath path to the file for this event - * @param options the options for this event - * @throws UndefinedEventArchetypeException In case there is no Archetype to - * create a ScriptedEvent. - */ - ScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final int eventType, @NotNull final String subtypeAttribute, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { - this.scriptArchUtils = scriptArchUtils; - this.subtypeAttribute = subtypeAttribute; - event = newEventGameObject(eventType); - setEventData(pluginName, scriptPath, options); - } - - /** {@inheritDoc} */ - public void modifyEventPath() { - final String newPath = ScriptedEventEditor.inputScriptPath.getText().trim(); - final String newPluginName = ScriptedEventEditor.inputPluginName.getText().trim(); - final String newOptions = ScriptedEventEditor.inputOptions.getText().trim(); - - if (newPath.length() > 0) { - setScriptPath(newPath); - } - if (newPluginName.length() > 0) { - setPluginName(newPluginName); - } - if (newOptions.length() > 0) { - setOptions(newOptions); - } - } - - /** {@inheritDoc} */ - public GameObject getEventArch() { - return event; - } - - /** {@inheritDoc} */ - public int getEventType() { - return event.getAttributeInt(subtypeAttribute); - } - - public String getPluginName() { - return event.getBestName(); - } - - public String getScriptPath() { - return event.getAttributeString("race"); - } - - public String getOptions() { - return event.getAttributeString("slaying"); - } - - public void setPluginName(final String pluginName) { - setEventData(pluginName, getScriptPath(), getOptions()); - } - - public void setScriptPath(final String scriptPath) { - setEventData(getPluginName(), scriptPath, getOptions()); - } - - public void setOptions(final String options) { - setEventData(getPluginName(), getScriptPath(), options); - } - - /** {@inheritDoc} */ - @NotNull - @Override - protected String typeName(final int eventType) { - return scriptArchUtils.typeName(eventType); - } - - - /** {@inheritDoc} */ - @Override - protected void setEventData(@NotNull final String pluginName, @NotNull final String scriptPath, @NotNull final String options) { - final int eventType = getEventType(); - event.resetObjectText(); - event.addObjectText(subtypeAttribute + " " + eventType); - if (pluginName != null && pluginName.length() > 0) { - event.setObjName(pluginName); - } - if (scriptPath != null && scriptPath.length() > 0) { - event.addObjectText("race " + scriptPath); - } - if (options != null && options.length() > 0) { - event.addObjectText("slaying " + options); - } - } - - /** - * Return a new event game object for a given event type. - * @param eventType the event type - * @return the new event game object - * @throws UndefinedEventArchetypeException if the event game object cannot - * be created - */ - private GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { - final String eventArchetypeName = scriptArchUtils.getArchetypeNameForEventType(eventType); - if (eventArchetypeName == null) { - throw new UndefinedEventArchetypeTypeException(eventType); - } - if (archetypeSet == null) { - throw new UndefinedEventArchetypeNameException(eventArchetypeName); - } - final Archetype eventArchetype = (Archetype) (Object) archetypeSet.getArchetype(eventArchetypeName); - if (eventArchetype == null) { - throw new UndefinedEventArchetypeNameException(eventArchetypeName); - } - final GameObject event = eventArchetype.createGameObject(); - event.addObjectText(subtypeAttribute + " " + eventType); - event.postParseGameObject(0); - return event; - } - -} // class ScriptedEvent This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-16 17:10:55
|
Revision: 5543 http://gridarta.svn.sourceforge.net/gridarta/?rev=5543&view=rev Author: akirschbaum Date: 2008-10-16 17:10:45 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Remove AbstractScriptArchData.typeName(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:06:54 UTC (rev 5542) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:10:45 UTC (rev 5543) @@ -50,7 +50,7 @@ * @param eventTypeNo the object type for event objects */ public DefaultScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final String subtypeAttribute, final int eventTypeNo) { - super(subtypeAttribute, eventTypeNo); + super(subtypeAttribute, eventTypeNo, scriptArchUtils); this.scriptArchUtils = scriptArchUtils; } @@ -66,11 +66,4 @@ DefaultScriptArchEditor.createNewEvent(frame, this, gameObject); } - /** {@inheritDoc} */ - @NotNull - @Override - protected String typeName(final int attributeInt) { - return scriptArchUtils.typeName(attributeInt); - } - } // class DefaultScriptArchData Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:06:54 UTC (rev 5542) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:10:45 UTC (rev 5543) @@ -50,7 +50,7 @@ * @param eventTypeNo the object type for event objects */ public DefaultScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final String subtypeAttribute, final int eventTypeNo) { - super(subtypeAttribute, eventTypeNo); + super(subtypeAttribute, eventTypeNo, scriptArchUtils); this.scriptArchUtils = scriptArchUtils; } @@ -66,11 +66,4 @@ DefaultScriptArchEditor.createNewEvent(frame, this, gameObject); } - /** {@inheritDoc} */ - @NotNull - @Override - protected String typeName(final int attributeInt) { - return scriptArchUtils.typeName(attributeInt); - } - } // class DefaultScriptArchData Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-16 17:06:54 UTC (rev 5542) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-16 17:10:45 UTC (rev 5543) @@ -59,13 +59,21 @@ private final int eventTypeNo; /** + * The {@link ScriptArchUtils} instance to use. + */ + @NotNull + private final ScriptArchUtils scriptArchUtils; + + /** * Create a ScriptArchData. * @param subtypeAttribute the attribute name for the subtype field * @param eventTypeNo the object type for event objects + * @param scriptArchUtils the script arch utils instance to use */ - protected AbstractScriptArchData(@NotNull final String subtypeAttribute, final int eventTypeNo) { + protected AbstractScriptArchData(@NotNull final String subtypeAttribute, final int eventTypeNo, @NotNull final ScriptArchUtils scriptArchUtils) { this.subtypeAttribute = subtypeAttribute; this.eventTypeNo = eventTypeNo; + this.scriptArchUtils = scriptArchUtils; } /** {@inheritDoc} */ @@ -75,7 +83,7 @@ final Vector<String> content = new Vector<String>(); for (final G tmp : gameObject) { if (tmp.getTypeNo() == eventTypeNo) { - content.add(" " + typeName(tmp.getAttributeInt(subtypeAttribute))); + content.add(" " + scriptArchUtils.typeName(tmp.getAttributeInt(subtypeAttribute))); } } @@ -83,14 +91,6 @@ list.setSelectedIndex(0); } - /** - * Returns a description for a script type. - * @param attributeInt the script type - * @return the description - */ - @NotNull - protected abstract String typeName(final int attributeInt); - /** {@inheritDoc} */ @Nullable public G getScriptedEvent(final int eventSubtype, @NotNull final G gameObject) { @@ -157,7 +157,7 @@ ScriptedEventEditor.editParameters(event, parent); } else if (task == ScriptTab.SCRIPT_REMOVE) { // first ask for confirmation - if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { + if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + scriptArchUtils.typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { // remove this event from the GameObject oldEvent.remove(); addEventsToJList(panelList, gameObject); // update panel JList This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-16 17:31:46
|
Revision: 5544 http://gridarta.svn.sourceforge.net/gridarta/?rev=5544&view=rev Author: akirschbaum Date: 2008-10-16 17:31:35 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Convert utility class ScriptArchEditor to normal class. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java trunk/src/app/net/sf/gridarta/AbstractMainControl.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptArchEditor.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 17:10:45 UTC (rev 5543) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 17:31:35 UTC (rev 5544) @@ -28,6 +28,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObjects; import cfeditor.gameobject.scripts.DefaultScriptArchData; +import cfeditor.gameobject.scripts.DefaultScriptArchEditor; import cfeditor.gameobject.scripts.DefaultScriptArchUtils; import cfeditor.gui.map.CMapViewBasic; import cfeditor.gui.map.DefaultMapPropertiesDialogFactory; @@ -59,6 +60,8 @@ import net.sf.gridarta.gameobject.face.FaceObjectProviders; import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.gameobject.match.GameObjectMatcher; +import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import net.sf.gridarta.gui.MainView; import net.sf.gridarta.gui.MapViewManager; import net.sf.gridarta.gui.archetypechooser.ArchetypeChooserControl; @@ -128,6 +131,13 @@ /** {@inheritDoc} */ @NotNull @Override + protected ScriptArchEditor<GameObject> newScriptArchEditor() { + return new DefaultScriptArchEditor(); + } + + /** {@inheritDoc} */ + @NotNull + @Override protected DefaultScriptArchUtils newScriptArchUtils() { return new DefaultScriptArchUtils(); } @@ -135,8 +145,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected DefaultScriptArchData newScriptArchData(@NotNull final net.sf.gridarta.gameobject.scripts.ScriptArchUtils scriptArchUtils) { - return new DefaultScriptArchData(scriptArchUtils, "subtype", Archetype.TYPE_EVENT_CONNECTOR); + protected DefaultScriptArchData newScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { + return new DefaultScriptArchData(scriptArchUtils, scriptArchEditor, "subtype", Archetype.TYPE_EVENT_CONNECTOR); } /** {@inheritDoc} */ @@ -234,7 +244,7 @@ /** {@inheritDoc} */ @NotNull @Override - protected MapActions init1(@NotNull final net.sf.gridarta.gameobject.scripts.ScriptArchUtils scriptArchUtils, @NotNull final MapArchObjectParserFactory<MapArchObject> mapArchObjectParserFactory, @NotNull final MapArchObjectFactory<MapArchObject> mapArchObjectFactory, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, @NotNull final MapViewManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapViewManager, @NotNull final ArchetypeTypeSet<GameObject, MapArchObject, Archetype> archetypeTypeSet, @NotNull final SelectedSquareView<GameObject, MapArchObject, Archetype, CMapViewBasic> selectedSquareView, @NotNull final GameObjectMatcher exitMatcher) { + protected MapActions init1(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final MapArchObjectParserFactory<MapArchObject> mapArchObjectParserFactory, @NotNull final MapArchObjectFactory<MapArchObject> mapArchObjectFactory, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, @NotNull final MapViewManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapViewManager, @NotNull final ArchetypeTypeSet<GameObject, MapArchObject, Archetype> archetypeTypeSet, @NotNull final SelectedSquareView<GameObject, MapArchObject, Archetype, CMapViewBasic> selectedSquareView, @NotNull final GameObjectMatcher exitMatcher) { archetypeTypeSet.getListTable().put("event", scriptArchUtils.getEventTypes()); final int[] directionMap = new int[] { CommonConstants.NORTH, Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:10:45 UTC (rev 5543) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:31:35 UTC (rev 5544) @@ -22,6 +22,7 @@ import cfeditor.gameobject.GameObject; import javax.swing.JDialog; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; +import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import org.jetbrains.annotations.NotNull; @@ -44,14 +45,22 @@ private final ScriptArchUtils scriptArchUtils; /** + * The {@link ScriptArchEditor} instance to use. + */ + @NotNull + private final ScriptArchEditor<GameObject> scriptArchEditor; + + /** * Create a ScriptArchData. * @param scriptArchUtils the script arch utils instance to use + * @param scriptArchEditor the script arch editor instance to use * @param subtypeAttribute the attribute name for the subtype field * @param eventTypeNo the object type for event objects */ - public DefaultScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final String subtypeAttribute, final int eventTypeNo) { + public DefaultScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { super(subtypeAttribute, eventTypeNo, scriptArchUtils); this.scriptArchUtils = scriptArchUtils; + this.scriptArchEditor = scriptArchEditor; } /** {@inheritDoc} */ @@ -63,7 +72,7 @@ /** {@inheritDoc} */ public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { - DefaultScriptArchEditor.createNewEvent(frame, this, gameObject); + scriptArchEditor.createNewEvent(frame, this, gameObject); } } // class DefaultScriptArchData Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 17:10:45 UTC (rev 5543) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 17:31:35 UTC (rev 5544) @@ -25,17 +25,19 @@ import javax.swing.JDialog; import javax.swing.JOptionPane; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.ScriptArchData; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; import net.sf.japi.swing.ActionFactory; import org.jetbrains.annotations.NotNull; -public class DefaultScriptArchEditor extends AbstractScriptArchEditor { +public class DefaultScriptArchEditor extends AbstractScriptArchEditor<GameObject> { /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - public static void createNewEvent(final JDialog frame, final DefaultScriptArchData scriptArchData, @NotNull final GameObject gameObject) { + /** {@inheritDoc} */ + public void createNewEvent(final JDialog frame, final ScriptArchData<GameObject> scriptArchData, @NotNull final GameObject gameObject) { String scriptPath = inputScriptPath.getText().trim(); final String options = inputOptions.getText().trim(); final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 17:10:45 UTC (rev 5543) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 17:31:35 UTC (rev 5544) @@ -28,6 +28,7 @@ import daieditor.gameobject.GameObject; import daieditor.gameobject.anim.AnimationObjects; import daieditor.gameobject.scripts.DefaultScriptArchData; +import daieditor.gameobject.scripts.DefaultScriptArchEditor; import daieditor.gameobject.scripts.DefaultScriptArchUtils; import daieditor.gui.map.CMapViewBasic; import daieditor.gui.map.DefaultMapPropertiesDialogFactory; @@ -66,6 +67,8 @@ import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.gameobject.match.MutableOrGameObjectMatcher; import net.sf.gridarta.gameobject.match.ViewGameObjectMatcherManager; +import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import net.sf.gridarta.gui.MainView; import net.sf.gridarta.gui.MapViewManager; import net.sf.gridarta.gui.archetypechooser.ArchetypeChooserControl; @@ -173,6 +176,13 @@ /** {@inheritDoc} */ @NotNull @Override + protected ScriptArchEditor<GameObject> newScriptArchEditor() { + return new DefaultScriptArchEditor(); + } + + /** {@inheritDoc} */ + @NotNull + @Override protected DefaultScriptArchUtils newScriptArchUtils() { return new DefaultScriptArchUtils(); } @@ -180,8 +190,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected DefaultScriptArchData newScriptArchData(@NotNull final net.sf.gridarta.gameobject.scripts.ScriptArchUtils scriptArchUtils) { - return new DefaultScriptArchData(scriptArchUtils, "sub_type", Archetype.TYPE_EVENT_OBJECT); + protected DefaultScriptArchData newScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { + return new DefaultScriptArchData(scriptArchUtils, scriptArchEditor, "sub_type", Archetype.TYPE_EVENT_OBJECT); } /** {@inheritDoc} */ @@ -282,7 +292,7 @@ /** {@inheritDoc} */ @NotNull @Override - protected MapActions init1(@NotNull final net.sf.gridarta.gameobject.scripts.ScriptArchUtils scriptArchUtils, @NotNull final MapArchObjectParserFactory<MapArchObject> mapArchObjectParserFactory, @NotNull final MapArchObjectFactory<MapArchObject> mapArchObjectFactory, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, @NotNull final MapViewManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapViewManager, @NotNull final ArchetypeTypeSet<GameObject, MapArchObject, Archetype> archetypeTypeSet, @NotNull final SelectedSquareView<GameObject, MapArchObject, Archetype, CMapViewBasic> selectedSquareView, @NotNull final GameObjectMatcher exitMatcher) { + protected MapActions init1(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final MapArchObjectParserFactory<MapArchObject> mapArchObjectParserFactory, @NotNull final MapArchObjectFactory<MapArchObject> mapArchObjectFactory, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, @NotNull final MapViewManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapViewManager, @NotNull final ArchetypeTypeSet<GameObject, MapArchObject, Archetype> archetypeTypeSet, @NotNull final SelectedSquareView<GameObject, MapArchObject, Archetype, CMapViewBasic> selectedSquareView, @NotNull final GameObjectMatcher exitMatcher) { final int[] directionMap = new int[] { CommonConstants.NORTH_EAST, CommonConstants.SOUTH_EAST, Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:10:45 UTC (rev 5543) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:31:35 UTC (rev 5544) @@ -22,6 +22,7 @@ import daieditor.gameobject.GameObject; import javax.swing.JDialog; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; +import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import org.jetbrains.annotations.NotNull; @@ -44,14 +45,22 @@ private final ScriptArchUtils scriptArchUtils; /** + * The {@link ScriptArchEditor} instance to use. + */ + @NotNull + private final ScriptArchEditor<GameObject> scriptArchEditor; + + /** * Create a ScriptArchData. * @param scriptArchUtils the script arch utils instance to use + * @param scriptArchEditor the script arch editor instance to use * @param subtypeAttribute the attribute name for the subtype field * @param eventTypeNo the object type for event objects */ - public DefaultScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final String subtypeAttribute, final int eventTypeNo) { + public DefaultScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { super(subtypeAttribute, eventTypeNo, scriptArchUtils); this.scriptArchUtils = scriptArchUtils; + this.scriptArchEditor = scriptArchEditor; } /** {@inheritDoc} */ @@ -63,7 +72,7 @@ /** {@inheritDoc} */ public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { - DefaultScriptArchEditor.createNewEvent(frame, this, gameObject); + scriptArchEditor.createNewEvent(frame, this, gameObject); } } // class DefaultScriptArchData Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 17:10:45 UTC (rev 5543) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 17:31:35 UTC (rev 5544) @@ -25,17 +25,19 @@ import javax.swing.JDialog; import javax.swing.JOptionPane; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.ScriptArchData; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; import net.sf.japi.swing.ActionFactory; import org.jetbrains.annotations.NotNull; -public class DefaultScriptArchEditor extends AbstractScriptArchEditor { +public class DefaultScriptArchEditor extends AbstractScriptArchEditor<GameObject> { /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - public static void createNewEvent(final JDialog frame, final DefaultScriptArchData scriptArchData, @NotNull final GameObject gameObject) { + /** {@inheritDoc} */ + public void createNewEvent(final JDialog frame, final ScriptArchData<GameObject> scriptArchData, @NotNull final GameObject gameObject) { String scriptPath = inputScriptPath.getText().trim(); final String options = inputOptions.getText().trim(); final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); Modified: trunk/src/app/net/sf/gridarta/AbstractMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-16 17:10:45 UTC (rev 5543) +++ trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-16 17:31:35 UTC (rev 5544) @@ -60,6 +60,7 @@ import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; import net.sf.gridarta.gameobject.scripts.AbstractScriptedEvent; import net.sf.gridarta.gameobject.scripts.ScriptArchData; +import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; import net.sf.gridarta.gui.About; @@ -471,7 +472,8 @@ final MapViewFactory<G, A, R, V> mapViewFactory = newMapViewFactory(faceObjects, selectedSquareView, this, mainView, editTypes, mapImageCache, toolPalette, filterControl); mapControlFactory.init(mapViewFactory, gameObjectParser, rendererFactory, mapActions, archetypeChooserModel, mapImageCache, autojoinLists, exitMatcher); copyBuffer.init(mapArchObjectFactory.newMapArchObject(false), mainView); - GameObject.initialize(archetypeSet, archetypeTypeSet, gameObjectMatchers, animationObjects, SystemIcons.getNofaceTileIcon(), newScriptArchData(scriptArchUtils)); + final ScriptArchEditor<G> scriptArchEditor = newScriptArchEditor(); + GameObject.initialize(archetypeSet, archetypeTypeSet, gameObjectMatchers, scriptArchEditor, animationObjects, SystemIcons.getNofaceTileIcon(), newScriptArchData(scriptArchUtils, scriptArchEditor)); init4(gameObjectParser, archetypeParser, editTypes, faceObjects, animationObjects, mainView, globalSettings, archetypeSet); if (globalSettings.isAutoPopupDocu()) { @@ -508,10 +510,13 @@ } @NotNull + protected abstract ScriptArchEditor<G> newScriptArchEditor(); + + @NotNull protected abstract ScriptArchUtils newScriptArchUtils(); @NotNull - protected abstract ScriptArchData<G> newScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils); + protected abstract ScriptArchData<G> newScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<G> scriptArchEditor); @NotNull protected abstract ArchetypeFactory<G, A, R> newArchetypeFactory(); Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2008-10-16 17:10:45 UTC (rev 5543) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2008-10-16 17:31:35 UTC (rev 5544) @@ -30,8 +30,8 @@ import net.sf.gridarta.gameobject.anim.AnimationObject; import net.sf.gridarta.gameobject.anim.AnimationObjects; import net.sf.gridarta.gameobject.match.GameObjectMatchers; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchData; +import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gui.GUIConstants; import net.sf.gridarta.gui.gameobjectattributespanel.ScriptTab; import net.sf.gridarta.map.MapArchObject; @@ -65,6 +65,8 @@ private static GameObjectMatchers gameObjectMatchers = null; + private static ScriptArchEditor scriptArchEditor = null; + @Nullable protected static AnimationObjects<? extends AnimationObject> animationObjects = null; @@ -222,10 +224,11 @@ * @param noFace the image icons for game objects having no face * @param scriptArchData the script arch data instance to use */ - public static void initialize(@Nullable final ArchetypeSet<?, ?, ?> archetypeSet, final ArchetypeTypeSet archetypeTypeSet, final GameObjectMatchers gameObjectMatchers, @Nullable final AnimationObjects<? extends AnimationObject> animationObjects, @NotNull final ImageIcon noFace, @NotNull final ScriptArchData<?> scriptArchData) { + public static void initialize(@Nullable final ArchetypeSet<?, ?, ?> archetypeSet, final ArchetypeTypeSet archetypeTypeSet, final GameObjectMatchers gameObjectMatchers, final ScriptArchEditor scriptArchEditor, @Nullable final AnimationObjects<? extends AnimationObject> animationObjects, @NotNull final ImageIcon noFace, @NotNull final ScriptArchData<?> scriptArchData) { GameObject.archetypeSet = archetypeSet; GameObject.archetypeTypeSet = archetypeTypeSet; GameObject.gameObjectMatchers = gameObjectMatchers; + GameObject.scriptArchEditor = scriptArchEditor; GameObject.animationObjects = animationObjects; GameObject.noFace = noFace; GameObject.scriptArchData = scriptArchData; @@ -1468,7 +1471,7 @@ * @param parent the parent frame for the editor */ public void addEventScript(@NotNull final JList eventList, @NotNull final ScriptTab<G, A, R> mapanel, @NotNull final Frame parent) { - AbstractScriptArchEditor.addEventScript((G) this, (ScriptArchData<G>) scriptArchData, parent); + ((ScriptArchEditor<G>) scriptArchEditor).addEventScript((G) this, (ScriptArchData<G>) scriptArchData, parent); if (!((ScriptArchData<G>) scriptArchData).isEmpty((G) this)) { mapanel.setScriptPanelButtonState(true, true, true, true); Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java 2008-10-16 17:10:45 UTC (rev 5543) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java 2008-10-16 17:31:35 UTC (rev 5544) @@ -43,7 +43,7 @@ import net.sf.gridarta.gameobject.GameObject; import org.jetbrains.annotations.NotNull; -public abstract class AbstractScriptArchEditor { +public abstract class AbstractScriptArchEditor<G extends GameObject<G, ?, ?>> implements ScriptArchEditor<G> { /** * The {@link ScriptArchUtils} instance to use. @@ -106,15 +106,8 @@ AbstractScriptArchEditor.mapManager = mapManager; } - /** - * A popup is opened and the user can create a new scripting event which - * gets attached to this gameObject. - * @param gameObject GameObject to add event to - * @param scriptArchData the <code>ScriptArchData</code> instance to - * display - * @param parent the parent frame for the editor - */ - public static <G extends GameObject<G, ?, ?>> void addEventScript(final G gameObject, final ScriptArchData<G> scriptArchData, @NotNull final Frame parent) { + /** {@inheritDoc} */ + public void addEventScript(final G gameObject, final ScriptArchData<G> scriptArchData, @NotNull final Frame parent) { final String archName = gameObject.getBestName(); // create a reasonable default script name for lazy users :-) final String defScriptName = ScriptUtils.chooseDefaultScriptName(mapManager.getLocalMapDir(), archName, scriptEnding); Added: trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptArchEditor.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptArchEditor.java 2008-10-16 17:31:35 UTC (rev 5544) @@ -0,0 +1,41 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gameobject.scripts; + +import java.awt.Frame; +import javax.swing.JDialog; +import net.sf.gridarta.gameobject.GameObject; +import org.jetbrains.annotations.NotNull; + +public interface ScriptArchEditor<G extends GameObject<G, ?, ?>> { + + void createNewEvent(JDialog frame, ScriptArchData<G> scriptArchData, @NotNull G gameObject); + + /** + * A popup is opened and the user can create a new scripting event which + * gets attached to this gameObject. + * @param gameObject GameObject to add event to + * @param scriptArchData the <code>ScriptArchData</code> instance to + * display + * @param parent the parent frame for the editor + */ + void addEventScript(G gameObject, ScriptArchData<G> scriptArchData, @NotNull Frame parent); + +} // interface ScriptArchEditor Property changes on: trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptArchEditor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-16 18:00:05
|
Revision: 5545 http://gridarta.svn.sourceforge.net/gridarta/?rev=5545&view=rev Author: akirschbaum Date: 2008-10-16 17:59:55 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Add ScriptedEventFactory. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java trunk/src/app/net/sf/gridarta/AbstractMainControl.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEventFactory.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEventFactory.java trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventFactory.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 17:31:35 UTC (rev 5544) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 17:59:55 UTC (rev 5545) @@ -30,6 +30,7 @@ import cfeditor.gameobject.scripts.DefaultScriptArchData; import cfeditor.gameobject.scripts.DefaultScriptArchEditor; import cfeditor.gameobject.scripts.DefaultScriptArchUtils; +import cfeditor.gameobject.scripts.DefaultScriptedEventFactory; import cfeditor.gui.map.CMapViewBasic; import cfeditor.gui.map.DefaultMapPropertiesDialogFactory; import cfeditor.gui.map.DefaultMapViewFactory; @@ -62,6 +63,7 @@ import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; +import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; import net.sf.gridarta.gui.MainView; import net.sf.gridarta.gui.MapViewManager; import net.sf.gridarta.gui.archetypechooser.ArchetypeChooserControl; @@ -131,13 +133,20 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptArchEditor<GameObject> newScriptArchEditor() { - return new DefaultScriptArchEditor(); + protected ScriptedEventFactory<GameObject> newScriptedEventFactory() { + return new DefaultScriptedEventFactory(); } /** {@inheritDoc} */ @NotNull @Override + protected ScriptArchEditor<GameObject> newScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { + return new DefaultScriptArchEditor(scriptedEventFactory); + } + + /** {@inheritDoc} */ + @NotNull + @Override protected DefaultScriptArchUtils newScriptArchUtils() { return new DefaultScriptArchUtils(); } @@ -145,8 +154,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected DefaultScriptArchData newScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { - return new DefaultScriptArchData(scriptArchUtils, scriptArchEditor, "subtype", Archetype.TYPE_EVENT_CONNECTOR); + protected DefaultScriptArchData newScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { + return new DefaultScriptArchData(scriptedEventFactory, scriptArchUtils, scriptArchEditor, "subtype", Archetype.TYPE_EVENT_CONNECTOR); } /** {@inheritDoc} */ Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:31:35 UTC (rev 5544) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:59:55 UTC (rev 5545) @@ -24,6 +24,8 @@ import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; +import net.sf.gridarta.gameobject.scripts.ScriptedEvent; +import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; import org.jetbrains.annotations.NotNull; /** @@ -39,6 +41,12 @@ private static final long serialVersionUID = 1L; /** + * The {@link ScriptedEventFactory} instance to use. + */ + @NotNull + private final ScriptedEventFactory<GameObject> scriptedEventFactory; + + /** * The {@link ScriptArchUtils} instance to use. */ @NotNull @@ -52,13 +60,15 @@ /** * Create a ScriptArchData. + * @param scriptedEventFactory the scripted event factory instance to use * @param scriptArchUtils the script arch utils instance to use * @param scriptArchEditor the script arch editor instance to use * @param subtypeAttribute the attribute name for the subtype field * @param eventTypeNo the object type for event objects */ - public DefaultScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { + public DefaultScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { super(subtypeAttribute, eventTypeNo, scriptArchUtils); + this.scriptedEventFactory = scriptedEventFactory; this.scriptArchUtils = scriptArchUtils; this.scriptArchEditor = scriptArchEditor; } @@ -66,8 +76,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected DefaultScriptedEvent newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { - return new DefaultScriptedEvent(scriptArchUtils, event, subtypeAttribute); + protected ScriptedEvent<GameObject> newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { + return scriptedEventFactory.newScriptedEvent(scriptArchUtils, event, subtypeAttribute); } /** {@inheritDoc} */ Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 17:31:35 UTC (rev 5544) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 17:59:55 UTC (rev 5545) @@ -26,6 +26,8 @@ import javax.swing.JOptionPane; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchData; +import net.sf.gridarta.gameobject.scripts.ScriptedEvent; +import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; import net.sf.japi.swing.ActionFactory; @@ -36,6 +38,20 @@ /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + /** + * The {@link ScriptedEventFactory} instance to use. + */ + @NotNull + private final ScriptedEventFactory<GameObject> scriptedEventFactory; + + /** + * Creates a new instance. + * @param scriptedEventFactory the scripted event factory instance to use + */ + public DefaultScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { + this.scriptedEventFactory = scriptedEventFactory; + } + /** {@inheritDoc} */ public void createNewEvent(final JDialog frame, final ScriptArchData<GameObject> scriptArchData, @NotNull final GameObject gameObject) { String scriptPath = inputScriptPath.getText().trim(); @@ -85,9 +101,9 @@ if (newScriptFile.exists()) { if (newScriptFile.isFile()) { // file exists -> link it to the event - final DefaultScriptedEvent event; + final ScriptedEvent<GameObject> event; try { - event = new DefaultScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); + event = scriptedEventFactory.newScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; @@ -120,9 +136,9 @@ JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); } else { // file has been created, now link it to the event - final DefaultScriptedEvent event; + final ScriptedEvent<GameObject> event; try { - event = new DefaultScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); + event = scriptedEventFactory.newScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; Added: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEventFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEventFactory.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEventFactory.java 2008-10-16 17:59:55 UTC (rev 5545) @@ -0,0 +1,48 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package cfeditor.gameobject.scripts; + +import cfeditor.gameobject.GameObject; +import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; +import net.sf.gridarta.gameobject.scripts.ScriptedEvent; +import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import org.jetbrains.annotations.NotNull; + +/** + * Implements a {@link ScriptedEventFactory} for creating Crossfire related + * instances. + * @author Andreas Kirschbaum + */ +public class DefaultScriptedEventFactory implements ScriptedEventFactory<GameObject> { + + /** {@inheritDoc} */ + @NotNull + public ScriptedEvent<GameObject> newScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final int eventType, @NotNull final String subtypeAttribute, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { + return new DefaultScriptedEvent(scriptArchUtils, eventType, subtypeAttribute, pluginName, scriptPath, options); + } + + /** {@inheritDoc} */ + @NotNull + public ScriptedEvent<GameObject> newScriptedEvent(final ScriptArchUtils scriptArchUtils, final GameObject event, final String subtypeAttribute) { + return new DefaultScriptedEvent(scriptArchUtils, event, subtypeAttribute); + } + +} // class DefaultScriptedEventFactory Property changes on: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEventFactory.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 17:31:35 UTC (rev 5544) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 17:59:55 UTC (rev 5545) @@ -30,6 +30,7 @@ import daieditor.gameobject.scripts.DefaultScriptArchData; import daieditor.gameobject.scripts.DefaultScriptArchEditor; import daieditor.gameobject.scripts.DefaultScriptArchUtils; +import daieditor.gameobject.scripts.DefaultScriptedEventFactory; import daieditor.gui.map.CMapViewBasic; import daieditor.gui.map.DefaultMapPropertiesDialogFactory; import daieditor.gui.map.DefaultMapViewFactory; @@ -69,6 +70,7 @@ import net.sf.gridarta.gameobject.match.ViewGameObjectMatcherManager; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; +import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; import net.sf.gridarta.gui.MainView; import net.sf.gridarta.gui.MapViewManager; import net.sf.gridarta.gui.archetypechooser.ArchetypeChooserControl; @@ -176,13 +178,20 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptArchEditor<GameObject> newScriptArchEditor() { - return new DefaultScriptArchEditor(); + protected ScriptedEventFactory<GameObject> newScriptedEventFactory() { + return new DefaultScriptedEventFactory(); } /** {@inheritDoc} */ @NotNull @Override + protected ScriptArchEditor<GameObject> newScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { + return new DefaultScriptArchEditor(scriptedEventFactory); + } + + /** {@inheritDoc} */ + @NotNull + @Override protected DefaultScriptArchUtils newScriptArchUtils() { return new DefaultScriptArchUtils(); } @@ -190,8 +199,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected DefaultScriptArchData newScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { - return new DefaultScriptArchData(scriptArchUtils, scriptArchEditor, "sub_type", Archetype.TYPE_EVENT_OBJECT); + protected DefaultScriptArchData newScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { + return new DefaultScriptArchData(scriptedEventFactory, scriptArchUtils, scriptArchEditor, "sub_type", Archetype.TYPE_EVENT_OBJECT); } /** {@inheritDoc} */ Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:31:35 UTC (rev 5544) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:59:55 UTC (rev 5545) @@ -24,6 +24,8 @@ import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; +import net.sf.gridarta.gameobject.scripts.ScriptedEvent; +import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; import org.jetbrains.annotations.NotNull; /** @@ -39,6 +41,12 @@ private static final long serialVersionUID = 1L; /** + * The {@link ScriptedEventFactory} instance to use. + */ + @NotNull + private final ScriptedEventFactory<GameObject> scriptedEventFactory; + + /** * The {@link ScriptArchUtils} instance to use. */ @NotNull @@ -52,13 +60,15 @@ /** * Create a ScriptArchData. + * @param scriptedEventFactory the scripted event factory instance to use * @param scriptArchUtils the script arch utils instance to use * @param scriptArchEditor the script arch editor instance to use * @param subtypeAttribute the attribute name for the subtype field * @param eventTypeNo the object type for event objects */ - public DefaultScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { + public DefaultScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { super(subtypeAttribute, eventTypeNo, scriptArchUtils); + this.scriptedEventFactory = scriptedEventFactory; this.scriptArchUtils = scriptArchUtils; this.scriptArchEditor = scriptArchEditor; } @@ -66,8 +76,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected DefaultScriptedEvent newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { - return new DefaultScriptedEvent(scriptArchUtils, event, subtypeAttribute); + protected ScriptedEvent<GameObject> newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { + return scriptedEventFactory.newScriptedEvent(scriptArchUtils, event, subtypeAttribute); } /** {@inheritDoc} */ Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 17:31:35 UTC (rev 5544) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 17:59:55 UTC (rev 5545) @@ -26,6 +26,8 @@ import javax.swing.JOptionPane; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchData; +import net.sf.gridarta.gameobject.scripts.ScriptedEvent; +import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; import net.sf.japi.swing.ActionFactory; @@ -36,6 +38,20 @@ /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + /** + * The {@link ScriptedEventFactory} instance to use. + */ + @NotNull + private final ScriptedEventFactory<GameObject> scriptedEventFactory; + + /** + * Creates a new instance. + * @param scriptedEventFactory the scripted event factory instance to use + */ + public DefaultScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { + this.scriptedEventFactory = scriptedEventFactory; + } + /** {@inheritDoc} */ public void createNewEvent(final JDialog frame, final ScriptArchData<GameObject> scriptArchData, @NotNull final GameObject gameObject) { String scriptPath = inputScriptPath.getText().trim(); @@ -85,9 +101,9 @@ if (newScriptFile.exists()) { if (newScriptFile.isFile()) { // file exists -> link it to the event - final DefaultScriptedEvent event; + final ScriptedEvent<GameObject> event; try { - event = new DefaultScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); + event = scriptedEventFactory.newScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; @@ -120,9 +136,9 @@ JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); } else { // file has been created, now link it to the event - final DefaultScriptedEvent event; + final ScriptedEvent<GameObject> event; try { - event = new DefaultScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); + event = scriptedEventFactory.newScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; Added: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEventFactory.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEventFactory.java (rev 0) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEventFactory.java 2008-10-16 17:59:55 UTC (rev 5545) @@ -0,0 +1,48 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package daieditor.gameobject.scripts; + +import daieditor.gameobject.GameObject; +import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; +import net.sf.gridarta.gameobject.scripts.ScriptedEvent; +import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import org.jetbrains.annotations.NotNull; + +/** + * Implements a {@link ScriptedEventFactory} for creating Crossfire related + * instances. + * @author Andreas Kirschbaum + */ +public class DefaultScriptedEventFactory implements ScriptedEventFactory<GameObject> { + + /** {@inheritDoc} */ + @NotNull + public ScriptedEvent<GameObject> newScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final int eventType, @NotNull final String subtypeAttribute, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { + return new DefaultScriptedEvent(scriptArchUtils, eventType, subtypeAttribute, pluginName, scriptPath, options); + } + + /** {@inheritDoc} */ + @NotNull + public ScriptedEvent<GameObject> newScriptedEvent(final ScriptArchUtils scriptArchUtils, final GameObject event, final String subtypeAttribute) { + return new DefaultScriptedEvent(scriptArchUtils, event, subtypeAttribute); + } + +} // class DefaultScriptedEventFactory Property changes on: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEventFactory.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/AbstractMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-16 17:31:35 UTC (rev 5544) +++ trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-16 17:59:55 UTC (rev 5545) @@ -63,6 +63,7 @@ import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; +import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; import net.sf.gridarta.gui.About; import net.sf.gridarta.gui.HideFileFilterProxy; import net.sf.gridarta.gui.LeftPanel; @@ -472,8 +473,9 @@ final MapViewFactory<G, A, R, V> mapViewFactory = newMapViewFactory(faceObjects, selectedSquareView, this, mainView, editTypes, mapImageCache, toolPalette, filterControl); mapControlFactory.init(mapViewFactory, gameObjectParser, rendererFactory, mapActions, archetypeChooserModel, mapImageCache, autojoinLists, exitMatcher); copyBuffer.init(mapArchObjectFactory.newMapArchObject(false), mainView); - final ScriptArchEditor<G> scriptArchEditor = newScriptArchEditor(); - GameObject.initialize(archetypeSet, archetypeTypeSet, gameObjectMatchers, scriptArchEditor, animationObjects, SystemIcons.getNofaceTileIcon(), newScriptArchData(scriptArchUtils, scriptArchEditor)); + final ScriptedEventFactory<G> scriptedEventFactory = newScriptedEventFactory(); + final ScriptArchEditor<G> scriptArchEditor = newScriptArchEditor(scriptedEventFactory); + GameObject.initialize(archetypeSet, archetypeTypeSet, gameObjectMatchers, scriptArchEditor, animationObjects, SystemIcons.getNofaceTileIcon(), newScriptArchData(scriptedEventFactory, scriptArchUtils, scriptArchEditor)); init4(gameObjectParser, archetypeParser, editTypes, faceObjects, animationObjects, mainView, globalSettings, archetypeSet); if (globalSettings.isAutoPopupDocu()) { @@ -510,13 +512,16 @@ } @NotNull - protected abstract ScriptArchEditor<G> newScriptArchEditor(); + protected abstract ScriptedEventFactory<G> newScriptedEventFactory(); @NotNull + protected abstract ScriptArchEditor<G> newScriptArchEditor(@NotNull final ScriptedEventFactory<G> scriptedEventFactory); + + @NotNull protected abstract ScriptArchUtils newScriptArchUtils(); @NotNull - protected abstract ScriptArchData<G> newScriptArchData(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<G> scriptArchEditor); + protected abstract ScriptArchData<G> newScriptArchData(@NotNull final ScriptedEventFactory<G> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<G> scriptArchEditor); @NotNull protected abstract ArchetypeFactory<G, A, R> newArchetypeFactory(); Added: trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventFactory.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventFactory.java 2008-10-16 17:59:55 UTC (rev 5545) @@ -0,0 +1,56 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gameobject.scripts; + +import net.sf.gridarta.gameobject.GameObject; +import org.jetbrains.annotations.NotNull; + +/** + * Factory for creating {@link ScriptedEvent} instances. + * @author Andreas Kirschbaum + */ +public interface ScriptedEventFactory<G extends GameObject<G, ?, ?>> { + + /** + * Creates a new {@link ScriptedEvent} instance. + * @param scriptArchUtils the script arch utils instance to use + * @param eventType type of the event + * @param subtypeAttribute the attribute name for the subtype field + * @param pluginName name of the plugin + * @param scriptPath path to the file for this event + * @param options the options for this event + * @return the new instance + * @throws UndefinedEventArchetypeException In case there is no Archetype to + * create a ScriptedEvent. + */ + @NotNull + ScriptedEvent<G> newScriptedEvent(@NotNull ScriptArchUtils scriptArchUtils, int eventType, @NotNull String subtypeAttribute, String pluginName, String scriptPath, String options) throws UndefinedEventArchetypeException; + + /** + * Creates a new {@link ScriptedEvent} instance. + * @param scriptArchUtils the script arch utils instance to use + * @param event the event game object + * @param subtypeAttribute the attribute name for the subtype field + * @return the new instance + */ + @NotNull + ScriptedEvent<G> newScriptedEvent(ScriptArchUtils scriptArchUtils, G event, String subtypeAttribute); + +} // interface ScriptedEventFactory Property changes on: trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventFactory.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-16 18:19:37
|
Revision: 5546 http://gridarta.svn.sourceforge.net/gridarta/?rev=5546&view=rev Author: akirschbaum Date: 2008-10-16 18:19:26 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Remove redundant parameters from ScriptedEventFactory.newScriptedEvent(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEventFactory.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEventFactory.java trunk/src/app/net/sf/gridarta/AbstractMainControl.java trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventFactory.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 17:59:55 UTC (rev 5545) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 18:19:26 UTC (rev 5546) @@ -133,8 +133,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptedEventFactory<GameObject> newScriptedEventFactory() { - return new DefaultScriptedEventFactory(); + protected ScriptedEventFactory<GameObject> newScriptedEventFactory(@NotNull final ScriptArchUtils scriptArchUtils) { + return new DefaultScriptedEventFactory(scriptArchUtils, "subtype"); } /** {@inheritDoc} */ Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:59:55 UTC (rev 5545) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 18:19:26 UTC (rev 5546) @@ -47,12 +47,6 @@ private final ScriptedEventFactory<GameObject> scriptedEventFactory; /** - * The {@link ScriptArchUtils} instance to use. - */ - @NotNull - private final ScriptArchUtils scriptArchUtils; - - /** * The {@link ScriptArchEditor} instance to use. */ @NotNull @@ -69,15 +63,14 @@ public DefaultScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { super(subtypeAttribute, eventTypeNo, scriptArchUtils); this.scriptedEventFactory = scriptedEventFactory; - this.scriptArchUtils = scriptArchUtils; this.scriptArchEditor = scriptArchEditor; } /** {@inheritDoc} */ @NotNull @Override - protected ScriptedEvent<GameObject> newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { - return scriptedEventFactory.newScriptedEvent(scriptArchUtils, event, subtypeAttribute); + protected ScriptedEvent<GameObject> newScriptedEvent(@NotNull final GameObject event) { + return scriptedEventFactory.newScriptedEvent(event); } /** {@inheritDoc} */ Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 17:59:55 UTC (rev 5545) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 18:19:26 UTC (rev 5546) @@ -103,7 +103,7 @@ // file exists -> link it to the event final ScriptedEvent<GameObject> event; try { - event = scriptedEventFactory.newScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); + event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; @@ -138,7 +138,7 @@ // file has been created, now link it to the event final ScriptedEvent<GameObject> event; try { - event = scriptedEventFactory.newScriptedEvent(scriptArchUtils, eventType, "subtype", pluginName, scriptPath, options); + event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEventFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEventFactory.java 2008-10-16 17:59:55 UTC (rev 5545) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptedEventFactory.java 2008-10-16 18:19:26 UTC (rev 5546) @@ -33,15 +33,37 @@ */ public class DefaultScriptedEventFactory implements ScriptedEventFactory<GameObject> { + /** + * The script arch utils instance to use. + */ + @NotNull + private final ScriptArchUtils scriptArchUtils; + + /** + * The attribute name for the subtype field. + */ + @NotNull + private final String subtypeAttribute; + + /** + * Creates a new instance. + * @param scriptArchUtils the script arch utils instance to use + * @param subtypeAttribute the attribute name for the subtype field + */ + public DefaultScriptedEventFactory(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final String subtypeAttribute) { + this.scriptArchUtils = scriptArchUtils; + this.subtypeAttribute = subtypeAttribute; + } + /** {@inheritDoc} */ @NotNull - public ScriptedEvent<GameObject> newScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final int eventType, @NotNull final String subtypeAttribute, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { + public ScriptedEvent<GameObject> newScriptedEvent(final int eventType, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { return new DefaultScriptedEvent(scriptArchUtils, eventType, subtypeAttribute, pluginName, scriptPath, options); } /** {@inheritDoc} */ @NotNull - public ScriptedEvent<GameObject> newScriptedEvent(final ScriptArchUtils scriptArchUtils, final GameObject event, final String subtypeAttribute) { + public ScriptedEvent<GameObject> newScriptedEvent(final GameObject event) { return new DefaultScriptedEvent(scriptArchUtils, event, subtypeAttribute); } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 17:59:55 UTC (rev 5545) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 18:19:26 UTC (rev 5546) @@ -178,8 +178,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptedEventFactory<GameObject> newScriptedEventFactory() { - return new DefaultScriptedEventFactory(); + protected ScriptedEventFactory<GameObject> newScriptedEventFactory(@NotNull final ScriptArchUtils scriptArchUtils) { + return new DefaultScriptedEventFactory(scriptArchUtils, "sub_type"); } /** {@inheritDoc} */ Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 17:59:55 UTC (rev 5545) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-16 18:19:26 UTC (rev 5546) @@ -47,12 +47,6 @@ private final ScriptedEventFactory<GameObject> scriptedEventFactory; /** - * The {@link ScriptArchUtils} instance to use. - */ - @NotNull - private final ScriptArchUtils scriptArchUtils; - - /** * The {@link ScriptArchEditor} instance to use. */ @NotNull @@ -69,15 +63,14 @@ public DefaultScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { super(subtypeAttribute, eventTypeNo, scriptArchUtils); this.scriptedEventFactory = scriptedEventFactory; - this.scriptArchUtils = scriptArchUtils; this.scriptArchEditor = scriptArchEditor; } /** {@inheritDoc} */ @NotNull @Override - protected ScriptedEvent<GameObject> newScriptedEvent(@NotNull final GameObject event, @NotNull final String subtypeAttribute) { - return scriptedEventFactory.newScriptedEvent(scriptArchUtils, event, subtypeAttribute); + protected ScriptedEvent<GameObject> newScriptedEvent(@NotNull final GameObject event) { + return scriptedEventFactory.newScriptedEvent(event); } /** {@inheritDoc} */ Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 17:59:55 UTC (rev 5545) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 18:19:26 UTC (rev 5546) @@ -103,7 +103,7 @@ // file exists -> link it to the event final ScriptedEvent<GameObject> event; try { - event = scriptedEventFactory.newScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); + event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; @@ -138,7 +138,7 @@ // file has been created, now link it to the event final ScriptedEvent<GameObject> event; try { - event = scriptedEventFactory.newScriptedEvent(scriptArchUtils, eventType, "sub_type", pluginName, scriptPath, options); + event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); } catch (final UndefinedEventArchetypeException ex) { JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); return; Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEventFactory.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEventFactory.java 2008-10-16 17:59:55 UTC (rev 5545) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptedEventFactory.java 2008-10-16 18:19:26 UTC (rev 5546) @@ -33,15 +33,37 @@ */ public class DefaultScriptedEventFactory implements ScriptedEventFactory<GameObject> { + /** + * The script arch utils instance to use. + */ + @NotNull + private final ScriptArchUtils scriptArchUtils; + + /** + * The attribute name for the subtype field. + */ + @NotNull + private final String subtypeAttribute; + + /** + * Creates a new instance. + * @param scriptArchUtils the script arch utils instance to use + * @param subtypeAttribute the attribute name for the subtype field + */ + public DefaultScriptedEventFactory(@NotNull final ScriptArchUtils scriptArchUtils, @NotNull final String subtypeAttribute) { + this.scriptArchUtils = scriptArchUtils; + this.subtypeAttribute = subtypeAttribute; + } + /** {@inheritDoc} */ @NotNull - public ScriptedEvent<GameObject> newScriptedEvent(@NotNull final ScriptArchUtils scriptArchUtils, final int eventType, @NotNull final String subtypeAttribute, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { + public ScriptedEvent<GameObject> newScriptedEvent(final int eventType, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { return new DefaultScriptedEvent(scriptArchUtils, eventType, subtypeAttribute, pluginName, scriptPath, options); } /** {@inheritDoc} */ @NotNull - public ScriptedEvent<GameObject> newScriptedEvent(final ScriptArchUtils scriptArchUtils, final GameObject event, final String subtypeAttribute) { + public ScriptedEvent<GameObject> newScriptedEvent(final GameObject event) { return new DefaultScriptedEvent(scriptArchUtils, event, subtypeAttribute); } Modified: trunk/src/app/net/sf/gridarta/AbstractMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-16 17:59:55 UTC (rev 5545) +++ trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-16 18:19:26 UTC (rev 5546) @@ -473,7 +473,7 @@ final MapViewFactory<G, A, R, V> mapViewFactory = newMapViewFactory(faceObjects, selectedSquareView, this, mainView, editTypes, mapImageCache, toolPalette, filterControl); mapControlFactory.init(mapViewFactory, gameObjectParser, rendererFactory, mapActions, archetypeChooserModel, mapImageCache, autojoinLists, exitMatcher); copyBuffer.init(mapArchObjectFactory.newMapArchObject(false), mainView); - final ScriptedEventFactory<G> scriptedEventFactory = newScriptedEventFactory(); + final ScriptedEventFactory<G> scriptedEventFactory = newScriptedEventFactory(scriptArchUtils); final ScriptArchEditor<G> scriptArchEditor = newScriptArchEditor(scriptedEventFactory); GameObject.initialize(archetypeSet, archetypeTypeSet, gameObjectMatchers, scriptArchEditor, animationObjects, SystemIcons.getNofaceTileIcon(), newScriptArchData(scriptedEventFactory, scriptArchUtils, scriptArchEditor)); init4(gameObjectParser, archetypeParser, editTypes, faceObjects, animationObjects, mainView, globalSettings, archetypeSet); @@ -512,7 +512,7 @@ } @NotNull - protected abstract ScriptedEventFactory<G> newScriptedEventFactory(); + protected abstract ScriptedEventFactory<G> newScriptedEventFactory(@NotNull final ScriptArchUtils scriptArchUtils); @NotNull protected abstract ScriptArchEditor<G> newScriptArchEditor(@NotNull final ScriptedEventFactory<G> scriptedEventFactory); Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-16 17:59:55 UTC (rev 5545) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-16 18:19:26 UTC (rev 5546) @@ -108,7 +108,7 @@ while (it.hasNext()) { final G tmp = it.next(); if (tmp.getTypeNo() == eventTypeNo) { - final ScriptedEvent<G> se = newScriptedEvent(tmp, subtypeAttribute); + final ScriptedEvent<G> se = newScriptedEvent(tmp); // validate this event if (!se.isValid()) { // this event is invalid @@ -149,7 +149,7 @@ } if (oldEvent != null) { - final ScriptedEvent<G> event = newScriptedEvent(oldEvent, subtypeAttribute); + final ScriptedEvent<G> event = newScriptedEvent(oldEvent); // now decide what to do: if (task == ScriptTab.SCRIPT_OPEN) { ScriptedEventEditor.openScript(mapManager, event.getScriptPath(), parent); @@ -169,6 +169,6 @@ } @NotNull - protected abstract ScriptedEvent<G> newScriptedEvent(@NotNull final G event, @NotNull final String subtypeAttribute); + protected abstract ScriptedEvent<G> newScriptedEvent(@NotNull final G event); } // class AbstractScriptArchData Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventFactory.java 2008-10-16 17:59:55 UTC (rev 5545) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventFactory.java 2008-10-16 18:19:26 UTC (rev 5546) @@ -30,9 +30,7 @@ /** * Creates a new {@link ScriptedEvent} instance. - * @param scriptArchUtils the script arch utils instance to use * @param eventType type of the event - * @param subtypeAttribute the attribute name for the subtype field * @param pluginName name of the plugin * @param scriptPath path to the file for this event * @param options the options for this event @@ -41,16 +39,14 @@ * create a ScriptedEvent. */ @NotNull - ScriptedEvent<G> newScriptedEvent(@NotNull ScriptArchUtils scriptArchUtils, int eventType, @NotNull String subtypeAttribute, String pluginName, String scriptPath, String options) throws UndefinedEventArchetypeException; + ScriptedEvent<G> newScriptedEvent(int eventType, String pluginName, String scriptPath, String options) throws UndefinedEventArchetypeException; /** * Creates a new {@link ScriptedEvent} instance. - * @param scriptArchUtils the script arch utils instance to use * @param event the event game object - * @param subtypeAttribute the attribute name for the subtype field * @return the new instance */ @NotNull - ScriptedEvent<G> newScriptedEvent(ScriptArchUtils scriptArchUtils, G event, String subtypeAttribute); + ScriptedEvent<G> newScriptedEvent(G event); } // interface ScriptedEventFactory This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-16 18:25:54
|
Revision: 5547 http://gridarta.svn.sourceforge.net/gridarta/?rev=5547&view=rev Author: akirschbaum Date: 2008-10-16 18:25:43 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Move ScriptArchEditor.createNewEvent() to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 18:19:26 UTC (rev 5546) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 18:25:43 UTC (rev 5547) @@ -20,140 +20,18 @@ package cfeditor.gameobject.scripts; import cfeditor.gameobject.GameObject; -import java.io.File; -import java.io.IOException; -import javax.swing.JDialog; -import javax.swing.JOptionPane; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; -import net.sf.gridarta.gameobject.scripts.ScriptArchData; -import net.sf.gridarta.gameobject.scripts.ScriptedEvent; import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; -import net.sf.japi.swing.ActionFactory; import org.jetbrains.annotations.NotNull; public class DefaultScriptArchEditor extends AbstractScriptArchEditor<GameObject> { - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - /** - * The {@link ScriptedEventFactory} instance to use. - */ - @NotNull - private final ScriptedEventFactory<GameObject> scriptedEventFactory; - - /** * Creates a new instance. * @param scriptedEventFactory the scripted event factory instance to use */ public DefaultScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { - this.scriptedEventFactory = scriptedEventFactory; + super(scriptedEventFactory); } - /** {@inheritDoc} */ - public void createNewEvent(final JDialog frame, final ScriptArchData<GameObject> scriptArchData, @NotNull final GameObject gameObject) { - String scriptPath = inputScriptPath.getText().trim(); - final String options = inputOptions.getText().trim(); - final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); - final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); - - final File localMapDir = mapManager.getLocalMapDir(); - - // first check if that event type is not already in use - final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType, gameObject); - if (replaceObject != null) { - // collision with existing event -> ask user: replace? - if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + scriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { - // bail out - return; - } - } - - // convert localized scriptPath into real, absolute path - scriptPath = scriptPath.replace('\\', '/'); - String absScriptPath; - if (scriptPath.startsWith("/")) { - // script path is absolute - final File mapDir = new File(globalSettings.getMapDefaultFolder()); // global map directory - if (!mapDir.exists()) { - // if map dir doesn't exist, this is not going to work - frame.setVisible(false); - ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); - return; - } else { - absScriptPath = mapDir.getAbsolutePath() + scriptPath; - } - } else { - // script path is relative - absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; - } - - // now check if the specified path points to an existing script - File newScriptFile = new File(absScriptPath); - if (!newScriptFile.exists() && !absScriptPath.endsWith(scriptEnding)) { - absScriptPath += scriptEnding; - scriptPath += scriptEnding; - newScriptFile = new File(absScriptPath); - } - - if (newScriptFile.exists()) { - if (newScriptFile.isFile()) { - // file exists -> link it to the event - final ScriptedEvent<GameObject> event; - try { - event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return; - } - if (replaceObject != null) { - replaceObject.remove(); - } - gameObject.addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - } - } else { - if (!absScriptPath.endsWith(scriptEnding)) { - absScriptPath += scriptEnding; - scriptPath += scriptEnding; - newScriptFile = new File(absScriptPath); - } - - // file does not exist -> aks user: create new file? - if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { - // okay, create new script file and open it - boolean couldCreateFile = false; // true when file creation successful - try { - // try to create new empty file - couldCreateFile = newScriptFile.createNewFile(); - } catch (final IOException e) { - /* ignore (really?) */ - } - - if (!couldCreateFile) { - JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); - } else { - // file has been created, now link it to the event - final ScriptedEvent<GameObject> event; - try { - event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return; - } - if (replaceObject != null) { - replaceObject.remove(); - } - gameObject.addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - - // open new script file - ScriptEditControlInstance.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); - } - } - } - } - } // class DefaultScriptArchEditor Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 18:19:26 UTC (rev 5546) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 18:25:43 UTC (rev 5547) @@ -20,140 +20,18 @@ package daieditor.gameobject.scripts; import daieditor.gameobject.GameObject; -import java.io.File; -import java.io.IOException; -import javax.swing.JDialog; -import javax.swing.JOptionPane; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; -import net.sf.gridarta.gameobject.scripts.ScriptArchData; -import net.sf.gridarta.gameobject.scripts.ScriptedEvent; import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; -import net.sf.japi.swing.ActionFactory; import org.jetbrains.annotations.NotNull; public class DefaultScriptArchEditor extends AbstractScriptArchEditor<GameObject> { - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - /** - * The {@link ScriptedEventFactory} instance to use. - */ - @NotNull - private final ScriptedEventFactory<GameObject> scriptedEventFactory; - - /** * Creates a new instance. * @param scriptedEventFactory the scripted event factory instance to use */ public DefaultScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { - this.scriptedEventFactory = scriptedEventFactory; + super(scriptedEventFactory); } - /** {@inheritDoc} */ - public void createNewEvent(final JDialog frame, final ScriptArchData<GameObject> scriptArchData, @NotNull final GameObject gameObject) { - String scriptPath = inputScriptPath.getText().trim(); - final String options = inputOptions.getText().trim(); - final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); - final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); - - final File localMapDir = mapManager.getLocalMapDir(); - - // first check if that event type is not already in use - final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType, gameObject); - if (replaceObject != null) { - // collision with existing event -> ask user: replace? - if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + scriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { - // bail out - return; - } - } - - // convert localized scriptPath into real, absolute path - scriptPath = scriptPath.replace('\\', '/'); - String absScriptPath; - if (scriptPath.startsWith("/")) { - // script path is absolute - final File mapDir = new File(globalSettings.getMapDefaultFolder()); // global map directory - if (!mapDir.exists()) { - // if map dir doesn't exist, this is not going to work - frame.setVisible(false); - ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); - return; - } else { - absScriptPath = mapDir.getAbsolutePath() + scriptPath; - } - } else { - // script path is relative - absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; - } - - // now check if the specified path points to an existing script - File newScriptFile = new File(absScriptPath); - if (!newScriptFile.exists() && !absScriptPath.endsWith(scriptEnding)) { - absScriptPath += scriptEnding; - scriptPath += scriptEnding; - newScriptFile = new File(absScriptPath); - } - - if (newScriptFile.exists()) { - if (newScriptFile.isFile()) { - // file exists -> link it to the event - final ScriptedEvent<GameObject> event; - try { - event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return; - } - if (replaceObject != null) { - replaceObject.remove(); - } - gameObject.addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - } - } else { - if (!absScriptPath.endsWith(scriptEnding)) { - absScriptPath += scriptEnding; - scriptPath += scriptEnding; - newScriptFile = new File(absScriptPath); - } - - // file does not exist -> aks user: create new file? - if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { - // okay, create new script file and open it - boolean couldCreateFile = false; // true when file creation successful - try { - // try to create new empty file - couldCreateFile = newScriptFile.createNewFile(); - } catch (final IOException e) { - /* ignore (really?) */ - } - - if (!couldCreateFile) { - JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); - } else { - // file has been created, now link it to the event - final ScriptedEvent<GameObject> event; - try { - event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return; - } - if (replaceObject != null) { - replaceObject.remove(); - } - gameObject.addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - - // open new script file - ScriptEditControlInstance.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); - } - } - } - } - } // class DefaultScriptArchEditor Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java 2008-10-16 18:19:26 UTC (rev 5546) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java 2008-10-16 18:25:43 UTC (rev 5547) @@ -26,6 +26,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; +import java.io.IOException; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; @@ -34,6 +35,7 @@ import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.WindowConstants; @@ -41,10 +43,15 @@ import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.MapManager; import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; +import net.sf.japi.swing.ActionFactory; import org.jetbrains.annotations.NotNull; public abstract class AbstractScriptArchEditor<G extends GameObject<G, ?, ?>> implements ScriptArchEditor<G> { + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.gridarta"); + /** * The {@link ScriptArchUtils} instance to use. */ @@ -80,8 +87,15 @@ private static PathButtonListener nsOkListener; + /** + * The {@link ScriptedEventFactory} instance to use. + */ + @NotNull + private final ScriptedEventFactory<G> scriptedEventFactory; + /** Creates a new instance. */ - protected AbstractScriptArchEditor() { + protected AbstractScriptArchEditor(@NotNull final ScriptedEventFactory<G> scriptedEventFactory) { + this.scriptedEventFactory = scriptedEventFactory; } /** @@ -221,4 +235,108 @@ } } + /** {@inheritDoc} */ + public void createNewEvent(final JDialog frame, final ScriptArchData<G> scriptArchData, @NotNull final G gameObject) { + String scriptPath = inputScriptPath.getText().trim(); + final String options = inputOptions.getText().trim(); + final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); + final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); + + final File localMapDir = mapManager.getLocalMapDir(); + + // first check if that event type is not already in use + final G replaceObject = scriptArchData.getScriptedEvent(eventType, gameObject); + if (replaceObject != null) { + // collision with existing event -> ask user: replace? + if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + scriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { + // bail out + return; + } + } + + // convert localized scriptPath into real, absolute path + scriptPath = scriptPath.replace('\\', '/'); + String absScriptPath; + if (scriptPath.startsWith("/")) { + // script path is absolute + final File mapDir = new File(globalSettings.getMapDefaultFolder()); // global map directory + if (!mapDir.exists()) { + // if map dir doesn't exist, this is not going to work + frame.setVisible(false); + ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); + return; + } else { + absScriptPath = mapDir.getAbsolutePath() + scriptPath; + } + } else { + // script path is relative + absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; + } + + // now check if the specified path points to an existing script + File newScriptFile = new File(absScriptPath); + if (!newScriptFile.exists() && !absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; + newScriptFile = new File(absScriptPath); + } + + if (newScriptFile.exists()) { + if (newScriptFile.isFile()) { + // file exists -> link it to the event + final ScriptedEvent<G> event; + try { + event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); + } catch (final UndefinedEventArchetypeException ex) { + JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); + return; + } + if (replaceObject != null) { + replaceObject.remove(); + } + gameObject.addLast(event.getEventArch()); + frame.setVisible(false); // close dialog + } + } else { + if (!absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; + newScriptFile = new File(absScriptPath); + } + + // file does not exist -> aks user: create new file? + if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { + // okay, create new script file and open it + boolean couldCreateFile = false; // true when file creation successful + try { + // try to create new empty file + couldCreateFile = newScriptFile.createNewFile(); + } catch (final IOException e) { + /* ignore (really?) */ + } + + if (!couldCreateFile) { + JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); + } else { + // file has been created, now link it to the event + final ScriptedEvent<G> event; + try { + event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); + } catch (final UndefinedEventArchetypeException ex) { + JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); + return; + } + if (replaceObject != null) { + replaceObject.remove(); + } + gameObject.addLast(event.getEventArch()); + frame.setVisible(false); // close dialog + + // open new script file + ScriptEditControlInstance.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); + } + } + } + } + } // class AbstractScriptArchEditor This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-16 18:30:56
|
Revision: 5548 http://gridarta.svn.sourceforge.net/gridarta/?rev=5548&view=rev Author: akirschbaum Date: 2008-10-16 18:30:44 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Remove empty classes DefaultScriptArchEditor. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 18:25:43 UTC (rev 5547) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 18:30:44 UTC (rev 5548) @@ -28,7 +28,6 @@ import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObjects; import cfeditor.gameobject.scripts.DefaultScriptArchData; -import cfeditor.gameobject.scripts.DefaultScriptArchEditor; import cfeditor.gameobject.scripts.DefaultScriptArchUtils; import cfeditor.gameobject.scripts.DefaultScriptedEventFactory; import cfeditor.gui.map.CMapViewBasic; @@ -61,6 +60,7 @@ import net.sf.gridarta.gameobject.face.FaceObjectProviders; import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.gameobject.match.GameObjectMatcher; +import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; @@ -141,7 +141,7 @@ @NotNull @Override protected ScriptArchEditor<GameObject> newScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { - return new DefaultScriptArchEditor(scriptedEventFactory); + return new AbstractScriptArchEditor<GameObject>(scriptedEventFactory); } /** {@inheritDoc} */ Deleted: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 18:25:43 UTC (rev 5547) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 18:30:44 UTC (rev 5548) @@ -1,37 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package cfeditor.gameobject.scripts; - -import cfeditor.gameobject.GameObject; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; -import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; -import org.jetbrains.annotations.NotNull; - -public class DefaultScriptArchEditor extends AbstractScriptArchEditor<GameObject> { - - /** - * Creates a new instance. - * @param scriptedEventFactory the scripted event factory instance to use - */ - public DefaultScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { - super(scriptedEventFactory); - } - -} // class DefaultScriptArchEditor Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 18:25:43 UTC (rev 5547) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 18:30:44 UTC (rev 5548) @@ -28,7 +28,6 @@ import daieditor.gameobject.GameObject; import daieditor.gameobject.anim.AnimationObjects; import daieditor.gameobject.scripts.DefaultScriptArchData; -import daieditor.gameobject.scripts.DefaultScriptArchEditor; import daieditor.gameobject.scripts.DefaultScriptArchUtils; import daieditor.gameobject.scripts.DefaultScriptedEventFactory; import daieditor.gui.map.CMapViewBasic; @@ -68,6 +67,7 @@ import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.gameobject.match.MutableOrGameObjectMatcher; import net.sf.gridarta.gameobject.match.ViewGameObjectMatcherManager; +import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; @@ -186,7 +186,7 @@ @NotNull @Override protected ScriptArchEditor<GameObject> newScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { - return new DefaultScriptArchEditor(scriptedEventFactory); + return new AbstractScriptArchEditor<GameObject>(scriptedEventFactory); } /** {@inheritDoc} */ Deleted: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 18:25:43 UTC (rev 5547) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 18:30:44 UTC (rev 5548) @@ -1,37 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor.gameobject.scripts; - -import daieditor.gameobject.GameObject; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; -import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; -import org.jetbrains.annotations.NotNull; - -public class DefaultScriptArchEditor extends AbstractScriptArchEditor<GameObject> { - - /** - * Creates a new instance. - * @param scriptedEventFactory the scripted event factory instance to use - */ - public DefaultScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { - super(scriptedEventFactory); - } - -} // class DefaultScriptArchEditor Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java 2008-10-16 18:25:43 UTC (rev 5547) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java 2008-10-16 18:30:44 UTC (rev 5548) @@ -47,7 +47,7 @@ import net.sf.japi.swing.ActionFactory; import org.jetbrains.annotations.NotNull; -public abstract class AbstractScriptArchEditor<G extends GameObject<G, ?, ?>> implements ScriptArchEditor<G> { +public class AbstractScriptArchEditor<G extends GameObject<G, ?, ?>> implements ScriptArchEditor<G> { /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.gridarta"); @@ -93,8 +93,11 @@ @NotNull private final ScriptedEventFactory<G> scriptedEventFactory; - /** Creates a new instance. */ - protected AbstractScriptArchEditor(@NotNull final ScriptedEventFactory<G> scriptedEventFactory) { + /** + * Creates a new instance. + * @param scriptedEventFactory the scripted event factory instance to use + */ + public AbstractScriptArchEditor(@NotNull final ScriptedEventFactory<G> scriptedEventFactory) { this.scriptedEventFactory = scriptedEventFactory; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-16 18:32:48
|
Revision: 5549 http://gridarta.svn.sourceforge.net/gridarta/?rev=5549&view=rev Author: akirschbaum Date: 2008-10-16 18:32:36 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Rename AbstractScriptArchEditor to DefaultScriptArchEditor since it is not anymore abstract. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/src/app/net/sf/gridarta/AbstractMainControl.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchEditor.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 18:30:44 UTC (rev 5548) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-16 18:32:36 UTC (rev 5549) @@ -60,7 +60,7 @@ import net.sf.gridarta.gameobject.face.FaceObjectProviders; import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.gameobject.match.GameObjectMatcher; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.DefaultScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; @@ -141,7 +141,7 @@ @NotNull @Override protected ScriptArchEditor<GameObject> newScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { - return new AbstractScriptArchEditor<GameObject>(scriptedEventFactory); + return new DefaultScriptArchEditor<GameObject>(scriptedEventFactory); } /** {@inheritDoc} */ Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 18:30:44 UTC (rev 5548) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-16 18:32:36 UTC (rev 5549) @@ -67,7 +67,7 @@ import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.gameobject.match.MutableOrGameObjectMatcher; import net.sf.gridarta.gameobject.match.ViewGameObjectMatcherManager; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.DefaultScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; @@ -186,7 +186,7 @@ @NotNull @Override protected ScriptArchEditor<GameObject> newScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { - return new AbstractScriptArchEditor<GameObject>(scriptedEventFactory); + return new DefaultScriptArchEditor<GameObject>(scriptedEventFactory); } /** {@inheritDoc} */ Modified: trunk/src/app/net/sf/gridarta/AbstractMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-16 18:30:44 UTC (rev 5548) +++ trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-16 18:32:36 UTC (rev 5549) @@ -57,8 +57,8 @@ import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.gameobject.match.GameObjectMatchers; import net.sf.gridarta.gameobject.match.NamedGameObjectMatcher; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; import net.sf.gridarta.gameobject.scripts.AbstractScriptedEvent; +import net.sf.gridarta.gameobject.scripts.DefaultScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; @@ -448,7 +448,7 @@ } catch (final FileNotFoundException ex) { log.error("Cannot read " + CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage()); } - AbstractScriptArchEditor.initEventTypeBoxes(scriptArchUtils, scriptExtension, scriptName, scriptArchUtils.createEventTypeBox(), scriptFileFilter, globalSettings, mapManager); + DefaultScriptArchEditor.initEventTypeBoxes(scriptArchUtils, scriptExtension, scriptName, scriptArchUtils.createEventTypeBox(), scriptFileFilter, globalSettings, mapManager); final LockedItemsControl<G, A, R, V> lockedItemsControl = new LockedItemsControl<G, A, R, V>(mapManager, mapViewManager, lockedItemsTypeNumbers); final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel = new GameObjectAttributesModel<G, A, R>(); gameObjectAttributesControl = new GameObjectAttributesControl<G, A, R, V>(gameObjectAttributesModel, gameObjectAttributesDialogFactory, objectChooser, archetypeTypeSet, mapManager, mapViewManager, animationObjects, lockedItemsControl, monsterMatcher, selectedSquareControl, selectedSquareView, mainView); Deleted: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java 2008-10-16 18:30:44 UTC (rev 5548) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java 2008-10-16 18:32:36 UTC (rev 5549) @@ -1,345 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package net.sf.gridarta.gameobject.scripts; - -import java.awt.Color; -import java.awt.FlowLayout; -import java.awt.Frame; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.IOException; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JFileChooser; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.WindowConstants; -import javax.swing.filechooser.FileFilter; -import net.sf.gridarta.GlobalSettings; -import net.sf.gridarta.MapManager; -import net.sf.gridarta.gameobject.GameObject; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; -import net.sf.japi.swing.ActionFactory; -import org.jetbrains.annotations.NotNull; - -public class AbstractScriptArchEditor<G extends GameObject<G, ?, ?>> implements ScriptArchEditor<G> { - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.gridarta"); - - /** - * The {@link ScriptArchUtils} instance to use. - */ - @NotNull - protected static ScriptArchUtils scriptArchUtils; - - /** The ending for scripts. */ - protected static String scriptEnding; - - protected static JComboBox eventTypeBox; - - private static FileFilter scriptFileFilter; - - @NotNull - protected static GlobalSettings globalSettings; - - /** - * The map manager instance to use. - */ - @NotNull - protected static MapManager<?, ?, ?, ?> mapManager; - - protected static JComboBox pluginNameBox; - - // popup frame for new scripts: - private static JDialog newScriptFrame; - - private static JLabel headingLabel; - - protected static JTextField inputScriptPath; - - protected static JTextField inputOptions; - - private static PathButtonListener nsOkListener; - - /** - * The {@link ScriptedEventFactory} instance to use. - */ - @NotNull - private final ScriptedEventFactory<G> scriptedEventFactory; - - /** - * Creates a new instance. - * @param scriptedEventFactory the scripted event factory instance to use - */ - public AbstractScriptArchEditor(@NotNull final ScriptedEventFactory<G> scriptedEventFactory) { - this.scriptedEventFactory = scriptedEventFactory; - } - - /** - * Initialize the JComboBox with the event types. - * @param scriptArchUtils the script arch utils instance to use - * @param scriptEnding the suffix for script files - * @param name the default event type - * @param eventTypeBox the <code>JComboBox</code> containing all event - * types - * @param mapManager the map manager instance to use - */ - public static synchronized void initEventTypeBoxes(@NotNull final ScriptArchUtils scriptArchUtils, final String scriptEnding, final String name, final JComboBox eventTypeBox, @NotNull final FileFilter scriptFileFilter, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<?, ?, ?, ?> mapManager) { - AbstractScriptArchEditor.scriptArchUtils = scriptArchUtils; - AbstractScriptArchEditor.scriptEnding = scriptEnding; - - pluginNameBox = new JComboBox(new String[] {name}); - pluginNameBox.setSelectedIndex(0); - - AbstractScriptArchEditor.eventTypeBox = eventTypeBox; - AbstractScriptArchEditor.scriptFileFilter = scriptFileFilter; - AbstractScriptArchEditor.globalSettings = globalSettings; - AbstractScriptArchEditor.mapManager = mapManager; - } - - /** {@inheritDoc} */ - public void addEventScript(final G gameObject, final ScriptArchData<G> scriptArchData, @NotNull final Frame parent) { - final String archName = gameObject.getBestName(); - // create a reasonable default script name for lazy users :-) - final String defScriptName = ScriptUtils.chooseDefaultScriptName(mapManager.getLocalMapDir(), archName, scriptEnding); - - if (newScriptFrame == null) { - // initialize popup frame - newScriptFrame = new JDialog(parent, "New Scripted Event", true); - newScriptFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // first line: heading - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - headingLabel = new JLabel("New scripted event for \"" + archName + "\":"); - headingLabel.setForeground(Color.black); - line1.add(headingLabel); - mainPanel.add(line1); - - // event type - mainPanel.add(Box.createVerticalStrut(10)); - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel tlabel1 = new JLabel("Event type:"); - line2.add(tlabel1); - line2.add(eventTypeBox); - //mainPanel.add(line2); - line2.add(Box.createHorizontalStrut(10)); - - // plugin name - final JLabel tlabel2 = new JLabel("Plugin:"); - line2.add(tlabel2); - line2.add(pluginNameBox); - mainPanel.add(line2); - - // path - mainPanel.add(Box.createVerticalStrut(5)); - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel tlabel3 = new JLabel("Script file:"); - line3.add(tlabel3); - mainPanel.add(line3); - inputScriptPath = new JTextField(defScriptName, 20); - final JButton browseb = new JButton("..."); - browseb.setMargin(new Insets(0, 10, 0, 10)); - browseb.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - final File home = mapManager.getLocalMapDir(); - - final JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("Select Script File"); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileChooser.setCurrentDirectory(home); - fileChooser.setMultiSelectionEnabled(false); - fileChooser.setFileFilter(scriptFileFilter); - - if (fileChooser.showOpenDialog(newScriptFrame) == JFileChooser.APPROVE_OPTION) { - // user has selected a file - final File f = fileChooser.getSelectedFile(); - inputScriptPath.setText(ScriptUtils.localizeEventPath(mapManager.getLocalMapDir(), f, new File(globalSettings.getMapDefaultFolder()))); - } - } - }); - line3.add(inputScriptPath); - line3.add(browseb); - mainPanel.add(line3); - - // options - mainPanel.add(Box.createVerticalStrut(5)); - final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - line4.add(new JLabel("Script options:")); - inputOptions = new JTextField("", 20); - line4.add(inputOptions); - mainPanel.add(line4); - - // description - final JPanel line5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JPanel textPanel = new JPanel(); - textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS)); - final JLabel tlabel4 = new JLabel("When you specify an existing file, the new event will be linked"); - textPanel.add(tlabel4); - final JLabel tlabel5 = new JLabel("to that existing script. Otherwise a new script file is created."); - textPanel.add(tlabel5); - line5.add(textPanel); - mainPanel.add(line5); - - // button panel: - mainPanel.add(Box.createVerticalStrut(10)); - final JPanel line6 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JButton nsOkButton = new JButton("OK"); - nsOkListener = new PathButtonListener(true, newScriptFrame, scriptArchData, gameObject); - nsOkButton.addActionListener(nsOkListener); - line6.add(nsOkButton); - - final JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(new PathButtonListener(false, newScriptFrame, null, null)); - line6.add(cancelButton); - mainPanel.add(line6); - - newScriptFrame.getContentPane().add(mainPanel); - newScriptFrame.pack(); - newScriptFrame.setLocationRelativeTo(parent); - newScriptFrame.setVisible(true); - } else { - // just set fields and show - headingLabel.setText("New scripted event for \"" + archName + "\":"); - inputScriptPath.setText(defScriptName); - inputOptions.setText(""); - nsOkListener.setScriptArchData(scriptArchData, gameObject); - newScriptFrame.toFront(); - newScriptFrame.setVisible(true); - } - } - - /** {@inheritDoc} */ - public void createNewEvent(final JDialog frame, final ScriptArchData<G> scriptArchData, @NotNull final G gameObject) { - String scriptPath = inputScriptPath.getText().trim(); - final String options = inputOptions.getText().trim(); - final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); - final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); - - final File localMapDir = mapManager.getLocalMapDir(); - - // first check if that event type is not already in use - final G replaceObject = scriptArchData.getScriptedEvent(eventType, gameObject); - if (replaceObject != null) { - // collision with existing event -> ask user: replace? - if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + scriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { - // bail out - return; - } - } - - // convert localized scriptPath into real, absolute path - scriptPath = scriptPath.replace('\\', '/'); - String absScriptPath; - if (scriptPath.startsWith("/")) { - // script path is absolute - final File mapDir = new File(globalSettings.getMapDefaultFolder()); // global map directory - if (!mapDir.exists()) { - // if map dir doesn't exist, this is not going to work - frame.setVisible(false); - ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); - return; - } else { - absScriptPath = mapDir.getAbsolutePath() + scriptPath; - } - } else { - // script path is relative - absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; - } - - // now check if the specified path points to an existing script - File newScriptFile = new File(absScriptPath); - if (!newScriptFile.exists() && !absScriptPath.endsWith(scriptEnding)) { - absScriptPath += scriptEnding; - scriptPath += scriptEnding; - newScriptFile = new File(absScriptPath); - } - - if (newScriptFile.exists()) { - if (newScriptFile.isFile()) { - // file exists -> link it to the event - final ScriptedEvent<G> event; - try { - event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return; - } - if (replaceObject != null) { - replaceObject.remove(); - } - gameObject.addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - } - } else { - if (!absScriptPath.endsWith(scriptEnding)) { - absScriptPath += scriptEnding; - scriptPath += scriptEnding; - newScriptFile = new File(absScriptPath); - } - - // file does not exist -> aks user: create new file? - if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { - // okay, create new script file and open it - boolean couldCreateFile = false; // true when file creation successful - try { - // try to create new empty file - couldCreateFile = newScriptFile.createNewFile(); - } catch (final IOException e) { - /* ignore (really?) */ - } - - if (!couldCreateFile) { - JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); - } else { - // file has been created, now link it to the event - final ScriptedEvent<G> event; - try { - event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return; - } - if (replaceObject != null) { - replaceObject.remove(); - } - gameObject.addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - - // open new script file - ScriptEditControlInstance.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); - } - } - } - } - -} // class AbstractScriptArchEditor Copied: trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchEditor.java (from rev 5548, trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchEditor.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-16 18:32:36 UTC (rev 5549) @@ -0,0 +1,345 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gameobject.scripts; + +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import javax.swing.filechooser.FileFilter; +import net.sf.gridarta.GlobalSettings; +import net.sf.gridarta.MapManager; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; +import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; + +public class DefaultScriptArchEditor<G extends GameObject<G, ?, ?>> implements ScriptArchEditor<G> { + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.gridarta"); + + /** + * The {@link ScriptArchUtils} instance to use. + */ + @NotNull + protected static ScriptArchUtils scriptArchUtils; + + /** The ending for scripts. */ + protected static String scriptEnding; + + protected static JComboBox eventTypeBox; + + private static FileFilter scriptFileFilter; + + @NotNull + protected static GlobalSettings globalSettings; + + /** + * The map manager instance to use. + */ + @NotNull + protected static MapManager<?, ?, ?, ?> mapManager; + + protected static JComboBox pluginNameBox; + + // popup frame for new scripts: + private static JDialog newScriptFrame; + + private static JLabel headingLabel; + + protected static JTextField inputScriptPath; + + protected static JTextField inputOptions; + + private static PathButtonListener nsOkListener; + + /** + * The {@link ScriptedEventFactory} instance to use. + */ + @NotNull + private final ScriptedEventFactory<G> scriptedEventFactory; + + /** + * Creates a new instance. + * @param scriptedEventFactory the scripted event factory instance to use + */ + public DefaultScriptArchEditor(@NotNull final ScriptedEventFactory<G> scriptedEventFactory) { + this.scriptedEventFactory = scriptedEventFactory; + } + + /** + * Initialize the JComboBox with the event types. + * @param scriptArchUtils the script arch utils instance to use + * @param scriptEnding the suffix for script files + * @param name the default event type + * @param eventTypeBox the <code>JComboBox</code> containing all event + * types + * @param mapManager the map manager instance to use + */ + public static synchronized void initEventTypeBoxes(@NotNull final ScriptArchUtils scriptArchUtils, final String scriptEnding, final String name, final JComboBox eventTypeBox, @NotNull final FileFilter scriptFileFilter, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<?, ?, ?, ?> mapManager) { + DefaultScriptArchEditor.scriptArchUtils = scriptArchUtils; + DefaultScriptArchEditor.scriptEnding = scriptEnding; + + pluginNameBox = new JComboBox(new String[] {name}); + pluginNameBox.setSelectedIndex(0); + + DefaultScriptArchEditor.eventTypeBox = eventTypeBox; + DefaultScriptArchEditor.scriptFileFilter = scriptFileFilter; + DefaultScriptArchEditor.globalSettings = globalSettings; + DefaultScriptArchEditor.mapManager = mapManager; + } + + /** {@inheritDoc} */ + public void addEventScript(final G gameObject, final ScriptArchData<G> scriptArchData, @NotNull final Frame parent) { + final String archName = gameObject.getBestName(); + // create a reasonable default script name for lazy users :-) + final String defScriptName = ScriptUtils.chooseDefaultScriptName(mapManager.getLocalMapDir(), archName, scriptEnding); + + if (newScriptFrame == null) { + // initialize popup frame + newScriptFrame = new JDialog(parent, "New Scripted Event", true); + newScriptFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + + final JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); + + // first line: heading + final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + headingLabel = new JLabel("New scripted event for \"" + archName + "\":"); + headingLabel.setForeground(Color.black); + line1.add(headingLabel); + mainPanel.add(line1); + + // event type + mainPanel.add(Box.createVerticalStrut(10)); + final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JLabel tlabel1 = new JLabel("Event type:"); + line2.add(tlabel1); + line2.add(eventTypeBox); + //mainPanel.add(line2); + line2.add(Box.createHorizontalStrut(10)); + + // plugin name + final JLabel tlabel2 = new JLabel("Plugin:"); + line2.add(tlabel2); + line2.add(pluginNameBox); + mainPanel.add(line2); + + // path + mainPanel.add(Box.createVerticalStrut(5)); + final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JLabel tlabel3 = new JLabel("Script file:"); + line3.add(tlabel3); + mainPanel.add(line3); + inputScriptPath = new JTextField(defScriptName, 20); + final JButton browseb = new JButton("..."); + browseb.setMargin(new Insets(0, 10, 0, 10)); + browseb.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + final File home = mapManager.getLocalMapDir(); + + final JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("Select Script File"); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + fileChooser.setCurrentDirectory(home); + fileChooser.setMultiSelectionEnabled(false); + fileChooser.setFileFilter(scriptFileFilter); + + if (fileChooser.showOpenDialog(newScriptFrame) == JFileChooser.APPROVE_OPTION) { + // user has selected a file + final File f = fileChooser.getSelectedFile(); + inputScriptPath.setText(ScriptUtils.localizeEventPath(mapManager.getLocalMapDir(), f, new File(globalSettings.getMapDefaultFolder()))); + } + } + }); + line3.add(inputScriptPath); + line3.add(browseb); + mainPanel.add(line3); + + // options + mainPanel.add(Box.createVerticalStrut(5)); + final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + line4.add(new JLabel("Script options:")); + inputOptions = new JTextField("", 20); + line4.add(inputOptions); + mainPanel.add(line4); + + // description + final JPanel line5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JPanel textPanel = new JPanel(); + textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS)); + final JLabel tlabel4 = new JLabel("When you specify an existing file, the new event will be linked"); + textPanel.add(tlabel4); + final JLabel tlabel5 = new JLabel("to that existing script. Otherwise a new script file is created."); + textPanel.add(tlabel5); + line5.add(textPanel); + mainPanel.add(line5); + + // button panel: + mainPanel.add(Box.createVerticalStrut(10)); + final JPanel line6 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JButton nsOkButton = new JButton("OK"); + nsOkListener = new PathButtonListener(true, newScriptFrame, scriptArchData, gameObject); + nsOkButton.addActionListener(nsOkListener); + line6.add(nsOkButton); + + final JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(new PathButtonListener(false, newScriptFrame, null, null)); + line6.add(cancelButton); + mainPanel.add(line6); + + newScriptFrame.getContentPane().add(mainPanel); + newScriptFrame.pack(); + newScriptFrame.setLocationRelativeTo(parent); + newScriptFrame.setVisible(true); + } else { + // just set fields and show + headingLabel.setText("New scripted event for \"" + archName + "\":"); + inputScriptPath.setText(defScriptName); + inputOptions.setText(""); + nsOkListener.setScriptArchData(scriptArchData, gameObject); + newScriptFrame.toFront(); + newScriptFrame.setVisible(true); + } + } + + /** {@inheritDoc} */ + public void createNewEvent(final JDialog frame, final ScriptArchData<G> scriptArchData, @NotNull final G gameObject) { + String scriptPath = inputScriptPath.getText().trim(); + final String options = inputOptions.getText().trim(); + final int eventType = scriptArchUtils.indexToEventType(eventTypeBox.getSelectedIndex()); + final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); + + final File localMapDir = mapManager.getLocalMapDir(); + + // first check if that event type is not already in use + final G replaceObject = scriptArchData.getScriptedEvent(eventType, gameObject); + if (replaceObject != null) { + // collision with existing event -> ask user: replace? + if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + scriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { + // bail out + return; + } + } + + // convert localized scriptPath into real, absolute path + scriptPath = scriptPath.replace('\\', '/'); + String absScriptPath; + if (scriptPath.startsWith("/")) { + // script path is absolute + final File mapDir = new File(globalSettings.getMapDefaultFolder()); // global map directory + if (!mapDir.exists()) { + // if map dir doesn't exist, this is not going to work + frame.setVisible(false); + ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); + return; + } else { + absScriptPath = mapDir.getAbsolutePath() + scriptPath; + } + } else { + // script path is relative + absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; + } + + // now check if the specified path points to an existing script + File newScriptFile = new File(absScriptPath); + if (!newScriptFile.exists() && !absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; + newScriptFile = new File(absScriptPath); + } + + if (newScriptFile.exists()) { + if (newScriptFile.isFile()) { + // file exists -> link it to the event + final ScriptedEvent<G> event; + try { + event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); + } catch (final UndefinedEventArchetypeException ex) { + JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); + return; + } + if (replaceObject != null) { + replaceObject.remove(); + } + gameObject.addLast(event.getEventArch()); + frame.setVisible(false); // close dialog + } + } else { + if (!absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; + newScriptFile = new File(absScriptPath); + } + + // file does not exist -> aks user: create new file? + if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { + // okay, create new script file and open it + boolean couldCreateFile = false; // true when file creation successful + try { + // try to create new empty file + couldCreateFile = newScriptFile.createNewFile(); + } catch (final IOException e) { + /* ignore (really?) */ + } + + if (!couldCreateFile) { + JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); + } else { + // file has been created, now link it to the event + final ScriptedEvent<G> event; + try { + event = scriptedEventFactory.newScriptedEvent(eventType, pluginName, scriptPath, options); + } catch (final UndefinedEventArchetypeException ex) { + JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); + return; + } + if (replaceObject != null) { + replaceObject.remove(); + } + gameObject.addLast(event.getEventArch()); + frame.setVisible(false); // close dialog + + // open new script file + ScriptEditControlInstance.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); + } + } + } + } + +} // class DefaultScriptArchEditor Property changes on: trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchEditor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-16 18:36:08
|
Revision: 5550 http://gridarta.svn.sourceforge.net/gridarta/?rev=5550&view=rev Author: akirschbaum Date: 2008-10-16 18:35:49 +0000 (Thu, 16 Oct 2008) Log Message: ----------- Move text resources to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_de.properties trunk/crossfire/src/cfeditor/messages_fr.properties trunk/crossfire/src/cfeditor/messages_sv.properties trunk/daimonin/src/daieditor/messages.properties trunk/daimonin/src/daieditor/messages_de.properties trunk/daimonin/src/daieditor/messages_fr.properties trunk/daimonin/src/daieditor/messages_sv.properties trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/crossfire/src/cfeditor/messages.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -30,9 +30,6 @@ ########## # Dialogs -mapDirDoesntExist.title=Invalid map directory -mapDirDoesntExist.message=The map directory "{0}" doesn''t exist.\nPlease select menu ''File->Options...'' and correct that. - loadDuplicateFace.title=Error: Duplicate face loadDuplicateFace.message=Warning!\n\nDuplicate face: ''{0}''\nFiles: ''{1}''\nand ''{2}''\nI will ignore this duplicate. Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -26,9 +26,6 @@ ########## # Dialogs -mapDirDoesntExist.title=Ung\xFCltiges Verzeichnis -mapDirDoesntExist.message=Das Verzeichnis f\xFCr Karten "{0}" existiert nicht.\nBitte legen sie es unter ''Datei->Optionen...'' fest. - loadDuplicateFace.title=Fehler: doppelte Grafik loadDuplicateFace.message=Warning!\n\nDopplete Grafik: ''{0}''\nDateien: ''{1}''\nund ''{2}''\nDie doppelte Grafik wird ignoriert. Modified: trunk/crossfire/src/cfeditor/messages_fr.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_fr.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/crossfire/src/cfeditor/messages_fr.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -27,9 +27,6 @@ ########## # Dialogs -#mapDirDoesntExist.title= -#mapDirDoesntExist.message= - #loadDuplicateFace.title= #loadDuplicateFace.message= Modified: trunk/crossfire/src/cfeditor/messages_sv.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_sv.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/crossfire/src/cfeditor/messages_sv.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -26,9 +26,6 @@ ########## # Dialogs -mapDirDoesntExist.title=Ogiltig katalog f\xF6r kartor. -mapDirDoesntExist.message=Katalogen f\xF6r kartor, "{0}", finns inte.\nVar v\xE4nlig och v\xE4lj menyn ''Arkiv->Inst\xE4llningar...'' f\xF6r att byta katalog. - loadDuplicateFace.title=Fel: duplicerad bild loadDuplicateFace.message=Varning!\n\nDuplicerad bild: ''{0}''\nFiler: ''{1}''\noch ''{2}''\nJag kommer att ignorera detta duplikat. Modified: trunk/daimonin/src/daieditor/messages.properties =================================================================== --- trunk/daimonin/src/daieditor/messages.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/daimonin/src/daieditor/messages.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -31,9 +31,6 @@ mapUnsaved.title=Map Not Saved mapUnsaved.message=Please save this map first. -mapDirDoesntExist.title=Invalid map directory -mapDirDoesntExist.message=The map directory "{0}" doesn''t exist.\nPlease select menu ''File->Options...'' and correct that. - loadDuplicateFace.title=Error: Duplicate face loadDuplicateFace.message=Warning!\n\nDuplicate face: ''{0}''\nFiles: ''{1}''\nand ''{2}''\nI will ignore this duplicate. Modified: trunk/daimonin/src/daieditor/messages_de.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_de.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/daimonin/src/daieditor/messages_de.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -31,9 +31,6 @@ #mapUnsaved.title= #mapUnsaved.message= -mapDirDoesntExist.title=Ung\xFCltiges Verzeichnis -mapDirDoesntExist.message=Das Verzeichnis f\xFCr Karten "{0}" existiert nicht.\nBitte legen sie es unter ''Datei->Optionen...'' fest. - loadDuplicateFace.title=Fehler: doppelte Grafik loadDuplicateFace.message=Warning!\n\nDopplete Grafik: ''{0}''\nDateien: ''{1}''\nund ''{2}''\nDie doppelte Grafik wird ignoriert. Modified: trunk/daimonin/src/daieditor/messages_fr.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_fr.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/daimonin/src/daieditor/messages_fr.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -32,9 +32,6 @@ #mapUnsaved.title= #mapUnsaved.message= -#mapDirDoesntExist.title= -#mapDirDoesntExist.message= - #loadDuplicateFace.title= #loadDuplicateFace.message= Modified: trunk/daimonin/src/daieditor/messages_sv.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_sv.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/daimonin/src/daieditor/messages_sv.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -31,9 +31,6 @@ mapUnsaved.title=Kartan har inte sparats. mapUnsaved.message=Var v\xE4nlig och spara den h\xE4r kartan f\xF6rst. -mapDirDoesntExist.title=Ogiltig katalog f\xF6r kartor. -mapDirDoesntExist.message=Katalogen f\xF6r kartor, "{0}", finns inte.\nVar v\xE4nlig och v\xE4lj menyn ''Arkiv->Inst\xE4llningar...'' f\xF6r att byta katalog. - loadDuplicateFace.title=Fel: duplicerad bild loadDuplicateFace.message=Varning!\n\nDuplicerad bild: ''{0}''\nFiler: ''{1}''\noch ''{2}''\nJag kommer att ignorera detta duplikat. Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/src/app/net/sf/gridarta/messages.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -246,6 +246,9 @@ # Dialogs +mapDirDoesntExist.title=Invalid map directory +mapDirDoesntExist.message=The map directory "{0}" doesn''t exist.\nPlease select menu ''File->Options...'' and correct that. + mapOutOfMemory.title=Out of memory mapOutOfMemory.message=<html>Not enough memory available to open the map {0}!<br>You can increase the memory limit by using the <code>-Xmx</code> runtime flag.<br>For example: <code>java -Xmx128m -jar CrossfireEditor.jar</code></html> Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -229,6 +229,9 @@ # Dialogs +mapDirDoesntExist.title=Ung\xFCltiges Verzeichnis +mapDirDoesntExist.message=Das Verzeichnis f\xFCr Karten "{0}" existiert nicht.\nBitte legen sie es unter ''Datei->Optionen...'' fest. + mapOutOfMemory.title=Kann Karte nicht \xF6ffnen mapOutOfMemory.message=Es ist nicht gen\xFCgend freier Speicher vorhanden, um die\nKarte {0} zu laden. Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -228,6 +228,9 @@ # Dialogs +#mapDirDoesntExist.title= +#mapDirDoesntExist.message= + #mapOutOfMemory.title= #mapOutOfMemory.message= Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-10-16 18:32:36 UTC (rev 5549) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-10-16 18:35:49 UTC (rev 5550) @@ -232,6 +232,9 @@ ########## # Dialogs +mapDirDoesntExist.title=Ogiltig katalog f\xF6r kartor. +mapDirDoesntExist.message=Katalogen f\xF6r kartor, "{0}", finns inte.\nVar v\xE4nlig och v\xE4lj menyn ''Arkiv->Inst\xE4llningar...'' f\xF6r att byta katalog. + mapOutOfMemory.title=Slut p\xE5 minne mapOutOfMemory.message=<html>Det finns inte tillr\xE4ckligt med minne f\xF6r att \xF6ppna kartan {0}!<br>Du kan h\xF6ja minnesgr\xE4nsen med <code>-Xmx</code> -flaggan.<br>Till exempel: <code>java -Xmx128m -jar DaimoninEditor.jar</code></html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 07:10:20
|
Revision: 5554 http://gridarta.svn.sourceforge.net/gridarta/?rev=5554&view=rev Author: akirschbaum Date: 2008-10-19 07:10:16 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Remove parameter from ScriptArchEditor.initEventTypeBoxes(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/src/app/net/sf/gridarta/AbstractMainControl.java trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchEditor.java trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptArchEditor.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-19 06:53:35 UTC (rev 5553) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-19 07:10:16 UTC (rev 5554) @@ -44,6 +44,8 @@ import java.util.List; import java.util.Map; import java.util.regex.Pattern; +import javax.swing.JComboBox; +import javax.swing.filechooser.FileFilter; import net.sf.gridarta.AbstractMainControl; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.EditTypes; @@ -140,8 +142,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptArchEditor<GameObject> newScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { - return new DefaultScriptArchEditor<GameObject>(scriptedEventFactory); + protected ScriptArchEditor<GameObject> newScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, final String scriptExtension, final String scriptName, final JComboBox eventTypeBox, @NotNull final FileFilter scriptFileFilter, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<?, ?, ?, ?> mapManager) { + return new DefaultScriptArchEditor<GameObject>(scriptedEventFactory, scriptExtension, scriptName, eventTypeBox, scriptFileFilter, globalSettings, mapManager); } /** {@inheritDoc} */ Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 06:53:35 UTC (rev 5553) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 07:10:16 UTC (rev 5554) @@ -48,7 +48,9 @@ import java.util.List; import java.util.Map; import java.util.regex.Pattern; +import javax.swing.JComboBox; import javax.swing.JOptionPane; +import javax.swing.filechooser.FileFilter; import net.sf.gridarta.AbstractMainControl; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.EditTypes; @@ -185,8 +187,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected ScriptArchEditor<GameObject> newScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory) { - return new DefaultScriptArchEditor<GameObject>(scriptedEventFactory); + protected ScriptArchEditor<GameObject> newScriptArchEditor(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, final String scriptExtension, final String scriptName, final JComboBox eventTypeBox, @NotNull final FileFilter scriptFileFilter, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<?, ?, ?, ?> mapManager) { + return new DefaultScriptArchEditor<GameObject>(scriptedEventFactory, scriptExtension, scriptName, eventTypeBox, scriptFileFilter, globalSettings, mapManager); } /** {@inheritDoc} */ Modified: trunk/src/app/net/sf/gridarta/AbstractMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-19 06:53:35 UTC (rev 5553) +++ trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-19 07:10:16 UTC (rev 5554) @@ -32,6 +32,7 @@ import java.util.ResourceBundle; import java.util.prefs.Preferences; import javax.swing.ImageIcon; +import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JMenu; import javax.swing.JOptionPane; @@ -58,7 +59,6 @@ import net.sf.gridarta.gameobject.match.GameObjectMatchers; import net.sf.gridarta.gameobject.match.NamedGameObjectMatcher; import net.sf.gridarta.gameobject.scripts.AbstractScriptedEvent; -import net.sf.gridarta.gameobject.scripts.DefaultScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; @@ -473,8 +473,8 @@ mapControlFactory.init(mapViewFactory, gameObjectParser, rendererFactory, mapActions, archetypeChooserModel, mapImageCache, autojoinLists, exitMatcher); copyBuffer.init(mapArchObjectFactory.newMapArchObject(false), mainView); final ScriptedEventFactory<G> scriptedEventFactory = newScriptedEventFactory(scriptArchUtils); - final ScriptArchEditor<G> scriptArchEditor = newScriptArchEditor(scriptedEventFactory); - scriptArchEditor.initEventTypeBoxes(scriptArchUtils, scriptExtension, scriptName, scriptArchUtils.createEventTypeBox(), scriptFileFilter, globalSettings, mapManager); + final ScriptArchEditor<G> scriptArchEditor = newScriptArchEditor(scriptedEventFactory, scriptExtension, scriptName, scriptArchUtils.createEventTypeBox(), scriptFileFilter, globalSettings, mapManager); + scriptArchEditor.initEventTypeBoxes(scriptArchUtils); GameObject.initialize(archetypeSet, archetypeTypeSet, gameObjectMatchers, scriptArchEditor, animationObjects, SystemIcons.getNofaceTileIcon(), newScriptArchData(scriptedEventFactory, scriptArchUtils, scriptArchEditor)); init4(gameObjectParser, archetypeParser, editTypes, faceObjects, animationObjects, mainView, globalSettings, archetypeSet); @@ -515,7 +515,7 @@ protected abstract ScriptedEventFactory<G> newScriptedEventFactory(@NotNull final ScriptArchUtils scriptArchUtils); @NotNull - protected abstract ScriptArchEditor<G> newScriptArchEditor(@NotNull final ScriptedEventFactory<G> scriptedEventFactory); + protected abstract ScriptArchEditor<G> newScriptArchEditor(@NotNull final ScriptedEventFactory<G> scriptedEventFactory, final String scriptExtension, final String scriptName, final JComboBox eventTypeBox, @NotNull final FileFilter scriptFileFilter, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<?, ?, ?, ?> mapManager); @NotNull protected abstract ScriptArchUtils newScriptArchUtils(); Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-19 06:53:35 UTC (rev 5553) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchEditor.java 2008-10-19 07:10:16 UTC (rev 5554) @@ -96,14 +96,14 @@ /** * Creates a new instance. * @param scriptedEventFactory the scripted event factory instance to use + * @param scriptEnding the suffix for script files + * @param name the default event type + * @param eventTypeBox the <code>JComboBox</code> containing all event + * types + * @param mapManager the map manager instance to use */ - public DefaultScriptArchEditor(@NotNull final ScriptedEventFactory<G> scriptedEventFactory) { + public DefaultScriptArchEditor(@NotNull final ScriptedEventFactory<G> scriptedEventFactory, final String scriptEnding, final String name, final JComboBox eventTypeBox, @NotNull final FileFilter scriptFileFilter, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<?, ?, ?, ?> mapManager) { this.scriptedEventFactory = scriptedEventFactory; - } - - /** {@inheritDoc} */ - public void initEventTypeBoxes(@NotNull final ScriptArchUtils scriptArchUtils, final String scriptEnding, final String name, final JComboBox eventTypeBox, @NotNull final FileFilter scriptFileFilter, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<?, ?, ?, ?> mapManager) { - this.scriptArchUtils = scriptArchUtils; this.scriptEnding = scriptEnding; pluginNameBox = new JComboBox(new String[] {name}); @@ -116,6 +116,11 @@ } /** {@inheritDoc} */ + public void initEventTypeBoxes(@NotNull final ScriptArchUtils scriptArchUtils) { + this.scriptArchUtils = scriptArchUtils; + } + + /** {@inheritDoc} */ public void addEventScript(final G gameObject, final ScriptArchData<G> scriptArchData, @NotNull final Frame parent) { final String archName = gameObject.getBestName(); // create a reasonable default script name for lazy users :-) Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptArchEditor.java 2008-10-19 06:53:35 UTC (rev 5553) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptArchEditor.java 2008-10-19 07:10:16 UTC (rev 5554) @@ -20,11 +20,7 @@ package net.sf.gridarta.gameobject.scripts; import java.awt.Frame; -import javax.swing.JComboBox; import javax.swing.JDialog; -import javax.swing.filechooser.FileFilter; -import net.sf.gridarta.GlobalSettings; -import net.sf.gridarta.MapManager; import net.sf.gridarta.gameobject.GameObject; import org.jetbrains.annotations.NotNull; @@ -33,13 +29,8 @@ /** * Initialize the JComboBox with the event types. * @param scriptArchUtils the script arch utils instance to use - * @param scriptEnding the suffix for script files - * @param name the default event type - * @param eventTypeBox the <code>JComboBox</code> containing all event - * types - * @param mapManager the map manager instance to use */ - void initEventTypeBoxes(@NotNull ScriptArchUtils scriptArchUtils, final String scriptEnding, final String name, final JComboBox eventTypeBox, @NotNull FileFilter scriptFileFilter, @NotNull GlobalSettings globalSettings, @NotNull MapManager<?, ?, ?, ?> mapManager); + void initEventTypeBoxes(@NotNull ScriptArchUtils scriptArchUtils); void createNewEvent(JDialog frame, ScriptArchData<G> scriptArchData, @NotNull G gameObject); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 07:22:27
|
Revision: 5555 http://gridarta.svn.sourceforge.net/gridarta/?rev=5555&view=rev Author: akirschbaum Date: 2008-10-19 07:22:24 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Move DefaultScriptArchData.newScriptedEvent() to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:10:16 UTC (rev 5554) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:22:24 UTC (rev 5555) @@ -24,7 +24,6 @@ import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; -import net.sf.gridarta.gameobject.scripts.ScriptedEvent; import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; import org.jetbrains.annotations.NotNull; @@ -41,12 +40,6 @@ private static final long serialVersionUID = 1L; /** - * The {@link ScriptedEventFactory} instance to use. - */ - @NotNull - private final ScriptedEventFactory<GameObject> scriptedEventFactory; - - /** * The {@link ScriptArchEditor} instance to use. */ @NotNull @@ -61,19 +54,11 @@ * @param eventTypeNo the object type for event objects */ public DefaultScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { - super(subtypeAttribute, eventTypeNo, scriptArchUtils); - this.scriptedEventFactory = scriptedEventFactory; + super(subtypeAttribute, eventTypeNo, scriptArchUtils, scriptedEventFactory); this.scriptArchEditor = scriptArchEditor; } /** {@inheritDoc} */ - @NotNull - @Override - protected ScriptedEvent<GameObject> newScriptedEvent(@NotNull final GameObject event) { - return scriptedEventFactory.newScriptedEvent(event); - } - - /** {@inheritDoc} */ public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { scriptArchEditor.createNewEvent(frame, this, gameObject); } Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:10:16 UTC (rev 5554) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:22:24 UTC (rev 5555) @@ -24,7 +24,6 @@ import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; -import net.sf.gridarta.gameobject.scripts.ScriptedEvent; import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; import org.jetbrains.annotations.NotNull; @@ -41,12 +40,6 @@ private static final long serialVersionUID = 1L; /** - * The {@link ScriptedEventFactory} instance to use. - */ - @NotNull - private final ScriptedEventFactory<GameObject> scriptedEventFactory; - - /** * The {@link ScriptArchEditor} instance to use. */ @NotNull @@ -61,19 +54,11 @@ * @param eventTypeNo the object type for event objects */ public DefaultScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { - super(subtypeAttribute, eventTypeNo, scriptArchUtils); - this.scriptedEventFactory = scriptedEventFactory; + super(subtypeAttribute, eventTypeNo, scriptArchUtils, scriptedEventFactory); this.scriptArchEditor = scriptArchEditor; } /** {@inheritDoc} */ - @NotNull - @Override - protected ScriptedEvent<GameObject> newScriptedEvent(@NotNull final GameObject event) { - return scriptedEventFactory.newScriptedEvent(event); - } - - /** {@inheritDoc} */ public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { scriptArchEditor.createNewEvent(frame, this, gameObject); } Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-19 07:10:16 UTC (rev 5554) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-19 07:22:24 UTC (rev 5555) @@ -65,15 +65,23 @@ private final ScriptArchUtils scriptArchUtils; /** + * The {@link ScriptedEventFactory} instance to use. + */ + @NotNull + private final ScriptedEventFactory<G> scriptedEventFactory; + + /** * Create a ScriptArchData. * @param subtypeAttribute the attribute name for the subtype field * @param eventTypeNo the object type for event objects * @param scriptArchUtils the script arch utils instance to use + * @param scriptedEventFactory the scripted event factory instance to use */ - protected AbstractScriptArchData(@NotNull final String subtypeAttribute, final int eventTypeNo, @NotNull final ScriptArchUtils scriptArchUtils) { + protected AbstractScriptArchData(@NotNull final String subtypeAttribute, final int eventTypeNo, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptedEventFactory<G> scriptedEventFactory) { this.subtypeAttribute = subtypeAttribute; this.eventTypeNo = eventTypeNo; this.scriptArchUtils = scriptArchUtils; + this.scriptedEventFactory = scriptedEventFactory; } /** {@inheritDoc} */ @@ -108,7 +116,7 @@ while (it.hasNext()) { final G tmp = it.next(); if (tmp.getTypeNo() == eventTypeNo) { - final ScriptedEvent<G> se = newScriptedEvent(tmp); + final ScriptedEvent<G> se = scriptedEventFactory.newScriptedEvent(tmp); // validate this event if (!se.isValid()) { // this event is invalid @@ -149,7 +157,7 @@ } if (oldEvent != null) { - final ScriptedEvent<G> event = newScriptedEvent(oldEvent); + final ScriptedEvent<G> event = scriptedEventFactory.newScriptedEvent(oldEvent); // now decide what to do: if (task == ScriptTab.SCRIPT_OPEN) { ScriptedEventEditor.openScript(mapManager, event.getScriptPath(), parent); @@ -168,7 +176,4 @@ } } - @NotNull - protected abstract ScriptedEvent<G> newScriptedEvent(@NotNull final G event); - } // class AbstractScriptArchData This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 07:35:23
|
Revision: 5556 http://gridarta.svn.sourceforge.net/gridarta/?rev=5556&view=rev Author: akirschbaum Date: 2008-10-19 07:35:19 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Move ScriptedEventFactory.createNewEvent() to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:22:24 UTC (rev 5555) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:35:19 UTC (rev 5556) @@ -20,7 +20,6 @@ package cfeditor.gameobject.scripts; import cfeditor.gameobject.GameObject; -import javax.swing.JDialog; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; @@ -40,12 +39,6 @@ private static final long serialVersionUID = 1L; /** - * The {@link ScriptArchEditor} instance to use. - */ - @NotNull - private final ScriptArchEditor<GameObject> scriptArchEditor; - - /** * Create a ScriptArchData. * @param scriptedEventFactory the scripted event factory instance to use * @param scriptArchUtils the script arch utils instance to use @@ -54,13 +47,7 @@ * @param eventTypeNo the object type for event objects */ public DefaultScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { - super(subtypeAttribute, eventTypeNo, scriptArchUtils, scriptedEventFactory); - this.scriptArchEditor = scriptArchEditor; + super(subtypeAttribute, eventTypeNo, scriptArchUtils, scriptedEventFactory, scriptArchEditor); } - /** {@inheritDoc} */ - public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { - scriptArchEditor.createNewEvent(frame, this, gameObject); - } - } // class DefaultScriptArchData Modified: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:22:24 UTC (rev 5555) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:35:19 UTC (rev 5556) @@ -20,7 +20,6 @@ package daieditor.gameobject.scripts; import daieditor.gameobject.GameObject; -import javax.swing.JDialog; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; @@ -40,12 +39,6 @@ private static final long serialVersionUID = 1L; /** - * The {@link ScriptArchEditor} instance to use. - */ - @NotNull - private final ScriptArchEditor<GameObject> scriptArchEditor; - - /** * Create a ScriptArchData. * @param scriptedEventFactory the scripted event factory instance to use * @param scriptArchUtils the script arch utils instance to use @@ -54,13 +47,7 @@ * @param eventTypeNo the object type for event objects */ public DefaultScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { - super(subtypeAttribute, eventTypeNo, scriptArchUtils, scriptedEventFactory); - this.scriptArchEditor = scriptArchEditor; + super(subtypeAttribute, eventTypeNo, scriptArchUtils, scriptedEventFactory, scriptArchEditor); } - /** {@inheritDoc} */ - public void createNewEvent(final JDialog frame, @NotNull final GameObject gameObject) { - scriptArchEditor.createNewEvent(frame, this, gameObject); - } - } // class DefaultScriptArchData Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-19 07:22:24 UTC (rev 5555) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-19 07:35:19 UTC (rev 5556) @@ -25,6 +25,7 @@ import java.util.Vector; import javax.swing.JList; import javax.swing.JOptionPane; +import javax.swing.JDialog; import net.sf.gridarta.MapManager; import net.sf.gridarta.gameobject.GameObject; import net.sf.gridarta.gui.gameobjectattributespanel.ScriptTab; @@ -71,20 +72,33 @@ private final ScriptedEventFactory<G> scriptedEventFactory; /** + * The {@link ScriptArchEditor} instance to use. + */ + @NotNull + private final ScriptArchEditor<G> scriptArchEditor; + + /** * Create a ScriptArchData. * @param subtypeAttribute the attribute name for the subtype field * @param eventTypeNo the object type for event objects * @param scriptArchUtils the script arch utils instance to use * @param scriptedEventFactory the scripted event factory instance to use + * @param scriptArchEditor the script arch editor instance to use */ - protected AbstractScriptArchData(@NotNull final String subtypeAttribute, final int eventTypeNo, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptedEventFactory<G> scriptedEventFactory) { + protected AbstractScriptArchData(@NotNull final String subtypeAttribute, final int eventTypeNo, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptedEventFactory<G> scriptedEventFactory, @NotNull final ScriptArchEditor<G> scriptArchEditor) { this.subtypeAttribute = subtypeAttribute; this.eventTypeNo = eventTypeNo; this.scriptArchUtils = scriptArchUtils; this.scriptedEventFactory = scriptedEventFactory; + this.scriptArchEditor = scriptArchEditor; } /** {@inheritDoc} */ + public void createNewEvent(final JDialog frame, @NotNull final G gameObject) { + scriptArchEditor.createNewEvent(frame, this, gameObject); + } + + /** {@inheritDoc} */ public void addEventsToJList(final JList list, @NotNull final G gameObject) { //cher: JList expects Vector, so we MUST use an obsolete concrete collection. //noinspection CollectionDeclaredAsConcreteClass,UseOfObsoleteCollectionType This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 07:43:28
|
Revision: 5557 http://gridarta.svn.sourceforge.net/gridarta/?rev=5557&view=rev Author: akirschbaum Date: 2008-10-19 07:43:19 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Remove empty class DefaultScriptArchData. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-19 07:35:19 UTC (rev 5556) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-19 07:43:19 UTC (rev 5557) @@ -27,7 +27,6 @@ import cfeditor.gameobject.DefaultGameObjectFactory; import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObjects; -import cfeditor.gameobject.scripts.DefaultScriptArchData; import cfeditor.gameobject.scripts.DefaultScriptArchUtils; import cfeditor.gameobject.scripts.DefaultScriptedEventFactory; import cfeditor.gui.map.CMapViewBasic; @@ -62,7 +61,9 @@ import net.sf.gridarta.gameobject.face.FaceObjectProviders; import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.gameobject.match.GameObjectMatcher; +import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; import net.sf.gridarta.gameobject.scripts.DefaultScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.ScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; @@ -156,8 +157,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected DefaultScriptArchData newScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { - return new DefaultScriptArchData(scriptedEventFactory, scriptArchUtils, scriptArchEditor, "subtype", Archetype.TYPE_EVENT_CONNECTOR); + protected ScriptArchData<GameObject> newScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { + return new AbstractScriptArchData<GameObject>("subtype", Archetype.TYPE_EVENT_CONNECTOR, scriptArchUtils, scriptedEventFactory, scriptArchEditor); } /** {@inheritDoc} */ Deleted: trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:35:19 UTC (rev 5556) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:43:19 UTC (rev 5557) @@ -1,53 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package cfeditor.gameobject.scripts; - -import cfeditor.gameobject.GameObject; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; -import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; -import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; -import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; -import org.jetbrains.annotations.NotNull; - -/** - * Stores and manages information about scripted events. This data is only - * needed for those arches with one or more events defined. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @xxx This class is designed very badly, as it combines model and - * presentation. - */ -public final class DefaultScriptArchData extends AbstractScriptArchData<GameObject> { - - /** Serial Version. */ - private static final long serialVersionUID = 1L; - - /** - * Create a ScriptArchData. - * @param scriptedEventFactory the scripted event factory instance to use - * @param scriptArchUtils the script arch utils instance to use - * @param scriptArchEditor the script arch editor instance to use - * @param subtypeAttribute the attribute name for the subtype field - * @param eventTypeNo the object type for event objects - */ - public DefaultScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { - super(subtypeAttribute, eventTypeNo, scriptArchUtils, scriptedEventFactory, scriptArchEditor); - } - -} // class DefaultScriptArchData Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 07:35:19 UTC (rev 5556) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 07:43:19 UTC (rev 5557) @@ -27,7 +27,6 @@ import daieditor.gameobject.DefaultGameObjectFactory; import daieditor.gameobject.GameObject; import daieditor.gameobject.anim.AnimationObjects; -import daieditor.gameobject.scripts.DefaultScriptArchData; import daieditor.gameobject.scripts.DefaultScriptArchUtils; import daieditor.gameobject.scripts.DefaultScriptedEventFactory; import daieditor.gui.map.CMapViewBasic; @@ -69,7 +68,9 @@ import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.gameobject.match.MutableOrGameObjectMatcher; import net.sf.gridarta.gameobject.match.ViewGameObjectMatcherManager; +import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; import net.sf.gridarta.gameobject.scripts.DefaultScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.ScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; @@ -201,8 +202,8 @@ /** {@inheritDoc} */ @NotNull @Override - protected DefaultScriptArchData newScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { - return new DefaultScriptArchData(scriptedEventFactory, scriptArchUtils, scriptArchEditor, "sub_type", Archetype.TYPE_EVENT_OBJECT); + protected ScriptArchData<GameObject> newScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { + return new AbstractScriptArchData<GameObject>("sub_type", Archetype.TYPE_EVENT_OBJECT, scriptArchUtils, scriptedEventFactory, scriptArchEditor); } /** {@inheritDoc} */ Deleted: trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:35:19 UTC (rev 5556) +++ trunk/daimonin/src/daieditor/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:43:19 UTC (rev 5557) @@ -1,53 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor.gameobject.scripts; - -import daieditor.gameobject.GameObject; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; -import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; -import net.sf.gridarta.gameobject.scripts.ScriptArchUtils; -import net.sf.gridarta.gameobject.scripts.ScriptedEventFactory; -import org.jetbrains.annotations.NotNull; - -/** - * Stores and manages information about scripted events. This data is only - * needed for those arches with one or more events defined. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @xxx This class is designed very badly, as it combines model and - * presentation. - */ -public final class DefaultScriptArchData extends AbstractScriptArchData<GameObject> { - - /** Serial Version. */ - private static final long serialVersionUID = 1L; - - /** - * Create a ScriptArchData. - * @param scriptedEventFactory the scripted event factory instance to use - * @param scriptArchUtils the script arch utils instance to use - * @param scriptArchEditor the script arch editor instance to use - * @param subtypeAttribute the attribute name for the subtype field - * @param eventTypeNo the object type for event objects - */ - public DefaultScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor, @NotNull final String subtypeAttribute, final int eventTypeNo) { - super(subtypeAttribute, eventTypeNo, scriptArchUtils, scriptedEventFactory, scriptArchEditor); - } - -} // class DefaultScriptArchData Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-19 07:35:19 UTC (rev 5556) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-19 07:43:19 UTC (rev 5557) @@ -40,7 +40,7 @@ * @xxx This class is designed very badly, as it combines model and * presentation. */ -public abstract class AbstractScriptArchData<G extends GameObject<G, ?, ?>> implements ScriptArchData<G>, Serializable { +public class AbstractScriptArchData<G extends GameObject<G, ?, ?>> implements ScriptArchData<G>, Serializable { /** The serial version UID. */ private static final long serialVersionUID = 1; @@ -85,7 +85,7 @@ * @param scriptedEventFactory the scripted event factory instance to use * @param scriptArchEditor the script arch editor instance to use */ - protected AbstractScriptArchData(@NotNull final String subtypeAttribute, final int eventTypeNo, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptedEventFactory<G> scriptedEventFactory, @NotNull final ScriptArchEditor<G> scriptArchEditor) { + public AbstractScriptArchData(@NotNull final String subtypeAttribute, final int eventTypeNo, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptedEventFactory<G> scriptedEventFactory, @NotNull final ScriptArchEditor<G> scriptArchEditor) { this.subtypeAttribute = subtypeAttribute; this.eventTypeNo = eventTypeNo; this.scriptArchUtils = scriptArchUtils; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 07:46:51
|
Revision: 5559 http://gridarta.svn.sourceforge.net/gridarta/?rev=5559&view=rev Author: akirschbaum Date: 2008-10-19 07:46:46 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Rename AbstractScriptArchData to DefaultScriptArchData since it is not anymore abstract. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CMainControl.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchData.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-19 07:45:20 UTC (rev 5558) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-19 07:46:46 UTC (rev 5559) @@ -61,7 +61,7 @@ import net.sf.gridarta.gameobject.face.FaceObjectProviders; import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.gameobject.match.GameObjectMatcher; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; +import net.sf.gridarta.gameobject.scripts.DefaultScriptArchData; import net.sf.gridarta.gameobject.scripts.DefaultScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; @@ -158,7 +158,7 @@ @NotNull @Override protected ScriptArchData<GameObject> newScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { - return new AbstractScriptArchData<GameObject>("subtype", Archetype.TYPE_EVENT_CONNECTOR, scriptArchUtils, scriptedEventFactory, scriptArchEditor); + return new DefaultScriptArchData<GameObject>("subtype", Archetype.TYPE_EVENT_CONNECTOR, scriptArchUtils, scriptedEventFactory, scriptArchEditor); } /** {@inheritDoc} */ Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 07:45:20 UTC (rev 5558) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 07:46:46 UTC (rev 5559) @@ -68,7 +68,7 @@ import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.gameobject.match.MutableOrGameObjectMatcher; import net.sf.gridarta.gameobject.match.ViewGameObjectMatcherManager; -import net.sf.gridarta.gameobject.scripts.AbstractScriptArchData; +import net.sf.gridarta.gameobject.scripts.DefaultScriptArchData; import net.sf.gridarta.gameobject.scripts.DefaultScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchData; import net.sf.gridarta.gameobject.scripts.ScriptArchEditor; @@ -203,7 +203,7 @@ @NotNull @Override protected ScriptArchData<GameObject> newScriptArchData(@NotNull final ScriptedEventFactory<GameObject> scriptedEventFactory, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptArchEditor<GameObject> scriptArchEditor) { - return new AbstractScriptArchData<GameObject>("sub_type", Archetype.TYPE_EVENT_OBJECT, scriptArchUtils, scriptedEventFactory, scriptArchEditor); + return new DefaultScriptArchData<GameObject>("sub_type", Archetype.TYPE_EVENT_OBJECT, scriptArchUtils, scriptedEventFactory, scriptArchEditor); } /** {@inheritDoc} */ Deleted: trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-19 07:45:20 UTC (rev 5558) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java 2008-10-19 07:46:46 UTC (rev 5559) @@ -1,193 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package net.sf.gridarta.gameobject.scripts; - -import java.awt.Frame; -import java.io.Serializable; -import java.util.Iterator; -import java.util.Vector; -import javax.swing.JDialog; -import javax.swing.JList; -import javax.swing.JOptionPane; -import net.sf.gridarta.MapManager; -import net.sf.gridarta.gameobject.GameObject; -import net.sf.gridarta.gui.gameobjectattributespanel.ScriptTab; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Stores and manages information about scripted events. This data is only - * needed for those arches with one or more events defined. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @xxx This class is designed very badly, as it combines model and - * presentation. - */ -public class AbstractScriptArchData<G extends GameObject<G, ?, ?>> implements ScriptArchData<G>, Serializable { - - /** The serial version UID. */ - private static final long serialVersionUID = 1; - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(AbstractScriptArchData.class); - - /** - * The attribute name for the subtype field. - */ - @NotNull - private final String subtypeAttribute; - - /** - * The object type for event objects. - */ - private final int eventTypeNo; - - /** - * The {@link ScriptArchUtils} instance to use. - */ - @NotNull - private final ScriptArchUtils scriptArchUtils; - - /** - * The {@link ScriptedEventFactory} instance to use. - */ - @NotNull - private final ScriptedEventFactory<G> scriptedEventFactory; - - /** - * The {@link ScriptArchEditor} instance to use. - */ - @NotNull - private final ScriptArchEditor<G> scriptArchEditor; - - /** - * Create a ScriptArchData. - * @param subtypeAttribute the attribute name for the subtype field - * @param eventTypeNo the object type for event objects - * @param scriptArchUtils the script arch utils instance to use - * @param scriptedEventFactory the scripted event factory instance to use - * @param scriptArchEditor the script arch editor instance to use - */ - public AbstractScriptArchData(@NotNull final String subtypeAttribute, final int eventTypeNo, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptedEventFactory<G> scriptedEventFactory, @NotNull final ScriptArchEditor<G> scriptArchEditor) { - this.subtypeAttribute = subtypeAttribute; - this.eventTypeNo = eventTypeNo; - this.scriptArchUtils = scriptArchUtils; - this.scriptedEventFactory = scriptedEventFactory; - this.scriptArchEditor = scriptArchEditor; - } - - /** {@inheritDoc} */ - public void createNewEvent(final JDialog frame, @NotNull final G gameObject) { - scriptArchEditor.createNewEvent(frame, this, gameObject); - } - - /** {@inheritDoc} */ - public void addEventsToJList(final JList list, @NotNull final G gameObject) { - //cher: JList expects Vector, so we MUST use an obsolete concrete collection. - //noinspection CollectionDeclaredAsConcreteClass,UseOfObsoleteCollectionType - final Vector<String> content = new Vector<String>(); - for (final G tmp : gameObject) { - if (tmp.getTypeNo() == eventTypeNo) { - content.add(" " + scriptArchUtils.typeName(tmp.getAttributeInt(subtypeAttribute))); - } - } - - list.setListData(content); - list.setSelectedIndex(0); - } - - /** {@inheritDoc} */ - @Nullable - public G getScriptedEvent(final int eventSubtype, @NotNull final G gameObject) { - for (final G tmp : gameObject) { - if (tmp.getTypeNo() == eventTypeNo && tmp.getAttributeInt(subtypeAttribute) == eventSubtype) { - return tmp; - } - } - return null; - } - - /** {@inheritDoc} */ - public void validateAllEvents(@NotNull final G gameObject) { - final Iterator<G> it = gameObject.iterator(); - while (it.hasNext()) { - final G tmp = it.next(); - if (tmp.getTypeNo() == eventTypeNo) { - final ScriptedEvent<G> se = scriptedEventFactory.newScriptedEvent(tmp); - // validate this event - if (!se.isValid()) { - // this event is invalid - if (log.isInfoEnabled()) { - log.info("-> Deleting invalid event..."); - } - it.remove(); - } - } - } - } - - /** {@inheritDoc} */ - public boolean isEmpty(@NotNull final G gameObject) { - for (final G tmp : gameObject) { - if (tmp.getTypeNo() == eventTypeNo) { - return false; - } - } - return true; - } - - - /** {@inheritDoc} */ - public void modifyEventScript(int eventIndex, final int task, @NotNull final JList panelList, @NotNull final MapManager<?, ?, ?, ?> mapManager, @NotNull final Frame parent, @NotNull final G gameObject) { - G oldEvent = null; - - /* Find the event object */ - for (final G tmp : gameObject) { - if (tmp.getTypeNo() == eventTypeNo) { - if (eventIndex == 0) { - oldEvent = tmp; - break; - } else { - eventIndex--; - } - } - } - - if (oldEvent != null) { - final ScriptedEvent<G> event = scriptedEventFactory.newScriptedEvent(oldEvent); - // now decide what to do: - if (task == ScriptTab.SCRIPT_OPEN) { - ScriptedEventEditor.openScript(mapManager, event.getScriptPath(), parent); - } else if (task == ScriptTab.SCRIPT_EDIT_PATH) { - ScriptedEventEditor.editParameters(event, parent); - } else if (task == ScriptTab.SCRIPT_REMOVE) { - // first ask for confirmation - if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + scriptArchUtils.typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { - // remove this event from the GameObject - oldEvent.remove(); - addEventsToJList(panelList, gameObject); // update panel JList - } - } - } else { - log.error("Error in modifyEventScript(): No event selected?"); - } - } - -} // class AbstractScriptArchData Copied: trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchData.java (from rev 5558, trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchData.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchData.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchData.java 2008-10-19 07:46:46 UTC (rev 5559) @@ -0,0 +1,193 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gameobject.scripts; + +import java.awt.Frame; +import java.io.Serializable; +import java.util.Iterator; +import java.util.Vector; +import javax.swing.JDialog; +import javax.swing.JList; +import javax.swing.JOptionPane; +import net.sf.gridarta.MapManager; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gui.gameobjectattributespanel.ScriptTab; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Stores and manages information about scripted events. This data is only + * needed for those arches with one or more events defined. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @xxx This class is designed very badly, as it combines model and + * presentation. + */ +public class DefaultScriptArchData<G extends GameObject<G, ?, ?>> implements ScriptArchData<G>, Serializable { + + /** The serial version UID. */ + private static final long serialVersionUID = 1; + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(DefaultScriptArchData.class); + + /** + * The attribute name for the subtype field. + */ + @NotNull + private final String subtypeAttribute; + + /** + * The object type for event objects. + */ + private final int eventTypeNo; + + /** + * The {@link ScriptArchUtils} instance to use. + */ + @NotNull + private final ScriptArchUtils scriptArchUtils; + + /** + * The {@link ScriptedEventFactory} instance to use. + */ + @NotNull + private final ScriptedEventFactory<G> scriptedEventFactory; + + /** + * The {@link ScriptArchEditor} instance to use. + */ + @NotNull + private final ScriptArchEditor<G> scriptArchEditor; + + /** + * Create a ScriptArchData. + * @param subtypeAttribute the attribute name for the subtype field + * @param eventTypeNo the object type for event objects + * @param scriptArchUtils the script arch utils instance to use + * @param scriptedEventFactory the scripted event factory instance to use + * @param scriptArchEditor the script arch editor instance to use + */ + public DefaultScriptArchData(@NotNull final String subtypeAttribute, final int eventTypeNo, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptedEventFactory<G> scriptedEventFactory, @NotNull final ScriptArchEditor<G> scriptArchEditor) { + this.subtypeAttribute = subtypeAttribute; + this.eventTypeNo = eventTypeNo; + this.scriptArchUtils = scriptArchUtils; + this.scriptedEventFactory = scriptedEventFactory; + this.scriptArchEditor = scriptArchEditor; + } + + /** {@inheritDoc} */ + public void createNewEvent(final JDialog frame, @NotNull final G gameObject) { + scriptArchEditor.createNewEvent(frame, this, gameObject); + } + + /** {@inheritDoc} */ + public void addEventsToJList(final JList list, @NotNull final G gameObject) { + //cher: JList expects Vector, so we MUST use an obsolete concrete collection. + //noinspection CollectionDeclaredAsConcreteClass,UseOfObsoleteCollectionType + final Vector<String> content = new Vector<String>(); + for (final G tmp : gameObject) { + if (tmp.getTypeNo() == eventTypeNo) { + content.add(" " + scriptArchUtils.typeName(tmp.getAttributeInt(subtypeAttribute))); + } + } + + list.setListData(content); + list.setSelectedIndex(0); + } + + /** {@inheritDoc} */ + @Nullable + public G getScriptedEvent(final int eventSubtype, @NotNull final G gameObject) { + for (final G tmp : gameObject) { + if (tmp.getTypeNo() == eventTypeNo && tmp.getAttributeInt(subtypeAttribute) == eventSubtype) { + return tmp; + } + } + return null; + } + + /** {@inheritDoc} */ + public void validateAllEvents(@NotNull final G gameObject) { + final Iterator<G> it = gameObject.iterator(); + while (it.hasNext()) { + final G tmp = it.next(); + if (tmp.getTypeNo() == eventTypeNo) { + final ScriptedEvent<G> se = scriptedEventFactory.newScriptedEvent(tmp); + // validate this event + if (!se.isValid()) { + // this event is invalid + if (log.isInfoEnabled()) { + log.info("-> Deleting invalid event..."); + } + it.remove(); + } + } + } + } + + /** {@inheritDoc} */ + public boolean isEmpty(@NotNull final G gameObject) { + for (final G tmp : gameObject) { + if (tmp.getTypeNo() == eventTypeNo) { + return false; + } + } + return true; + } + + + /** {@inheritDoc} */ + public void modifyEventScript(int eventIndex, final int task, @NotNull final JList panelList, @NotNull final MapManager<?, ?, ?, ?> mapManager, @NotNull final Frame parent, @NotNull final G gameObject) { + G oldEvent = null; + + /* Find the event object */ + for (final G tmp : gameObject) { + if (tmp.getTypeNo() == eventTypeNo) { + if (eventIndex == 0) { + oldEvent = tmp; + break; + } else { + eventIndex--; + } + } + } + + if (oldEvent != null) { + final ScriptedEvent<G> event = scriptedEventFactory.newScriptedEvent(oldEvent); + // now decide what to do: + if (task == ScriptTab.SCRIPT_OPEN) { + ScriptedEventEditor.openScript(mapManager, event.getScriptPath(), parent); + } else if (task == ScriptTab.SCRIPT_EDIT_PATH) { + ScriptedEventEditor.editParameters(event, parent); + } else if (task == ScriptTab.SCRIPT_REMOVE) { + // first ask for confirmation + if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + scriptArchUtils.typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { + // remove this event from the GameObject + oldEvent.remove(); + addEventsToJList(panelList, gameObject); // update panel JList + } + } + } else { + log.error("Error in modifyEventScript(): No event selected?"); + } + } + +} // class DefaultScriptArchData Property changes on: trunk/src/app/net/sf/gridarta/gameobject/scripts/DefaultScriptArchData.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 08:05:14
|
Revision: 5561 http://gridarta.svn.sourceforge.net/gridarta/?rev=5561&view=rev Author: akirschbaum Date: 2008-10-19 08:05:04 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Move ArchetypeSetLoader.addPNGFace() to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSetLoader.java trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_de.properties trunk/crossfire/src/cfeditor/messages_fr.properties trunk/crossfire/src/cfeditor/messages_sv.properties trunk/daimonin/src/daieditor/gameobject/ArchetypeSetLoader.java trunk/daimonin/src/daieditor/messages.properties trunk/daimonin/src/daieditor/messages_de.properties trunk/daimonin/src/daieditor/messages_fr.properties trunk/daimonin/src/daieditor/messages_sv.properties trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSetLoader.java trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSetLoader.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSetLoader.java 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSetLoader.java 2008-10-19 08:05:04 UTC (rev 5561) @@ -134,7 +134,7 @@ * @param throwableHandler the throwable handler to use */ public ArchetypeSetLoader(@NotNull final GlobalSettings globalSettings, @NotNull final GameObjectParser<GameObject, MapArchObject, Archetype> gameObjectParser, @NotNull final String collectedDirectory, @NotNull final String configurationDirectory, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final AbstractArchetypeParser<GameObject, MapArchObject, Archetype> archetypeParser, @NotNull final EditTypes editTypes, @NotNull final FaceObjects faceObjects, @NotNull final AnimationObjects<? extends AnimationObject> animationObjects, @NotNull final ThrowableHandler<Throwable> throwableHandler) { - super(collectedDirectory, animationObjects, throwableHandler); + super(collectedDirectory, animationObjects, throwableHandler, faceObjects); this.globalSettings = globalSettings; this.gameObjectParser = gameObjectParser; this.collectedDirectory = collectedDirectory; @@ -286,31 +286,10 @@ } } - /** - * Load a png from the file, convert it to IconImage and attach it to the - * facelist. - * @param baseDir the base directory to strip from filenames - * @param filename filename, absolute path - * @param name name of the png (e.g. blocked.111.png) - * @param parent the parent component for error messages - */ - private void addPNGFace(@NotNull final File baseDir, final String filename, final String name, @NotNull final Component parent) { - final String facename = generateFaceName(name); - ((ArchFaceProvider) FaceObjectProviders.normal).addInfo(facename, filename); - final int stripPath = baseDir.getAbsolutePath().length(); - try { - faceObjects.addFaceObject(facename, filename.substring(stripPath, filename.length() - 4).replace('\\', '/'), filename, 0, (int) new File(filename).length()); - } catch (final DuplicateFaceException e) { - ACTION_FACTORY.showMessageDialog(parent, "loadDuplicateFace", e.getDuplicate().getFaceName(), e.getDuplicate().getOriginalFilename(), e.getExisting().getOriginalFilename()); - } - } - - /** - * Generate the facename for a face. - * @param name filename to generate facename from - * @return facename generated from <var>name</var> - */ - private String generateFaceName(final String name) { + /** {@inheritDoc} */ + @NotNull + @Override + protected String generateFaceName(@NotNull final String name) { if (archetypeSet.getImageSet() != null) { // we have to snip out the imageset-information here from // the 'name', and the ".png": (e.g. blocked.base.111.png -> blocked.111) Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/crossfire/src/cfeditor/messages.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -30,8 +30,6 @@ ########## # Dialogs -loadDuplicateFace.title=Error: Duplicate face -loadDuplicateFace.message=Warning!\n\nDuplicate face: ''{0}''\nFiles: ''{1}''\nand ''{2}''\nI will ignore this duplicate. # Map Properties mapParametersTabTitle=Parameters Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -26,8 +26,6 @@ ########## # Dialogs -loadDuplicateFace.title=Fehler: doppelte Grafik -loadDuplicateFace.message=Warning!\n\nDopplete Grafik: ''{0}''\nDateien: ''{1}''\nund ''{2}''\nDie doppelte Grafik wird ignoriert. # Map Properties mapParametersTabTitle=Parameter Modified: trunk/crossfire/src/cfeditor/messages_fr.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_fr.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/crossfire/src/cfeditor/messages_fr.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -27,8 +27,6 @@ ########## # Dialogs -#loadDuplicateFace.title= -#loadDuplicateFace.message= # Map Properties #mapParametersTabTitle= Modified: trunk/crossfire/src/cfeditor/messages_sv.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_sv.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/crossfire/src/cfeditor/messages_sv.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -26,8 +26,6 @@ ########## # Dialogs -loadDuplicateFace.title=Fel: duplicerad bild -loadDuplicateFace.message=Varning!\n\nDuplicerad bild: ''{0}''\nFiler: ''{1}''\noch ''{2}''\nJag kommer att ignorera detta duplikat. # Map Properties #mapParametersTabTitle= Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSetLoader.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSetLoader.java 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSetLoader.java 2008-10-19 08:05:04 UTC (rev 5561) @@ -149,7 +149,7 @@ * @param throwableHandler the throwable handler to use */ public ArchetypeSetLoader(@NotNull final GlobalSettings globalSettings, @NotNull final GameObjectParser<GameObject, MapArchObject, Archetype> gameObjectParser, @NotNull final String collectedDirectory, @NotNull final String configurationDirectory, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final AbstractArchetypeParser<GameObject, MapArchObject, Archetype> archetypeParser, @NotNull final EditTypes editTypes, @NotNull final FaceObjects faceObjects, @NotNull final AnimationObjects<? extends AnimationObject> animationObjects, @NotNull final ThrowableHandler<Throwable> throwableHandler) { - super(collectedDirectory, animationObjects, throwableHandler); + super(collectedDirectory, animationObjects, throwableHandler, faceObjects); this.globalSettings = globalSettings; this.gameObjectParser = gameObjectParser; this.collectedDirectory = collectedDirectory; @@ -397,31 +397,10 @@ } } - /** - * Load a png from the file, convert it to IconImage and attach it to the - * facelist. - * @param baseDir the base directory to strip from filenames - * @param filename filename, absolute path - * @param name name of the png (e.g. blocked.111.png) - * @param parent the parent component for error messages - */ - private void addPNGFace(@NotNull final File baseDir, final String filename, final String name, @NotNull final Component parent) { - final String facename = generateFaceName(name); - ((ArchFaceProvider) FaceObjectProviders.normal).addInfo(facename, filename); - final int stripPath = baseDir.getAbsolutePath().length(); - try { - faceObjects.addFaceObject(facename, filename.substring(stripPath, filename.length() - 4).replace('\\', '/'), filename, 0, (int) new File(filename).length()); - } catch (final DuplicateFaceException e) { - ACTION_FACTORY.showMessageDialog(parent, "loadDuplicateFace", e.getDuplicate().getFaceName(), e.getDuplicate().getOriginalFilename(), e.getExisting().getOriginalFilename()); - } - } - - /** - * Generate the facename for a face. - * @param name filename to generate facename from - * @return facename generated from <var>name</var> - */ - private static String generateFaceName(final String name) { + /** {@inheritDoc} */ + @NotNull + @Override + protected String generateFaceName(@NotNull final String name) { return name.substring(0, name.length() - 4); } Modified: trunk/daimonin/src/daieditor/messages.properties =================================================================== --- trunk/daimonin/src/daieditor/messages.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/daimonin/src/daieditor/messages.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -31,9 +31,6 @@ mapUnsaved.title=Map Not Saved mapUnsaved.message=Please save this map first. -loadDuplicateFace.title=Error: Duplicate face -loadDuplicateFace.message=Warning!\n\nDuplicate face: ''{0}''\nFiles: ''{1}''\nand ''{2}''\nI will ignore this duplicate. - # Map Properties mapMap=Map mapSound=Background sound Modified: trunk/daimonin/src/daieditor/messages_de.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_de.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/daimonin/src/daieditor/messages_de.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -31,9 +31,6 @@ #mapUnsaved.title= #mapUnsaved.message= -loadDuplicateFace.title=Fehler: doppelte Grafik -loadDuplicateFace.message=Warning!\n\nDopplete Grafik: ''{0}''\nDateien: ''{1}''\nund ''{2}''\nDie doppelte Grafik wird ignoriert. - # Map Properties mapMap=Karte #mapSound= Modified: trunk/daimonin/src/daieditor/messages_fr.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_fr.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/daimonin/src/daieditor/messages_fr.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -32,9 +32,6 @@ #mapUnsaved.title= #mapUnsaved.message= -#loadDuplicateFace.title= -#loadDuplicateFace.message= - # Map Properties #mapMap= #mapSound= Modified: trunk/daimonin/src/daieditor/messages_sv.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_sv.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/daimonin/src/daieditor/messages_sv.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -31,9 +31,6 @@ mapUnsaved.title=Kartan har inte sparats. mapUnsaved.message=Var v\xE4nlig och spara den h\xE4r kartan f\xF6rst. -loadDuplicateFace.title=Fel: duplicerad bild -loadDuplicateFace.message=Varning!\n\nDuplicerad bild: ''{0}''\nFiler: ''{1}''\noch ''{2}''\nJag kommer att ignorera detta duplikat. - # Map Properties mapMap=Karta mapSound=Bakgrundsljud Modified: trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSetLoader.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSetLoader.java 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSetLoader.java 2008-10-19 08:05:04 UTC (rev 5561) @@ -19,6 +19,7 @@ package net.sf.gridarta.gameobject; +import java.awt.Component; import java.io.File; import java.io.IOException; import java.io.Reader; @@ -26,7 +27,12 @@ import net.sf.gridarta.gameobject.anim.AnimationObjects; import net.sf.gridarta.gameobject.anim.AnimationParseException; import net.sf.gridarta.gameobject.anim.DuplicateAnimationException; +import net.sf.gridarta.gameobject.face.ArchFaceProvider; +import net.sf.gridarta.gameobject.face.DuplicateFaceException; +import net.sf.gridarta.gameobject.face.FaceObjectProviders; +import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.utils.IOUtils; +import net.sf.japi.swing.ActionFactory; import net.sf.japi.util.ThrowableHandler; import org.jetbrains.annotations.NotNull; @@ -39,6 +45,9 @@ */ public abstract class AbstractArchetypeSetLoader { + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.gridarta"); + /** * The collected directory. */ @@ -58,15 +67,23 @@ private final ThrowableHandler<Throwable> throwableHandler; /** + * The face objects instance. + */ + @NotNull + private final FaceObjects faceObjects; + + /** * Creates a new instance. * @param collectedDirectory the collected directory * @param animationObjects the animation objects instance * @param throwableHandler the throwable handler to use + * @param faceObjects the face ojects instance */ - protected AbstractArchetypeSetLoader(@NotNull final String collectedDirectory, @NotNull final AnimationObjects<? extends AnimationObject> animationObjects, @NotNull final ThrowableHandler<Throwable> throwableHandler) { + protected AbstractArchetypeSetLoader(@NotNull final String collectedDirectory, @NotNull final AnimationObjects<? extends AnimationObject> animationObjects, @NotNull final ThrowableHandler<Throwable> throwableHandler, @NotNull final FaceObjects faceObjects) { this.collectedDirectory = collectedDirectory; this.animationObjects = animationObjects; this.throwableHandler = throwableHandler; + this.faceObjects = faceObjects; } /** Loading all animations from the big collected animations file. */ @@ -88,4 +105,31 @@ } } + /** + * Load a png from the file, convert it to IconImage and attach it to the + * facelist. + * @param baseDir the base directory to strip from filenames + * @param filename filename, absolute path + * @param name name of the png (e.g. blocked.111.png) + * @param parent the parent component for error messages + */ + protected void addPNGFace(@NotNull final File baseDir, final String filename, final String name, @NotNull final Component parent) { + final String facename = generateFaceName(name); + ((ArchFaceProvider) FaceObjectProviders.normal).addInfo(facename, filename); + final int stripPath = baseDir.getAbsolutePath().length(); + try { + faceObjects.addFaceObject(facename, filename.substring(stripPath, filename.length() - 4).replace('\\', '/'), filename, 0, (int) new File(filename).length()); + } catch (final DuplicateFaceException e) { + ACTION_FACTORY.showMessageDialog(parent, "loadDuplicateFace", e.getDuplicate().getFaceName(), e.getDuplicate().getOriginalFilename(), e.getExisting().getOriginalFilename()); + } + } + + /** + * Generate the facename for a face. + * @param name filename to generate facename from + * @return facename generated from <var>name</var> + */ + @NotNull + protected abstract String generateFaceName(@NotNull final String name); + } // class AbstractArchetypeSetLoader Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/src/app/net/sf/gridarta/messages.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -382,6 +382,9 @@ loadDuplicateArch.message.2.title.2=File loadDuplicateArch.message.3=I will ignore these duplicates. +loadDuplicateFace.title=Error: Duplicate face +loadDuplicateFace.message=Warning!\n\nDuplicate face: ''{0}''\nFiles: ''{1}''\nand ''{2}''\nI will ignore this duplicate. + # Map Properties mapTitle={0} ({1}) - Map Properties mapHelp.text=Help Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -365,6 +365,9 @@ loadDuplicateArch.message.2.title.2=Datei loadDuplicateArch.message.3=Diese Archetypen werden ignoriert. +loadDuplicateFace.title=Fehler: doppelte Grafik +loadDuplicateFace.message=Warning!\n\nDopplete Grafik: ''{0}''\nDateien: ''{1}''\nund ''{2}''\nDie doppelte Grafik wird ignoriert. + # Map Properties mapTitle={0} ({1}) - Karteneigenschaften mapHelp.text=Hilfe Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -364,6 +364,9 @@ #loadDuplicateArch.message.2.title.2= #loadDuplicateArch.message.3= +#loadDuplicateFace.title= +#loadDuplicateFace.message= + # Map Properties mapTitle={0} ({1}) - Propri\xE9t\xE9s de la carte #mapHelp.text= Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-10-19 07:48:26 UTC (rev 5560) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-10-19 08:05:04 UTC (rev 5561) @@ -368,6 +368,9 @@ loadDuplicateArch.message.2.title.2=Fil loadDuplicateArch.message.3=Jag kommer att ignorera detta duplikat. +loadDuplicateFace.title=Fel: duplicerad bild +loadDuplicateFace.message=Varning!\n\nDuplicerad bild: ''{0}''\nFiler: ''{1}''\noch ''{2}''\nJag kommer att ignorera detta duplikat. + # Map Properties mapTitle={0} ({1}) - Kartegenskaper mapHelp.text=Hj\xE4lp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 08:11:27
|
Revision: 5562 http://gridarta.svn.sourceforge.net/gridarta/?rev=5562&view=rev Author: akirschbaum Date: 2008-10-19 08:11:17 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Move CMapViewBasic.mapCursorListener to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/map/CMapViewBasic.java trunk/daimonin/src/daieditor/gui/map/CMapViewBasic.java trunk/src/app/net/sf/gridarta/gui/map/MapViewBasic.java Modified: trunk/crossfire/src/cfeditor/gui/map/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/CMapViewBasic.java 2008-10-19 08:05:04 UTC (rev 5561) +++ trunk/crossfire/src/cfeditor/gui/map/CMapViewBasic.java 2008-10-19 08:11:17 UTC (rev 5562) @@ -23,12 +23,8 @@ import cfeditor.gameobject.GameObject; import cfeditor.map.MapArchObject; import java.awt.Point; -import java.awt.Rectangle; import net.sf.gridarta.EditTypes; import net.sf.gridarta.filter.FilterControl; -import net.sf.gridarta.gui.map.MapCursor; -import net.sf.gridarta.gui.map.MapCursorEvent; -import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapUserListener; import net.sf.gridarta.gui.map.MapView; import net.sf.gridarta.gui.map.MapViewBasic; @@ -94,24 +90,6 @@ }; - private final MapCursorListener mapCursorListener = new MapCursorListener() { - - /** {@inheritDoc} */ - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { - final MapCursor mapCursor = e.getSource(); - if (mapCursor.isActive()) { - final Rectangle rec = renderer.getTileBounds(mapCursor.getLocation()); - renderer.scrollRectToVisible(rec); - } - } - - /** {@inheritDoc} */ - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { - // Ignore mode change events - } - - }; - /** * Constructs a level view. * @param filterControl the filter to use @@ -127,7 +105,6 @@ */ public CMapViewBasic(@NotNull final FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl, @NotNull final EditTypes editTypes, @NotNull final MapModel<GameObject, MapArchObject, Archetype> mapModel, final boolean isPickmap, @Nullable final Point initial, @NotNull final ToolPalette<GameObject, MapArchObject, Archetype, CMapViewBasic> toolPalette, final int xScrollDistance, final int yScrollDistance, @NotNull final SelectedSquareView<GameObject, MapArchObject, Archetype, CMapViewBasic> selectedSquareView) { super(mapModel, isPickmap, xScrollDistance, yScrollDistance, selectedSquareView); - getMapCursor().addMapCursorListener(mapCursorListener); renderer = isPickmap ? new PickmapRenderer(mapModel, getMapGrid()) : new MapRenderer(filterControl, editTypes, mapModel, getMapGrid()); setViewportView(renderer); @@ -155,7 +132,6 @@ /** {@inheritDoc} */ public void closeNotify() { super.closeNotify(); - getMapCursor().removeMapCursorListener(mapCursorListener); setViewportView(null); mapModel.removeMapModelListener(mapModelListener); renderer.removeMouseListener(mapUserListener); Modified: trunk/daimonin/src/daieditor/gui/map/CMapViewBasic.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/CMapViewBasic.java 2008-10-19 08:05:04 UTC (rev 5561) +++ trunk/daimonin/src/daieditor/gui/map/CMapViewBasic.java 2008-10-19 08:11:17 UTC (rev 5562) @@ -24,13 +24,9 @@ import daieditor.gameobject.GameObject; import daieditor.map.MapArchObject; import java.awt.Point; -import java.awt.Rectangle; import net.sf.gridarta.EditTypes; import net.sf.gridarta.filter.FilterControl; import net.sf.gridarta.gameobject.face.FaceObjects; -import net.sf.gridarta.gui.map.MapCursor; -import net.sf.gridarta.gui.map.MapCursorEvent; -import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapUserListener; import net.sf.gridarta.gui.map.MapView; import net.sf.gridarta.gui.map.MapViewBasic; @@ -98,24 +94,6 @@ }; - private final MapCursorListener mapCursorListener = new MapCursorListener() { - - /** {@inheritDoc} */ - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { - final MapCursor mapCursor = e.getSource(); - if (mapCursor.isActive()) { - final Rectangle rec = renderer.getTileBounds(mapCursor.getLocation()); - renderer.scrollRectToVisible(rec); - } - } - - /** {@inheritDoc} */ - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { - // Ignore mode change events - } - - }; - /** * Constructs a level view. * @param mainControl the main controller @@ -133,7 +111,6 @@ */ public CMapViewBasic(@NotNull final CMainControl mainControl, @NotNull final FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl, @NotNull final EditTypes editTypes, @NotNull final MapModel<GameObject, MapArchObject, Archetype> mapModel, final boolean isPickmap, @Nullable final Point initial, @NotNull final FaceObjects faceObjects, @NotNull final ToolPalette<GameObject, MapArchObject, Archetype, CMapViewBasic> toolPalette, final int xScrollDistance, final int yScrollDistance, @NotNull final SelectedSquareView<GameObject, MapArchObject, Archetype, CMapViewBasic> selectedSquareView) { super(mapModel, isPickmap, xScrollDistance, yScrollDistance, selectedSquareView); - getMapCursor().addMapCursorListener(mapCursorListener); renderer = isPickmap ? new PickmapRenderer(mainControl, mapModel, getMapGrid(), faceObjects) : new MapRenderer(mainControl, filterControl, editTypes, mapModel, getMapGrid(), faceObjects); setViewportView(renderer); @@ -161,7 +138,6 @@ /** {@inheritDoc} */ public void closeNotify() { super.closeNotify(); - getMapCursor().removeMapCursorListener(mapCursorListener); setViewportView(null); mapModel.removeMapModelListener(mapModelListener); renderer.removeMouseListener(mapUserListener); Modified: trunk/src/app/net/sf/gridarta/gui/map/MapViewBasic.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/MapViewBasic.java 2008-10-19 08:05:04 UTC (rev 5561) +++ trunk/src/app/net/sf/gridarta/gui/map/MapViewBasic.java 2008-10-19 08:11:17 UTC (rev 5562) @@ -82,6 +82,24 @@ @NotNull private final SelectedSquareView<G, A, R, V> selectedSquareView; + private final MapCursorListener mapCursorListener = new MapCursorListener() { + + /** {@inheritDoc} */ + public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + final MapCursor mapCursor = e.getSource(); + if (mapCursor.isActive()) { + final Rectangle rec = renderer.getTileBounds(mapCursor.getLocation()); + renderer.scrollRectToVisible(rec); + } + } + + /** {@inheritDoc} */ + public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + // Ignore mode change events + } + + }; + /** * Creates a MapViewBasic. * @param mapModel the map model to use @@ -108,6 +126,7 @@ getHorizontalScrollBar().setUnitIncrement(xScrollDistance); getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); + mapCursor.addMapCursorListener(mapCursorListener); } public abstract void init(@NotNull final MapView<G, A, R, V> mapView); @@ -263,6 +282,7 @@ if (!isPickmap) { mapCursor.removeMapCursorListener(selectedSquareView); } + mapCursor.removeMapCursorListener(mapCursorListener); } /** Turn the highlight off. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 08:48:42
|
Revision: 5564 http://gridarta.svn.sourceforge.net/gridarta/?rev=5564&view=rev Author: akirschbaum Date: 2008-10-19 08:47:40 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Add map validator "Exit path invalid": checks whether exit paths are valid. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gameobject/Archetype.java trunk/src/app/net/sf/gridarta/map/validation/checks/ExitChecker.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2008-10-19 08:35:32 UTC (rev 5563) +++ trunk/crossfire/ChangeLog 2008-10-19 08:47:40 UTC (rev 5564) @@ -1,3 +1,8 @@ +2008-10-19 Andreas Kirschbaum + + * Add map validator "Exit path invalid": checks whether exit paths + are valid. + 2008-10-13 Andreas Kirschbaum * Add "reload faces". Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-19 08:35:32 UTC (rev 5563) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-19 08:47:40 UTC (rev 5564) @@ -99,6 +99,7 @@ import net.sf.gridarta.map.validation.checks.ConnectedPickableChecker; import net.sf.gridarta.map.validation.checks.ConnectionChecker; import net.sf.gridarta.map.validation.checks.CustomTypeChecker; +import net.sf.gridarta.map.validation.checks.ExitChecker; import net.sf.gridarta.map.validation.checks.MapDifficultyChecker; import net.sf.gridarta.map.validation.checks.UndefinedArchetypeChecker; import net.sf.gridarta.map.validation.checks.UnsetSlayingChecker; @@ -342,6 +343,7 @@ Archetype.SUBTYPE_EVENT_CONNECTOR_TRIGGER, }), customTypeChecker, + new ExitChecker(globalSettings.getMapDir(), Archetype.TYPE_EXIT), new MapDifficultyChecker<GameObject, MapArchObject, Archetype>(), new UndefinedArchetypeChecker<GameObject, MapArchObject, Archetype>(), unsetSlayingChecker Modified: trunk/crossfire/src/cfeditor/gameobject/Archetype.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/Archetype.java 2008-10-19 08:35:32 UTC (rev 5563) +++ trunk/crossfire/src/cfeditor/gameobject/Archetype.java 2008-10-19 08:47:40 UTC (rev 5564) @@ -75,6 +75,8 @@ int TYPE_MOOD_FLOOR = 65; + int TYPE_EXIT = 66; + int TYPE_RING = 70; int TYPE_FLOOR = 71; Modified: trunk/src/app/net/sf/gridarta/map/validation/checks/ExitChecker.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/validation/checks/ExitChecker.java 2008-10-19 08:35:32 UTC (rev 5563) +++ trunk/src/app/net/sf/gridarta/map/validation/checks/ExitChecker.java 2008-10-19 08:47:40 UTC (rev 5564) @@ -57,7 +57,7 @@ public void validate(final G gameObject, final ErrorCollector<G, A, R> errorCollector) { if (gameObject.getTypeNo() == exitTypeNo) { final String path = gameObject.getAttributeString("slaying", false); - if (path.length() > 0) { + if (path.length() > 0 && !path.equals("/!")) { final File newfile; if (path.startsWith(File.pathSeparator) || path.startsWith("/")) { // we have an absolute path: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 09:26:15
|
Revision: 5563 http://gridarta.svn.sourceforge.net/gridarta/?rev=5563&view=rev Author: akirschbaum Date: 2008-10-19 08:35:32 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Move ExitChecker to common code base. Modified Paths: -------------- trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/messages.properties trunk/daimonin/src/daieditor/messages_de.properties trunk/daimonin/src/daieditor/messages_fr.properties trunk/daimonin/src/daieditor/messages_sv.properties trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties Added Paths: ----------- trunk/src/app/net/sf/gridarta/map/validation/checks/ExitChecker.java trunk/src/app/net/sf/gridarta/map/validation/checks/ExitError.java Removed Paths: ------------- trunk/daimonin/src/daieditor/map/validation/checks/ExitChecker.java trunk/daimonin/src/daieditor/map/validation/checks/ExitError.java Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 08:11:17 UTC (rev 5562) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 08:35:32 UTC (rev 5563) @@ -39,7 +39,6 @@ import daieditor.map.DefaultMapArchObjectFactory; import daieditor.map.DefaultMapControlFactory; import daieditor.map.MapArchObject; -import daieditor.map.validation.checks.ExitChecker; import daieditor.map.validation.checks.SlayingChecker; import daieditor.map.validation.checks.TilePathsChecker; import java.io.File; @@ -114,6 +113,7 @@ import net.sf.gridarta.map.validation.checks.DoubleLayerChecker; import net.sf.gridarta.map.validation.checks.DoubleTypeChecker; import net.sf.gridarta.map.validation.checks.EmptySpawnPointChecker; +import net.sf.gridarta.map.validation.checks.ExitChecker; import net.sf.gridarta.map.validation.checks.MapDifficultyChecker; import net.sf.gridarta.map.validation.checks.MobOutsideSpawnPointChecker; import net.sf.gridarta.map.validation.checks.SquareWithoutFloorChecker; @@ -405,7 +405,7 @@ new DoubleTypeChecker<GameObject, MapArchObject, Archetype>(), new DoubleLayerChecker<GameObject, MapArchObject, Archetype>(), new EmptySpawnPointChecker<GameObject, MapArchObject, Archetype>(Archetype.TYPE_SPAWN_POINT), - new ExitChecker(globalSettings.getMapDir()), + new ExitChecker(globalSettings.getMapDir(), Archetype.TYPE_EXIT), new MapDifficultyChecker<GameObject, MapArchObject, Archetype>(), new MobOutsideSpawnPointChecker<GameObject, MapArchObject, Archetype>(Archetype.TYPE_MOB), new SquareWithoutFloorChecker<GameObject, MapArchObject, Archetype>(Archetype.TYPE_FLOOR, Archetype.TYPE_SHOP_FLOOR), Deleted: trunk/daimonin/src/daieditor/map/validation/checks/ExitChecker.java =================================================================== --- trunk/daimonin/src/daieditor/map/validation/checks/ExitChecker.java 2008-10-19 08:11:17 UTC (rev 5562) +++ trunk/daimonin/src/daieditor/map/validation/checks/ExitChecker.java 2008-10-19 08:35:32 UTC (rev 5563) @@ -1,69 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor.map.validation.checks; - -import daieditor.gameobject.Archetype; -import daieditor.gameobject.GameObject; -import daieditor.map.MapArchObject; -import java.io.File; -import net.sf.gridarta.map.validation.AbstractValidator; -import net.sf.gridarta.map.validation.ErrorCollector; -import net.sf.gridarta.map.validation.GameObjectValidator; -import org.jetbrains.annotations.NotNull; - -/** - * A Validator to assert that exits are connected to maps properly. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public class ExitChecker extends AbstractValidator implements GameObjectValidator<GameObject, MapArchObject, Archetype> { - - /** The map directory to check. */ - @NotNull - private final File mapDirectory; - - /** - * Create a ExitChecker. - * @param mapDirectory map directory to check against - */ - public ExitChecker(final File mapDirectory) { - this.mapDirectory = mapDirectory; - } - - /** {@inheritDoc} */ - public void validate(final GameObject gameObject, final ErrorCollector<GameObject, MapArchObject, Archetype> errorCollector) { - if (gameObject.getTypeNo() == Archetype.TYPE_EXIT) { - final String path = gameObject.getAttributeString("slaying", false); - if (path.length() > 0) { - final File newfile; - if (path.startsWith(File.pathSeparator) || path.startsWith("/")) { - // we have an absolute path: - newfile = new File(mapDirectory.getAbsolutePath(), path.substring(1)); - } else { - // we have a relative path: - newfile = new File(gameObject.getMapSquare().getMapModel().getMapControl().getMapFile().getParent(), path); - } - if (!newfile.exists() || newfile.isDirectory()) { - errorCollector.collect(new ExitError<GameObject, MapArchObject, Archetype>(gameObject, path)); - } - } - } - } - -} // class ExitChecker Deleted: trunk/daimonin/src/daieditor/map/validation/checks/ExitError.java =================================================================== --- trunk/daimonin/src/daieditor/map/validation/checks/ExitError.java 2008-10-19 08:11:17 UTC (rev 5562) +++ trunk/daimonin/src/daieditor/map/validation/checks/ExitError.java 2008-10-19 08:35:32 UTC (rev 5563) @@ -1,54 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor.map.validation.checks; - -import net.sf.gridarta.gameobject.Archetype; -import net.sf.gridarta.gameobject.GameObject; -import net.sf.gridarta.map.MapArchObject; -import net.sf.gridarta.map.validation.GameObjectValidationError; - -/** - * Validation error that's used when a map has wrong exit paths. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public class ExitError<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends GameObjectValidationError<G, A, R> { - - /** The exit path that was wrong. */ - private final String exitPath; - - /** - * Create a MapValidationError. - * @param gameObject the GameObject on which the error occurred - * @param exitPath exit path which was wrong - */ - public ExitError(final G gameObject, final String exitPath) { - super(gameObject); - this.exitPath = exitPath; - } - - /** - * Returns the exit path that was wrong. - * @return the exit path that was wrong. - */ - public String getExitPath() { - return exitPath; - } - -} // class ExitError Modified: trunk/daimonin/src/daieditor/messages.properties =================================================================== --- trunk/daimonin/src/daieditor/messages.properties 2008-10-19 08:11:17 UTC (rev 5562) +++ trunk/daimonin/src/daieditor/messages.properties 2008-10-19 08:35:32 UTC (rev 5563) @@ -209,9 +209,6 @@ ################# # Map Validation -Validator.Exit.title=Exit path invalid -Validator.Exit.msg=<html><h3>{0}</h3><p>This exit has an invalid path.<br>Change the path or create the missing map. - Validator.TilePaths.title=Tile path invalid Validator.TilePaths.msg=<html><h3>{0}</h3><p>This map has invalid tile paths.<br>Go to the map properties dialog and change the map tile paths. Modified: trunk/daimonin/src/daieditor/messages_de.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_de.properties 2008-10-19 08:11:17 UTC (rev 5562) +++ trunk/daimonin/src/daieditor/messages_de.properties 2008-10-19 08:35:32 UTC (rev 5563) @@ -177,8 +177,5 @@ ################# # Map Validation -#Validator.Exit.title= -#Validator.Exit.msg= - #Validator.TilePaths.title= #Validator.TilePaths.msg= Modified: trunk/daimonin/src/daieditor/messages_fr.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_fr.properties 2008-10-19 08:11:17 UTC (rev 5562) +++ trunk/daimonin/src/daieditor/messages_fr.properties 2008-10-19 08:35:32 UTC (rev 5563) @@ -179,8 +179,5 @@ ################# # Map Validation -#Validator.Exit.title= -#Validator.Exit.msg= - #Validator.TilePaths.title= #Validator.TilePaths.msg= Modified: trunk/daimonin/src/daieditor/messages_sv.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_sv.properties 2008-10-19 08:11:17 UTC (rev 5562) +++ trunk/daimonin/src/daieditor/messages_sv.properties 2008-10-19 08:35:32 UTC (rev 5563) @@ -179,8 +179,5 @@ ################# # Map Validation -#Validator.Exit.title= -#Validator.Exit.msg= - #Validator.TilePaths.title= #Validator.TilePaths.msg= Copied: trunk/src/app/net/sf/gridarta/map/validation/checks/ExitChecker.java (from rev 5561, trunk/daimonin/src/daieditor/map/validation/checks/ExitChecker.java) =================================================================== --- trunk/src/app/net/sf/gridarta/map/validation/checks/ExitChecker.java (rev 0) +++ trunk/src/app/net/sf/gridarta/map/validation/checks/ExitChecker.java 2008-10-19 08:35:32 UTC (rev 5563) @@ -0,0 +1,76 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.map.validation.checks; + +import java.io.File; +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.validation.AbstractValidator; +import net.sf.gridarta.map.validation.ErrorCollector; +import net.sf.gridarta.map.validation.GameObjectValidator; +import org.jetbrains.annotations.NotNull; + +/** + * A Validator to assert that exits are connected to maps properly. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class ExitChecker<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractValidator implements GameObjectValidator<G, A, R> { + + /** The map directory to check. */ + @NotNull + private final File mapDirectory; + + /** + * The archetype type number of exits. + */ + private final int exitTypeNo; + + /** + * Create a ExitChecker. + * @param mapDirectory map directory to check against + * @param exitTypeNo the archetype type number of exits + */ + public ExitChecker(final File mapDirectory, final int exitTypeNo) { + this.mapDirectory = mapDirectory; + this.exitTypeNo = exitTypeNo; + } + + /** {@inheritDoc} */ + public void validate(final G gameObject, final ErrorCollector<G, A, R> errorCollector) { + if (gameObject.getTypeNo() == exitTypeNo) { + final String path = gameObject.getAttributeString("slaying", false); + if (path.length() > 0) { + final File newfile; + if (path.startsWith(File.pathSeparator) || path.startsWith("/")) { + // we have an absolute path: + newfile = new File(mapDirectory.getAbsolutePath(), path.substring(1)); + } else { + // we have a relative path: + newfile = new File(gameObject.getMapSquare().getMapModel().getMapControl().getMapFile().getParent(), path); + } + if (!newfile.exists() || newfile.isDirectory()) { + errorCollector.collect(new ExitError<G, A, R>(gameObject, path)); + } + } + } + } + +} // class ExitChecker Property changes on: trunk/src/app/net/sf/gridarta/map/validation/checks/ExitChecker.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Copied: trunk/src/app/net/sf/gridarta/map/validation/checks/ExitError.java (from rev 5561, trunk/daimonin/src/daieditor/map/validation/checks/ExitError.java) =================================================================== --- trunk/src/app/net/sf/gridarta/map/validation/checks/ExitError.java (rev 0) +++ trunk/src/app/net/sf/gridarta/map/validation/checks/ExitError.java 2008-10-19 08:35:32 UTC (rev 5563) @@ -0,0 +1,54 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.map.validation.checks; + +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.validation.GameObjectValidationError; + +/** + * Validation error that's used when a map has wrong exit paths. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class ExitError<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends GameObjectValidationError<G, A, R> { + + /** The exit path that was wrong. */ + private final String exitPath; + + /** + * Create a MapValidationError. + * @param gameObject the GameObject on which the error occurred + * @param exitPath exit path which was wrong + */ + public ExitError(final G gameObject, final String exitPath) { + super(gameObject); + this.exitPath = exitPath; + } + + /** + * Returns the exit path that was wrong. + * @return the exit path that was wrong. + */ + public String getExitPath() { + return exitPath; + } + +} // class ExitError Property changes on: trunk/src/app/net/sf/gridarta/map/validation/checks/ExitError.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2008-10-19 08:11:17 UTC (rev 5562) +++ trunk/src/app/net/sf/gridarta/messages.properties 2008-10-19 08:35:32 UTC (rev 5563) @@ -931,6 +931,7 @@ prefs.Validator.DoubleLayer=Whether this map validator check is is enabled. prefs.Validator.DoubleType=Whether this map validator check is is enabled. prefs.Validator.EmptySpawnPoint=Whether this map validator check is is enabled. +prefs.Validator.Exit=Whether this map validator check is is enabled. prefs.Validator.MapDifficulty=Whether this map validator check is is enabled. prefs.Validator.MobOutsideSpawnPoint=Whether this map validator check is is enabled. prefs.Validator.Slaying=Whether this map validator check is is enabled. @@ -1082,6 +1083,10 @@ Validator.EnvironmentSensorSlaying.title=Invalid slaying Validator.EnvironmentSensorSlaying.msg=<html><h3>{0}</h3><p>The slaying field of this game object is not valid for an environment sensor.<br>The value should be either empty or of the form HH:MM-HH:MM.</p><p>You could:</p><ul><li>Change the slaying attribute</li><li>Delete the environment sensor</li></ul> +Validator.Exit.default=true +Validator.Exit.title=Exit path invalid +Validator.Exit.msg=<html><h3>{0}</h3><p>This exit has an invalid path.<br>Change the path or create the missing map. + Validator.MapDifficulty.default=true Validator.MapDifficulty.title=Map difficulty invalid Validator.MapDifficulty.msg=<html><h3>{0}</h3>This map has an invalid difficulty.<br>Go to the map properties dialog and change the difficulty setting. Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2008-10-19 08:11:17 UTC (rev 5562) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2008-10-19 08:35:32 UTC (rev 5563) @@ -938,6 +938,9 @@ Validator.EnvironmentSensorSlaying.title=Ung\xFCltiger Wert f\xFCr "slaying" Validator.EnvironmentSensorSlaying.msg=<html><h3>{0}</h3><p>Dieses Objekt besitzt einen ung\xFCltigen Wert im Attribut "slaying".<br>Der Wert sollte entweder leer sein oder den Aufbau HH:MM-HH:MM haben.</p><p>Sie k\xF6nnen:</p><ul><li>Das Attribut \xE4ndern</li><li>Das Objekt l\xF6schen</li></ul> +Validator.Exit.title=Ung\xFCltiger Kartenpfad +Validator.Exit.msg=<html><h3>{0}</h3><p>Dieser Ausgang besitzt einen ung\xFCltigen Kartenpfad.<br>\xC4ndern sie den Kartenpfad oder erstellen Sie die fehlende Karte. + Validator.MapDifficulty.title=Ung\xFCltige Schwierigkeit Validator.MapDifficulty.msg=<html><h3>{0}</h3>Die Karte besitzt eine ung\xFCltige Schwierigkeit.<br>\xC4ndern Sie die Schwierigkeit in den Karteneigenschaften. Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-10-19 08:11:17 UTC (rev 5562) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-10-19 08:35:32 UTC (rev 5563) @@ -937,6 +937,9 @@ #Validator.EnvironmentSensorSlaying.title= #Validator.EnvironmentSensorSlaying.msg= +#Validator.Exit.title= +#Validator.Exit.msg= + #Validator.MapDifficulty.title= #Validator.MapDifficulty.msg= Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-10-19 08:11:17 UTC (rev 5562) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-10-19 08:35:32 UTC (rev 5563) @@ -942,6 +942,9 @@ #Validator.EnvironmentSensorSlaying.title= #Validator.EnvironmentSensorSlaying.msg= +#Validator.Exit.title= +#Validator.Exit.msg= + #Validator.MapDifficulty.title= #Validator.MapDifficulty.msg= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 18:31:36
|
Revision: 5565 http://gridarta.svn.sourceforge.net/gridarta/?rev=5565&view=rev Author: akirschbaum Date: 2008-10-19 18:31:34 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Move TilePathsChecker to common code base. Modified Paths: -------------- trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/messages.properties trunk/daimonin/src/daieditor/messages_de.properties trunk/daimonin/src/daieditor/messages_fr.properties trunk/daimonin/src/daieditor/messages_sv.properties trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties Added Paths: ----------- trunk/src/app/net/sf/gridarta/map/validation/checks/TilePathsChecker.java trunk/src/app/net/sf/gridarta/map/validation/checks/TilePathsError.java Removed Paths: ------------- trunk/daimonin/src/daieditor/map/validation/checks/TilePathsChecker.java trunk/daimonin/src/daieditor/map/validation/checks/TilePathsError.java Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 08:47:40 UTC (rev 5564) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 18:31:34 UTC (rev 5565) @@ -40,7 +40,6 @@ import daieditor.map.DefaultMapControlFactory; import daieditor.map.MapArchObject; import daieditor.map.validation.checks.SlayingChecker; -import daieditor.map.validation.checks.TilePathsChecker; import java.io.File; import java.util.Arrays; import java.util.List; @@ -118,6 +117,7 @@ import net.sf.gridarta.map.validation.checks.MobOutsideSpawnPointChecker; import net.sf.gridarta.map.validation.checks.SquareWithoutFloorChecker; import net.sf.gridarta.map.validation.checks.SysObjectNotOnLayerZeroChecker; +import net.sf.gridarta.map.validation.checks.TilePathsChecker; import net.sf.gridarta.map.validation.checks.UndefinedArchetypeChecker; import net.sf.gridarta.map.validation.checks.UnsetSlayingChecker; import net.sf.gridarta.spells.SpellsUtils; @@ -411,7 +411,7 @@ new SquareWithoutFloorChecker<GameObject, MapArchObject, Archetype>(Archetype.TYPE_FLOOR, Archetype.TYPE_SHOP_FLOOR), new SlayingChecker<GameObject, MapArchObject, Archetype>(), new SysObjectNotOnLayerZeroChecker<GameObject, MapArchObject, Archetype>(), - new TilePathsChecker(globalSettings.getMapDir()), + new TilePathsChecker(globalSettings.getMapDir(), 8), new UndefinedArchetypeChecker<GameObject, MapArchObject, Archetype>(), new UnsetSlayingChecker<GameObject, MapArchObject, Archetype>(Archetype.TYPE_LOCKED_DOOR, Archetype.TYPE_SPECIAL_KEY, Archetype.TYPE_DETECTOR, Archetype.TYPE_MARKER, Archetype.TYPE_INVENTORY_CHECKER, Archetype.TYPE_CONTAINER) ); Deleted: trunk/daimonin/src/daieditor/map/validation/checks/TilePathsChecker.java =================================================================== --- trunk/daimonin/src/daieditor/map/validation/checks/TilePathsChecker.java 2008-10-19 08:47:40 UTC (rev 5564) +++ trunk/daimonin/src/daieditor/map/validation/checks/TilePathsChecker.java 2008-10-19 18:31:34 UTC (rev 5565) @@ -1,72 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor.map.validation.checks; - -import daieditor.IGUIConstants; -import daieditor.gameobject.Archetype; -import daieditor.gameobject.GameObject; -import daieditor.map.MapArchObject; -import java.io.File; -import net.sf.gridarta.map.MapModel; -import net.sf.gridarta.map.validation.AbstractValidator; -import net.sf.gridarta.map.validation.ErrorCollector; -import net.sf.gridarta.map.validation.MapValidator; -import org.jetbrains.annotations.NotNull; - -/** - * Validator that checks whether all tile paths are valid. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @xxx contains some casting hacks that need to be removed. - */ -public class TilePathsChecker extends AbstractValidator implements MapValidator<GameObject, MapArchObject, Archetype> { - - /** The map directory to check. */ - @NotNull - private final File mapDirectory; - - /** - * Create a TilePathsChecker. - * @param mapDirectory map directory to check against - */ - public TilePathsChecker(final File mapDirectory) { - this.mapDirectory = mapDirectory; - } - - /** {@inheritDoc} */ - public void validate(final MapModel<GameObject, MapArchObject, Archetype> mapModel, final ErrorCollector<GameObject, MapArchObject, Archetype> errorCollector) { - for (final int direction : IGUIConstants.ALL_TILE_PATHS) { - final String path = mapModel.getMapArchObject().getTilePath(direction); - if (path.length() > 0) { - final File newfile; - if (path.startsWith(File.pathSeparator) || path.startsWith("/")) { - // we have an absolute path: - newfile = new File(mapDirectory.getAbsolutePath(), path.substring(1)); - } else { - // we have a relative path: - newfile = new File(mapModel.getMapControl().getMapFile().getParent(), path); - } - if (!newfile.exists() || newfile.isDirectory()) { - errorCollector.collect(new TilePathsError<GameObject, MapArchObject, Archetype>(mapModel, path)); - } - } - } - } - -} // class TilePathsChecker Deleted: trunk/daimonin/src/daieditor/map/validation/checks/TilePathsError.java =================================================================== --- trunk/daimonin/src/daieditor/map/validation/checks/TilePathsError.java 2008-10-19 08:47:40 UTC (rev 5564) +++ trunk/daimonin/src/daieditor/map/validation/checks/TilePathsError.java 2008-10-19 18:31:34 UTC (rev 5565) @@ -1,55 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor.map.validation.checks; - -import net.sf.gridarta.gameobject.Archetype; -import net.sf.gridarta.gameobject.GameObject; -import net.sf.gridarta.map.MapArchObject; -import net.sf.gridarta.map.MapModel; -import net.sf.gridarta.map.validation.MapValidationError; - -/** - * Validation error that's used when a map has wrong tile paths. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public class TilePathsError<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends MapValidationError<G, A, R> { - - /** The tile path that was wrong. */ - private final String tilePath; - - /** - * Create a MapValidationError. - * @param mapModel the map on which the error occurred - * @param tilePath tile path which was wrong - */ - public TilePathsError(final MapModel<G, A, R> mapModel, final String tilePath) { - super(mapModel); - this.tilePath = tilePath; - } - - /** - * Returns the tile path that was wrong. - * @return the tile path that was wrong. - */ - public String getTilePath() { - return tilePath; - } - -} // class TilePathsError Modified: trunk/daimonin/src/daieditor/messages.properties =================================================================== --- trunk/daimonin/src/daieditor/messages.properties 2008-10-19 08:47:40 UTC (rev 5564) +++ trunk/daimonin/src/daieditor/messages.properties 2008-10-19 18:31:34 UTC (rev 5565) @@ -206,13 +206,6 @@ mapwindowCursor.mnemonic=C -################# -# Map Validation - -Validator.TilePaths.title=Tile path invalid -Validator.TilePaths.msg=<html><h3>{0}</h3><p>This map has invalid tile paths.<br>Go to the map properties dialog and change the map tile paths. - - ####################### # Various Log Messages logDuplicateAnimation=Duplicate Animation: {0} Modified: trunk/daimonin/src/daieditor/messages_de.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_de.properties 2008-10-19 08:47:40 UTC (rev 5564) +++ trunk/daimonin/src/daieditor/messages_de.properties 2008-10-19 18:31:34 UTC (rev 5565) @@ -172,10 +172,3 @@ mapwindowCursor.text=Cursor mapwindowCursor.mnemonic=C - - -################# -# Map Validation - -#Validator.TilePaths.title= -#Validator.TilePaths.msg= Modified: trunk/daimonin/src/daieditor/messages_fr.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_fr.properties 2008-10-19 08:47:40 UTC (rev 5564) +++ trunk/daimonin/src/daieditor/messages_fr.properties 2008-10-19 18:31:34 UTC (rev 5565) @@ -174,10 +174,3 @@ #mapwindowCursor.text= mapwindowCursor.mnemonic=U - - -################# -# Map Validation - -#Validator.TilePaths.title= -#Validator.TilePaths.msg= Modified: trunk/daimonin/src/daieditor/messages_sv.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_sv.properties 2008-10-19 08:47:40 UTC (rev 5564) +++ trunk/daimonin/src/daieditor/messages_sv.properties 2008-10-19 18:31:34 UTC (rev 5565) @@ -174,10 +174,3 @@ mapwindowCursor.text=Mark\xF6r mapwindowCursor.mnemonic=M - - -################# -# Map Validation - -#Validator.TilePaths.title= -#Validator.TilePaths.msg= Copied: trunk/src/app/net/sf/gridarta/map/validation/checks/TilePathsChecker.java (from rev 5564, trunk/daimonin/src/daieditor/map/validation/checks/TilePathsChecker.java) =================================================================== --- trunk/src/app/net/sf/gridarta/map/validation/checks/TilePathsChecker.java (rev 0) +++ trunk/src/app/net/sf/gridarta/map/validation/checks/TilePathsChecker.java 2008-10-19 18:31:34 UTC (rev 5565) @@ -0,0 +1,78 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.map.validation.checks; + +import java.io.File; +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.MapModel; +import net.sf.gridarta.map.validation.AbstractValidator; +import net.sf.gridarta.map.validation.ErrorCollector; +import net.sf.gridarta.map.validation.MapValidator; +import org.jetbrains.annotations.NotNull; + +/** + * Validator that checks whether all tile paths are valid. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @xxx contains some casting hacks that need to be removed. + */ +public class TilePathsChecker<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractValidator implements MapValidator<G, A, R> { + + /** The map directory to check. */ + @NotNull + private final File mapDirectory; + + /** + * The number of tile paths to check. + */ + private final int tilePaths; + + /** + * Create a TilePathsChecker. + * @param mapDirectory map directory to check against + * @param tilePaths the number of tile paths to check + */ + public TilePathsChecker(final File mapDirectory, final int tilePaths) { + this.mapDirectory = mapDirectory; + this.tilePaths = tilePaths; + } + + /** {@inheritDoc} */ + public void validate(final MapModel<G, A, R> mapModel, final ErrorCollector<G, A, R> errorCollector) { + for (int direction = 0; direction < tilePaths; direction++) { + final String path = mapModel.getMapArchObject().getTilePath(direction); + if (path.length() > 0) { + final File newfile; + if (path.startsWith(File.pathSeparator) || path.startsWith("/")) { + // we have an absolute path: + newfile = new File(mapDirectory.getAbsolutePath(), path.substring(1)); + } else { + // we have a relative path: + newfile = new File(mapModel.getMapControl().getMapFile().getParent(), path); + } + if (!newfile.exists() || newfile.isDirectory()) { + errorCollector.collect(new TilePathsError<G, A, R>(mapModel, path)); + } + } + } + } + +} // class TilePathsChecker Property changes on: trunk/src/app/net/sf/gridarta/map/validation/checks/TilePathsChecker.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Copied: trunk/src/app/net/sf/gridarta/map/validation/checks/TilePathsError.java (from rev 5564, trunk/daimonin/src/daieditor/map/validation/checks/TilePathsError.java) =================================================================== --- trunk/src/app/net/sf/gridarta/map/validation/checks/TilePathsError.java (rev 0) +++ trunk/src/app/net/sf/gridarta/map/validation/checks/TilePathsError.java 2008-10-19 18:31:34 UTC (rev 5565) @@ -0,0 +1,55 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.map.validation.checks; + +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.MapModel; +import net.sf.gridarta.map.validation.MapValidationError; + +/** + * Validation error that's used when a map has wrong tile paths. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class TilePathsError<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends MapValidationError<G, A, R> { + + /** The tile path that was wrong. */ + private final String tilePath; + + /** + * Create a MapValidationError. + * @param mapModel the map on which the error occurred + * @param tilePath tile path which was wrong + */ + public TilePathsError(final MapModel<G, A, R> mapModel, final String tilePath) { + super(mapModel); + this.tilePath = tilePath; + } + + /** + * Returns the tile path that was wrong. + * @return the tile path that was wrong. + */ + public String getTilePath() { + return tilePath; + } + +} // class TilePathsError Property changes on: trunk/src/app/net/sf/gridarta/map/validation/checks/TilePathsError.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2008-10-19 08:47:40 UTC (rev 5564) +++ trunk/src/app/net/sf/gridarta/messages.properties 2008-10-19 18:31:34 UTC (rev 5565) @@ -937,6 +937,7 @@ prefs.Validator.Slaying=Whether this map validator check is is enabled. prefs.Validator.SquareWithoutFloor=Whether this map validator check is is enabled. prefs.Validator.SysObjectNotOnLayerZero=Whether this map validator check is is enabled. +prefs.Validator.TilePaths=Whether this map validator check is is enabled. prefs.Validator.UndefinedArchetype=Whether this map validator check is is enabled. prefs.Validator.UnsetSlaying=Whether this map validator check is is enabled. prefs.WindowState=Main windows''s state (maximized, iconized, etc.) @@ -1107,6 +1108,10 @@ Validator.SysObjectNotOnLayerZero.title=System object not on layer zero Validator.SysObjectNotOnLayerZero.msg=<html><h3>{0}</h3><p>This arch object is a system object.<br>System objects should always be in layer 0.<br>But this system object is in another layer.</p><p>You could:</p><ul><li>Ignore this</li><li>Change this arch object''s layer to 0</li></ul> +Validator.TilePaths.default=true +Validator.TilePaths.title=Tile path invalid +Validator.TilePaths.msg=<html><h3>{0}</h3><p>This map has invalid tile paths.<br>Go to the map properties dialog and change the map tile paths. + Validator.UndefinedArchetype.default=true Validator.UndefinedArchetype.title=Undefined archetype Validator.UndefinedArchetype.msg=<html><h3>{0}</h3><p>This object references an undefined archetype.<br>Every object is created by copying an archetype.<br>If this archetype does not exist the object cannot be created by the server.</p><p>You could:</p><ul><li>Remove the object</li></ul> Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2008-10-19 08:47:40 UTC (rev 5564) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2008-10-19 18:31:34 UTC (rev 5565) @@ -956,6 +956,9 @@ Validator.SysObjectNotOnLayerZero.title=System-Objekt nicht auf Ebene Null Validator.SysObjectNotOnLayerZero.msg=<html><h3>{0}</h3><p>Dieses Objekt ist ein System-Objekt.<br>System-Objekte sollten immer in Ebene Null liegen,<br>aber dieses Objekt ist in einer anderen Ebene.</p><p>Sie k\xF6nnen:</p><ul><li>Dieses Problem ignorieren</li><li>Die Ebene des System-Objekt auf Null setzen</li></ul> +Validator.TilePaths.title=\xDCng\xFCltiger Kartenverbindungspfad +Validator.TilePaths.msg=<html><h3>{0}</h3><p>Diese Karte besitzt einen ung\xFCltigen Kartenverbindungspfad.<br>\xC4ndern Sie den Kartenverbindungspfad in den Karteneigenschaften. + Validator.UndefinedArchetype.title=Ung\xFCltiger Archetyp Validator.UndefinedArchetype.msg=<html><h3>{0}</h3><p>Dieses Objekt verwendet ein Archetyp, der nicht existiert.<br>Der Server erzeugt Objekte als Kopie von Archetypen.<br>Daher ist es nicht m\xF6glich, einen nicht-vohandenen Archetypen zu verwenden.</p><p>Sie k\xF6nnen:</p><ul><li>Das Objekt l\xF6schen</li></ul> Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-10-19 08:47:40 UTC (rev 5564) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-10-19 18:31:34 UTC (rev 5565) @@ -955,6 +955,9 @@ #Validator.SysObjectOnLayerZero.title= #Validator.SysObjectOnLayerZero.msg= +#Validator.TilePaths.title= +#Validator.TilePaths.msg= + #Validator.UndefinedArchetype.title= #Validator.UndefinedArchetype.msg= Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-10-19 08:47:40 UTC (rev 5564) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-10-19 18:31:34 UTC (rev 5565) @@ -960,6 +960,9 @@ Validator.SysObjectNotOnLayerZero.title=Systemobjekt utanf\xF6r lager noll Validator.SysObjectNotOnLayerZero.msg=<html><h3>{0}</h3><p>Detta \xE4r ett systemobjekt.<br>Systemobjekt ska alltid vara i lager 0,<br>men det h\xE4r objektet \xE4r i ett annat lager.</p><p>Du kan:</p><ul><li>ignorera detta</li><li>\xE4ndra objektets lager till 0.</li></ul> +#Validator.TilePaths.title= +#Validator.TilePaths.msg= + #Validator.UndefinedArchetype.title= #Validator.UndefinedArchetype.msg= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 20:03:22
|
Revision: 5568 http://gridarta.svn.sourceforge.net/gridarta/?rev=5568&view=rev Author: akirschbaum Date: 2008-10-19 20:03:16 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Make SlayingChecker more flexible. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java trunk/src/app/net/sf/gridarta/AbstractMainControl.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-19 19:41:41 UTC (rev 5567) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-19 20:03:16 UTC (rev 5568) @@ -61,6 +61,7 @@ import net.sf.gridarta.gameobject.face.FaceObjectProviders; import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.gameobject.match.GameObjectMatcher; +import net.sf.gridarta.gameobject.match.GameObjectMatchers; import net.sf.gridarta.gameobject.scripts.DefaultScriptArchData; import net.sf.gridarta.gameobject.scripts.DefaultScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptArchData; @@ -288,7 +289,7 @@ /** {@inheritDoc} */ @NotNull @Override - protected DelegatingMapValidator<GameObject, MapArchObject, Archetype> createMapValidators(@NotNull final GlobalSettings globalSettings) { + protected DelegatingMapValidator<GameObject, MapArchObject, Archetype> createMapValidators(@NotNull final GlobalSettings globalSettings, @NotNull final GameObjectMatchers gameObjectMatchers) { final DelegatingMapValidator<GameObject, MapArchObject, Archetype> mapValidators = new DelegatingMapValidator<GameObject, MapArchObject, Archetype>(); final AttributeRangeChecker<GameObject, MapArchObject, Archetype> attributeRangeChecker = new AttributeRangeChecker<GameObject, MapArchObject, Archetype>(); // make sure sustenance is [-20..20]; amulet of Sustenance is +15 so +20 should be safe Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 19:41:41 UTC (rev 5567) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 20:03:16 UTC (rev 5568) @@ -64,6 +64,7 @@ import net.sf.gridarta.gameobject.face.FaceObjectProviders; import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.gameobject.match.GameObjectMatcher; +import net.sf.gridarta.gameobject.match.GameObjectMatchers; import net.sf.gridarta.gameobject.match.MutableOrGameObjectMatcher; import net.sf.gridarta.gameobject.match.ViewGameObjectMatcherManager; import net.sf.gridarta.gameobject.scripts.DefaultScriptArchData; @@ -357,10 +358,13 @@ /** {@inheritDoc} */ @NotNull @Override - protected DelegatingMapValidator<GameObject, MapArchObject, Archetype> createMapValidators(@NotNull final GlobalSettings globalSettings) { + protected DelegatingMapValidator<GameObject, MapArchObject, Archetype> createMapValidators(@NotNull final GlobalSettings globalSettings, @NotNull final GameObjectMatchers gameObjectMatchers) { final DelegatingMapValidator<GameObject, MapArchObject, Archetype> mapValidators = new DelegatingMapValidator<GameObject, MapArchObject, Archetype>(); final CustomTypeChecker<GameObject, MapArchObject, Archetype> customTypeChecker = new CustomTypeChecker<GameObject, MapArchObject, Archetype>(); customTypeChecker.addIgnore(Archetype.TYPE_MOB, Archetype.TYPE_SPAWN_POINT_MOB, Archetype.TYPE_SPAWN_POINT); + final SlayingChecker<GameObject, MapArchObject, Archetype> slayingChecker = new SlayingChecker<GameObject, MapArchObject, Archetype>(); + final GameObjectMatcher environmentSensorMatcher = gameObjectMatchers.getMatcherFatal("system_environment_sensor"); + slayingChecker.addMatcher(environmentSensorMatcher, Pattern.compile("|([0-1][0-9]|2[0-3]):[0-5][0-9]-([0-1][0-9]|2[0-3]):[0-5][0-9]")); mapValidators.add( new BlockedSpawnPointChecker<GameObject, MapArchObject, Archetype>(Archetype.TYPE_SPAWN_POINT), new BlockedMobOrSpawnPointChecker<GameObject, MapArchObject, Archetype>(Archetype.TYPE_MOB), @@ -409,7 +413,7 @@ new MapDifficultyChecker<GameObject, MapArchObject, Archetype>(), new MobOutsideSpawnPointChecker<GameObject, MapArchObject, Archetype>(Archetype.TYPE_MOB), new SquareWithoutFloorChecker<GameObject, MapArchObject, Archetype>(Archetype.TYPE_FLOOR, Archetype.TYPE_SHOP_FLOOR), - new SlayingChecker<GameObject, MapArchObject, Archetype>(), + slayingChecker, new SysObjectNotOnLayerZeroChecker<GameObject, MapArchObject, Archetype>(), new TilePathsChecker(globalSettings.getMapDir(), 8), new UndefinedArchetypeChecker<GameObject, MapArchObject, Archetype>(), Modified: trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java =================================================================== --- trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java 2008-10-19 19:41:41 UTC (rev 5567) +++ trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java 2008-10-19 20:03:16 UTC (rev 5568) @@ -19,42 +19,87 @@ package daieditor.map.validation.checks; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Pattern; import net.sf.gridarta.gameobject.Archetype; import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.map.MapArchObject; import net.sf.gridarta.map.validation.ErrorCollector; +import net.sf.gridarta.map.validation.GameObjectValidator; import net.sf.gridarta.map.validation.checks.EnvironmentSensorSlayingError; +import org.jetbrains.annotations.NotNull; /** - * An GameObjectValidator to assert that arch objects do not have critical - * slaying strings. This class adds checks for exceptional cases for Daimonin. + * A {@link GameObjectValidator} to assert that game objects do not have + * critical slaying strings. * @author Andreas Kirschbaum */ public class SlayingChecker<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends net.sf.gridarta.map.validation.checks.SlayingChecker<G, A, R> { - /** The pattern to match valid slaying values. */ - private static final Pattern pattern = Pattern.compile("|([0-1][0-9]|2[0-3]):[0-5][0-9]-([0-1][0-9]|2[0-3]):[0-5][0-9]"); + /** + * The matchers to check. + */ + private List<Entry<G, A, R>> entries = new ArrayList<Entry<G, A, R>>(); + /** + * Adds a matcher to check. + * @param gameObjectMatcher selects the game objects to check + * @param regex the allowed values of the "slaying" field + */ + public void addMatcher(@NotNull final GameObjectMatcher gameObjectMatcher, @NotNull final Pattern regex) { + entries.add(new Entry(gameObjectMatcher, regex)); + } + /** {@inheritDoc} */ @Override public void validate(final G gameObject, final ErrorCollector<G, A, R> errorCollector) { - switch (gameObject.getTypeNo()) { - case daieditor.gameobject.Archetype.TYPE_ENVIRONMENT_SENSOR: - final String slaying = gameObject.getAttributeString("slaying", true); - if (!pattern.matcher(slaying).matches()) { - errorCollector.collect(new EnvironmentSensorSlayingError<G, A, R>(gameObject)); - } - break; + for (final Entry<G, A, R> entry : entries) { + entry.validate(gameObject, errorCollector); + } + } - case daieditor.gameobject.Archetype.TYPE_EVENT_OBJECT: - // any value is allowed for now - break; + /** + * An entry to match consiting of a {@link GameObjectMatcher} and a regular + * expression which defined the allowed value of the "slaying" field. + */ + private static class Entry<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { - default: - super.validate(gameObject, errorCollector); - break; + /** + * Selects the game objects to check. + */ + private final GameObjectMatcher gameObjectMatcher; + + /** + * The allowed values of the "slaying" field. + */ + private final Pattern regex; + + /** + * Creates a new instance. + * @param gameObjectMatcher selects the game objects to check + * @param regex the allowed values of the "slaying" field + */ + public Entry(@NotNull final GameObjectMatcher gameObjectMatcher, @NotNull final Pattern regex) { + this.gameObjectMatcher = gameObjectMatcher; + this.regex = regex; } - } + /** + * Validates one {@link GameObject} instance. + * @param gameObject the game object instance + * @param errorCollector the error collector to use + */ + public void validate(final G gameObject, final ErrorCollector<G, A, R> errorCollector) { + if (gameObjectMatcher.isMatching(gameObject)) { + final String slaying = gameObject.getAttributeString("slaying", true); + if (!regex.matcher(slaying).matches()) { + errorCollector.collect(new EnvironmentSensorSlayingError<G, A, R>(gameObject)); + } + } + } + + } // class Entry + } // class SlayingChecker Modified: trunk/src/app/net/sf/gridarta/AbstractMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-19 19:41:41 UTC (rev 5567) +++ trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-19 20:03:16 UTC (rev 5568) @@ -376,10 +376,8 @@ final SelectedSquareControl<G, A, R, V> selectedSquareControl = new SelectedSquareControl<G, A, R, V>(ACTION_FACTORY, gameObjectAttributesDialogFactory, objectChooser, mapManager, mapViewManager, editTypes, mapTileListBottom, compassIcon, archetypeSet); final SelectedSquareView<G, A, R, V> selectedSquareView = selectedSquareControl.getSelectedSquareView(); new MapCursorActions<G, A, R, V>(key, gameObjectAttributesDialogFactory, mapViewManager, selectedSquareControl, selectedSquareView); - validators = createMapValidators(globalSettings); final CopyBuffer<G, A, R, V> copyBuffer = new CopyBuffer<G, A, R, V>(editTypes, mapControlFactory); final ReplaceDialogManager<G, A, R, V> replaceDialogManager = new ReplaceDialogManager<G, A, R, V>(mainView, archetypeSet, copyBuffer, objectChooser, mapViewManager); - mainActions = new MainActions<G, A, R, V>(replaceDialogManager, this, mainView, globalSettings, validators, editTypes, archetypeSet, copyBuffer, animationObjects, ACTION_FACTORY, faceObjects, objectChooser, mapManager, mapViewManager); new About(key, mainView); new UndoControl<G, A, R, V>(mapManager); final UpdaterManager updaterManager = new UpdaterManager(key, this, mapManager, mainView, gridartaJarFilename); @@ -407,6 +405,8 @@ } catch (final IOException ex) { log.error("Cannot read GameObjectMatchers.xml: " + ex.getMessage()); } + validators = createMapValidators(globalSettings, gameObjectMatchers); + mainActions = new MainActions<G, A, R, V>(replaceDialogManager, this, mainView, globalSettings, validators, editTypes, archetypeSet, copyBuffer, animationObjects, ACTION_FACTORY, faceObjects, objectChooser, mapManager, mapViewManager); final GameObjectMatcher floorMatcher = gameObjectMatchers.getMatcher("system_floor", "floor"); final GameObjectMatcher wallMatcher = gameObjectMatchers.getMatcher("system_wall", "wall"); final GameObjectMatcher monsterMatcher = gameObjectMatchers.getMatcherFatal("system_monster", "monster"); @@ -556,10 +556,11 @@ /** * Initializes the map validators. * @param globalSettings the global settings instance + * @param gameObjectMatchers the defined game object machers * @return A MapValidator that delegates to other map validators. */ @NotNull - protected abstract DelegatingMapValidator<G, A, R> createMapValidators(@NotNull final GlobalSettings globalSettings); + protected abstract DelegatingMapValidator<G, A, R> createMapValidators(@NotNull final GlobalSettings globalSettings, @NotNull final GameObjectMatchers gameObjectMatchers); /** * Creates a new {@link NewMapDialogFactory} instance. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 20:12:40
|
Revision: 5569 http://gridarta.svn.sourceforge.net/gridarta/?rev=5569&view=rev Author: akirschbaum Date: 2008-10-19 20:12:38 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Make SlayingChecker more flexible. Modified Paths: -------------- trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java trunk/src/app/net/sf/gridarta/map/validation/checks/SlayingChecker.java Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 20:03:16 UTC (rev 5568) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-19 20:12:38 UTC (rev 5569) @@ -362,7 +362,7 @@ final DelegatingMapValidator<GameObject, MapArchObject, Archetype> mapValidators = new DelegatingMapValidator<GameObject, MapArchObject, Archetype>(); final CustomTypeChecker<GameObject, MapArchObject, Archetype> customTypeChecker = new CustomTypeChecker<GameObject, MapArchObject, Archetype>(); customTypeChecker.addIgnore(Archetype.TYPE_MOB, Archetype.TYPE_SPAWN_POINT_MOB, Archetype.TYPE_SPAWN_POINT); - final SlayingChecker<GameObject, MapArchObject, Archetype> slayingChecker = new SlayingChecker<GameObject, MapArchObject, Archetype>(); + final SlayingChecker<GameObject, MapArchObject, Archetype> slayingChecker = new SlayingChecker<GameObject, MapArchObject, Archetype>(Pattern.compile("^[a-zA-Z_0-9/.]*$")); final GameObjectMatcher environmentSensorMatcher = gameObjectMatchers.getMatcherFatal("system_environment_sensor"); slayingChecker.addMatcher(environmentSensorMatcher, Pattern.compile("|([0-1][0-9]|2[0-3]):[0-5][0-9]-([0-1][0-9]|2[0-3]):[0-5][0-9]")); mapValidators.add( Modified: trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java =================================================================== --- trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java 2008-10-19 20:03:16 UTC (rev 5568) +++ trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java 2008-10-19 20:12:38 UTC (rev 5569) @@ -44,6 +44,15 @@ private List<Entry<G, A, R>> entries = new ArrayList<Entry<G, A, R>>(); /** + * Creates a new instance. + * @param defaultRegex the regular expression for any "slaying" field not + * matching any specific game object + */ + public SlayingChecker(@NotNull final Pattern defaultRegex) { + super(defaultRegex); + } + + /** * Adds a matcher to check. * @param gameObjectMatcher selects the game objects to check * @param regex the allowed values of the "slaying" field Modified: trunk/src/app/net/sf/gridarta/map/validation/checks/SlayingChecker.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/validation/checks/SlayingChecker.java 2008-10-19 20:03:16 UTC (rev 5568) +++ trunk/src/app/net/sf/gridarta/map/validation/checks/SlayingChecker.java 2008-10-19 20:12:38 UTC (rev 5569) @@ -19,12 +19,14 @@ package net.sf.gridarta.map.validation.checks; +import java.util.regex.Pattern; import net.sf.gridarta.gameobject.Archetype; import net.sf.gridarta.gameobject.GameObject; import net.sf.gridarta.map.MapArchObject; import net.sf.gridarta.map.validation.AbstractValidator; import net.sf.gridarta.map.validation.ErrorCollector; import net.sf.gridarta.map.validation.GameObjectValidator; +import org.jetbrains.annotations.NotNull; /** * An GameObjectValidator to assert that arch objects do not have critical @@ -33,10 +35,25 @@ */ public class SlayingChecker<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractValidator implements GameObjectValidator<G, A, R> { + /** + * The regular expression for any "slaying" field not matching any specific + * game object. + */ + private final Pattern defaultRegex; + + /** + * Creates a new instance. + * @param defaultRegex the regular expression for any "slaying" field not + * matching any specific game object + */ + public SlayingChecker(@NotNull final Pattern defaultRegex) { + this.defaultRegex = defaultRegex; + } + /** {@inheritDoc} */ public void validate(final G gameObject, final ErrorCollector<G, A, R> errorCollector) { final String slaying = gameObject.getAttributeString("slaying", true); - if (!slaying.matches("^[a-zA-Z_0-9/.]*$")) { + if (!defaultRegex.matcher(slaying).matches()) { errorCollector.collect(new SlayingError<G, A, R>(gameObject)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-19 20:17:10
|
Revision: 5570 http://gridarta.svn.sourceforge.net/gridarta/?rev=5570&view=rev Author: akirschbaum Date: 2008-10-19 20:17:00 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Move code from SlayingChecker to common code base. Modified Paths: -------------- trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java trunk/src/app/net/sf/gridarta/map/validation/checks/SlayingChecker.java Modified: trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java =================================================================== --- trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java 2008-10-19 20:12:38 UTC (rev 5569) +++ trunk/daimonin/src/daieditor/map/validation/checks/SlayingChecker.java 2008-10-19 20:17:00 UTC (rev 5570) @@ -19,16 +19,11 @@ package daieditor.map.validation.checks; -import java.util.ArrayList; -import java.util.List; import java.util.regex.Pattern; import net.sf.gridarta.gameobject.Archetype; import net.sf.gridarta.gameobject.GameObject; -import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.map.MapArchObject; -import net.sf.gridarta.map.validation.ErrorCollector; import net.sf.gridarta.map.validation.GameObjectValidator; -import net.sf.gridarta.map.validation.checks.EnvironmentSensorSlayingError; import org.jetbrains.annotations.NotNull; /** @@ -39,11 +34,6 @@ public class SlayingChecker<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends net.sf.gridarta.map.validation.checks.SlayingChecker<G, A, R> { /** - * The matchers to check. - */ - private List<Entry<G, A, R>> entries = new ArrayList<Entry<G, A, R>>(); - - /** * Creates a new instance. * @param defaultRegex the regular expression for any "slaying" field not * matching any specific game object @@ -52,63 +42,4 @@ super(defaultRegex); } - /** - * Adds a matcher to check. - * @param gameObjectMatcher selects the game objects to check - * @param regex the allowed values of the "slaying" field - */ - public void addMatcher(@NotNull final GameObjectMatcher gameObjectMatcher, @NotNull final Pattern regex) { - entries.add(new Entry(gameObjectMatcher, regex)); - } - - /** {@inheritDoc} */ - @Override - public void validate(final G gameObject, final ErrorCollector<G, A, R> errorCollector) { - for (final Entry<G, A, R> entry : entries) { - entry.validate(gameObject, errorCollector); - } - } - - /** - * An entry to match consiting of a {@link GameObjectMatcher} and a regular - * expression which defined the allowed value of the "slaying" field. - */ - private static class Entry<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { - - /** - * Selects the game objects to check. - */ - private final GameObjectMatcher gameObjectMatcher; - - /** - * The allowed values of the "slaying" field. - */ - private final Pattern regex; - - /** - * Creates a new instance. - * @param gameObjectMatcher selects the game objects to check - * @param regex the allowed values of the "slaying" field - */ - public Entry(@NotNull final GameObjectMatcher gameObjectMatcher, @NotNull final Pattern regex) { - this.gameObjectMatcher = gameObjectMatcher; - this.regex = regex; - } - - /** - * Validates one {@link GameObject} instance. - * @param gameObject the game object instance - * @param errorCollector the error collector to use - */ - public void validate(final G gameObject, final ErrorCollector<G, A, R> errorCollector) { - if (gameObjectMatcher.isMatching(gameObject)) { - final String slaying = gameObject.getAttributeString("slaying", true); - if (!regex.matcher(slaying).matches()) { - errorCollector.collect(new EnvironmentSensorSlayingError<G, A, R>(gameObject)); - } - } - } - - } // class Entry - } // class SlayingChecker Modified: trunk/src/app/net/sf/gridarta/map/validation/checks/SlayingChecker.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/validation/checks/SlayingChecker.java 2008-10-19 20:12:38 UTC (rev 5569) +++ trunk/src/app/net/sf/gridarta/map/validation/checks/SlayingChecker.java 2008-10-19 20:17:00 UTC (rev 5570) @@ -19,9 +19,12 @@ package net.sf.gridarta.map.validation.checks; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Pattern; import net.sf.gridarta.gameobject.Archetype; import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.map.MapArchObject; import net.sf.gridarta.map.validation.AbstractValidator; import net.sf.gridarta.map.validation.ErrorCollector; @@ -42,6 +45,11 @@ private final Pattern defaultRegex; /** + * The matchers to check. + */ + private List<Entry<G, A, R>> entries = new ArrayList<Entry<G, A, R>>(); + + /** * Creates a new instance. * @param defaultRegex the regular expression for any "slaying" field not * matching any specific game object @@ -50,12 +58,76 @@ this.defaultRegex = defaultRegex; } + /** + * Adds a matcher to check. + * @param gameObjectMatcher selects the game objects to check + * @param regex the allowed values of the "slaying" field + */ + public void addMatcher(@NotNull final GameObjectMatcher gameObjectMatcher, @NotNull final Pattern regex) { + entries.add(new Entry(gameObjectMatcher, regex)); + } + /** {@inheritDoc} */ public void validate(final G gameObject, final ErrorCollector<G, A, R> errorCollector) { - final String slaying = gameObject.getAttributeString("slaying", true); - if (!defaultRegex.matcher(slaying).matches()) { - errorCollector.collect(new SlayingError<G, A, R>(gameObject)); + boolean useDefaultRegex = true; + for (final Entry<G, A, R> entry : entries) { + if (entry.validate(gameObject, errorCollector)) { + useDefaultRegex = false; + } } + + if (useDefaultRegex) { + final String slaying = gameObject.getAttributeString("slaying", true); + if (!defaultRegex.matcher(slaying).matches()) { + errorCollector.collect(new SlayingError<G, A, R>(gameObject)); + } + } } + /** + * An entry to match consiting of a {@link GameObjectMatcher} and a regular + * expression which defined the allowed value of the "slaying" field. + */ + private static class Entry<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { + + /** + * Selects the game objects to check. + */ + private final GameObjectMatcher gameObjectMatcher; + + /** + * The allowed values of the "slaying" field. + */ + private final Pattern regex; + + /** + * Creates a new instance. + * @param gameObjectMatcher selects the game objects to check + * @param regex the allowed values of the "slaying" field + */ + public Entry(@NotNull final GameObjectMatcher gameObjectMatcher, @NotNull final Pattern regex) { + this.gameObjectMatcher = gameObjectMatcher; + this.regex = regex; + } + + /** + * Validates one {@link GameObject} instance. + * @param gameObject the game object instance + * @param errorCollector the error collector to use + * @return whether the game object did match + */ + public boolean validate(final G gameObject, final ErrorCollector<G, A, R> errorCollector) { + if (!gameObjectMatcher.isMatching(gameObject)) { + return false; + } + + final String slaying = gameObject.getAttributeString("slaying", true); + if (!regex.matcher(slaying).matches()) { + errorCollector.collect(new EnvironmentSensorSlayingError<G, A, R>(gameObject)); + } + return true; + } + + } // class Entry + } // class SlayingChecker This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |