Editor:Plugin format
This article is part of design documentation.
Design documentation describes how software is implemented or is about to be implemented. It focuses on system structure (e.g. dependencies), module interactions and relevant algorithms. Concepts described in these articles should form the terminology that is used when discussing about the software that forms FIFE.
Introduction
Goals
- Projects using FIFE should be able to use FIFedit in every stage of development
- No project should be forced to fork FIFedit to e.g. be able to also place triggers on the maps
- FIFedit should have basic functionality (opening / saving maps, placing / deleting / moving instances etc.) and allow plugins to do more with the selected instances / loaded maps / whatever else you might need for map creation.
This is all about workflow: Why you should write and maintain a customized editor if this can be avoided. Or: Why should you switch to a custom tool to place triggers, setup npc inventories, add player starting points, add map exit points etc...
Plugins for FIFedit can e.g. write data to own fileformats (sqlite, xml, other custom binarys) and are easier to maintain then a full featured (customized) editor suite. Plus, if major changes are made in FIFE, only one application has to be updated, and all projects are in sync again. (without spending hours to update their homebrewn tools)
Plugins and the editor
Plugins can use all the subsystems and features of the editor by accessing the Editor object.
Creating and activating plugins
- Create your python file in the editor's plugin directory (editor/plugins/)
- The filename must match exactly the name of the contained class. The filename is case-dependant. If your plugin has a plugin class named "MyPlugin", your python file must be called MyPlugin.py.
- Inherit scripts.plugin.Plugin and implement the abstract functions.
- Start the editor. Your plugin isn't enabled yet, so you must enable it.
- By running the editor, you updated the settings.xml file. To enable your plugin, you must edit this file.
- Open the settings.xml file and edit the setting called "MyPlugin" under the Plugins module. (This step won't be necessary once a tool for managing plugins are written)
Your settings.xml file is located in:
- ~/.fife/editor/settings.xml if you're on linux
- %APPDATA%\fife\editor if you're on windows
Interface
class Plugin: abstract function enable() abstract function disable() abstract function isEnabled() abstract function getName() function getAuthor() function getDescription() function getLicense() function getVersion()
Example
Untested code.
from scripts.plugin import Plugin
from pychan import widgets, tools
class MyPlugin(Plugin):
def __init__(self):
pass
#--- Plugin interface methods ---#
def enable(self, editor):
if self._enabled:
return
self.gui = tools.loadXML("gui/myplugin.xml")
showButton = self.gui.findChild(name="showButton")
hideButton = self.gui.findChild(name="hideButton")
showbutton.capture(self.showAllLayers)
hideButton.capture(self.hideAllLayers)
self._enabled = True
def disable(self, editor):
if self._enabled is False:
return
showButton = self.gui.findChild(name="showButton")
hideButton = self.gui.findChild(name="hideButton")
showbutton.capture(None)
hideButton.capture(None)
self.gui = None
self._enabled = False
def isEnabled(self):
return self._enabled
def getName(self):
return "My plugin"
# [...]
#--- Other methods ---#
def showAllLayers(self, event):
layers = self.editor.getEngine().getMap().getLayers()
for layer in layers:
layer.show()
def hideAllLayers(self, event):
layers = self.editor.getEngine().getMap().getLayers()
for layer in layers:
layer.hide()
# [...]