From: <aki...@us...> - 2007-01-10 22:04:35
|
Revision: 1548 http://svn.sourceforge.net/gridarta/?rev=1548&view=rev Author: akirschbaum Date: 2007-01-10 14:03:19 -0800 (Wed, 10 Jan 2007) Log Message: ----------- Unify code to create event game objects. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gameobject/scripts/ trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeException.java trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeNameException.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeException.java trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeNameException.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2007-01-10 21:47:05 UTC (rev 1547) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2007-01-10 22:03:19 UTC (rev 1548) @@ -33,6 +33,8 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.WindowConstants; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; Deleted: trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeException.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeException.java 2007-01-10 21:47:05 UTC (rev 1547) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeException.java 2007-01-10 22:03:19 UTC (rev 1548) @@ -1,45 +0,0 @@ -/* - * Gridarta Map Editor. - * Copyright (C) 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., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -package cfeditor.gameobject.scripts; - -import org.jetbrains.annotations.NotNull; - -/** - * The class <code>UndefinedEventArchetypeException</code> is thrown when an - * event game object cannot be created. - * - * @author Andreas Kirschbaum - */ -public abstract class UndefinedEventArchetypeException extends Exception { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** - * Create a new instance. - * - * @param msg the exception message - */ - public UndefinedEventArchetypeException(@NotNull final String msg) { - super(msg); - } - -} // class UndefinedEventArchetypeException Deleted: trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeNameException.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeNameException.java 2007-01-10 21:47:05 UTC (rev 1547) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeNameException.java 2007-01-10 22:03:19 UTC (rev 1548) @@ -1,60 +0,0 @@ -/* - * Gridarta Map Editor. - * Copyright (C) 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., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -package cfeditor.gameobject.scripts; - -import org.jetbrains.annotations.NotNull; - -/** - * This class implements an {@link UndefinedEventArchetypeException} that - * describes a missing archetype. - * - * @author Andreas Kirschbaum - */ -public class UndefinedEventArchetypeNameException extends UndefinedEventArchetypeException { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** - * The archetype that could not be found. - */ - @NotNull private final String archName; - - /** - * Create a new instance. - * - * @param archName the archetype that could not be found - */ - public UndefinedEventArchetypeNameException(@NotNull final String archName) { - super("undefined archetype " + archName); - this.archName = archName; - } - - /** - * Return the archetype that could not be found. - * - * @return the archetype that could not be found - */ - @NotNull public String getArchName() { - return archName; - } - -} // class UndefinedEventArchetypeNameException Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-10 21:47:05 UTC (rev 1547) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-10 22:03:19 UTC (rev 1548) @@ -52,6 +52,7 @@ import javax.swing.JTextField; import javax.swing.WindowConstants; import net.sf.gridarta.io.PathManager; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import net.sf.japi.util.Arrays2; @@ -485,7 +486,13 @@ if (newScriptFile.exists()) { if (newScriptFile.isFile()) { // file exists -> link it to the event - final ScriptedEvent event = new ScriptedEvent(eventType, pluginName, scriptPath, options); + final ScriptedEvent event; + try { + event = new ScriptedEvent(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 false; + } if (replaceObject != null) { replaceObject.remove(); } @@ -514,7 +521,13 @@ 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 = new ScriptedEvent(eventType, pluginName, scriptPath, options); + final ScriptedEvent event; + try { + event = new ScriptedEvent(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 false; + } if (replaceObject != null) { replaceObject.remove(); } Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2007-01-10 21:47:05 UTC (rev 1547) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2007-01-10 22:03:19 UTC (rev 1548) @@ -33,6 +33,8 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.WindowConstants; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; @@ -79,13 +81,9 @@ * @param scriptPath path to the file for this event * @param options options for this event */ - ScriptedEvent(final int eventType, final String pluginName, final String scriptPath, final String options) { - event = new GameObject(); // FIXME: This arch has no default arch - event.setArchTypNr(118); - event.setArchetypeName("event_obj"); - event.setArchetype(CMainControl.getInstance().getArchetypeSet().getArchetype("event_obj")); - event.setObjectFace(); - setEventData(eventType, pluginName, scriptPath, options); + ScriptedEvent(final int eventType, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { + event = newEventGameObject(eventType); + setEventData(pluginName, scriptPath, options); } /** @@ -112,7 +110,7 @@ scriptPath = scriptPath.replace('\\', '/'); // just make sure there are only slashes: '/' - setEventData(eventType, pluginName, scriptPath, options); + setEventData(pluginName, scriptPath, options); return true; } @@ -261,18 +259,18 @@ } public void setPluginName(final String pluginName) { - setEventData(getEventType(), pluginName, getScriptPath(), getOptions()); + setEventData(pluginName, getScriptPath(), getOptions()); } public void setScriptPath(final String scriptPath) { - setEventData(getEventType(), getPluginName(), scriptPath, getOptions()); + setEventData(getPluginName(), scriptPath, getOptions()); } public void setOptions(final String options) { - setEventData(getEventType(), getPluginName(), getScriptPath(), options); + setEventData(getPluginName(), getScriptPath(), options); } - private void setEventData(final int eventType, final String pluginName, final String scriptPath, final String options) { + private void setEventData(final String pluginName, final String scriptPath, final String options) { event.resetObjectText(); if (pluginName != null && pluginName.length() > 0) { event.setObjName(pluginName); @@ -283,7 +281,28 @@ 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 static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { + final String typeArchName = "event_obj"; + final GameObject eventArch = CMainControl.getInstance().getArchetypeSet().getArchetype(typeArchName); + if (eventArch == null) { + throw new UndefinedEventArchetypeNameException(typeArchName); + } + final GameObject event = eventArch.createArch(); event.addObjectText("sub_type " + eventType); + CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); + return event; } } // class ScriptedEvent Copied: trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeException.java (from rev 1544, trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeException.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeException.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeException.java 2007-01-10 22:03:19 UTC (rev 1548) @@ -0,0 +1,45 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package net.sf.gridarta.gameobject.scripts; + +import org.jetbrains.annotations.NotNull; + +/** + * The class <code>UndefinedEventArchetypeException</code> is thrown when an + * event game object cannot be created. + * + * @author Andreas Kirschbaum + */ +public abstract class UndefinedEventArchetypeException extends Exception { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** + * Create a new instance. + * + * @param msg the exception message + */ + public UndefinedEventArchetypeException(@NotNull final String msg) { + super(msg); + } + +} // class UndefinedEventArchetypeException Copied: trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeNameException.java (from rev 1544, trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeNameException.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeNameException.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeNameException.java 2007-01-10 22:03:19 UTC (rev 1548) @@ -0,0 +1,60 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package net.sf.gridarta.gameobject.scripts; + +import org.jetbrains.annotations.NotNull; + +/** + * This class implements an {@link UndefinedEventArchetypeException} that + * describes a missing archetype. + * + * @author Andreas Kirschbaum + */ +public class UndefinedEventArchetypeNameException extends UndefinedEventArchetypeException { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** + * The archetype that could not be found. + */ + @NotNull private final String archName; + + /** + * Create a new instance. + * + * @param archName the archetype that could not be found + */ + public UndefinedEventArchetypeNameException(@NotNull final String archName) { + super("undefined archetype " + archName); + this.archName = archName; + } + + /** + * Return the archetype that could not be found. + * + * @return the archetype that could not be found + */ + @NotNull public String getArchName() { + return archName; + } + +} // class UndefinedEventArchetypeNameException This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |