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