Skip to content

Instantly share code, notes, and snippets.

@stubb
Created June 26, 2011 22:03
Show Gist options
  • Save stubb/1048043 to your computer and use it in GitHub Desktop.
Save stubb/1048043 to your computer and use it in GitHub Desktop.
patch for UH to get fife 0.3.3 compatibility
Index: ambientsound.py
===================================================================
--- ambientsound.py (revision 7764)
+++ ambientsound.py (working copy)
@@ -69,7 +69,7 @@
# set to current position
if(hasattr(self, 'position') and self.position != None and self.__positioning):
self.__emitter.setPosition(self.position.center().x, self.position.center().y, 1)
- self.__emitter.setSoundClip(horizons.main.fife.soundclippool.addResourceFromFile(soundfile))
+ self.__emitter.setSoundClip(horizons.main.fife.soundclipmanager.load(soundfile).getHandle())
if play_every is None:
self.__emitter.setLooping(looping)
elif looping and play_every is not None:
Index: engine.py
===================================================================
--- engine.py (revision 7764)
+++ engine.py (working copy)
@@ -67,6 +67,10 @@
self.engine = fife.Engine()
self.engine_settings = self.engine.getSettings()
+ logToPrompt, logToFile, debugPychan = True, True, False
+ self._log = fifelog.LogManager(self.engine, 1 if logToPrompt else 0, 1 if logToFile else 0)
+
+
self.loadSettings()
self.pychan = pychan
@@ -142,9 +146,9 @@
"1680x1050","1920x1080","1920x1200",] # Add more supported resolutions here.
current_state = self.engine_settings.isFullScreen()
self.engine_settings.setFullScreen(1)
- for x,y in self.engine_settings.getPossibleResolutions():
- if x >= 1024 and y >= 768 and str(x) + "x" + str(y) not in possible_resolutions:
- possible_resolutions.append(str(x) + "x" + str(y))
+# for x,y in self.engine_settings.getPossibleResolutions():
+# if x >= 1024 and y >= 768 and str(x) + "x" + str(y) not in possible_resolutions:
+# possible_resolutions.append(str(x) + "x" + str(y))
self.engine_settings.setFullScreen(current_state)
self._setting.entries[FIFE_MODULE]['ScreenResolution'].initialdata = possible_resolutions
@@ -228,16 +232,16 @@
self.soundmanager = self.engine.getSoundManager()
self.soundmanager.init()
self.setup_sound()
- self.imagepool = self.engine.getImagePool()
- self.animationpool = self.engine.getAnimationPool()
+ self.imagemanager = self.engine.getImageManager()
+# self.animationpool = self.engine.getAnimationPool()
self.animationloader = SQLiteAnimationLoader()
- self.animationpool.addResourceLoader(self.animationloader)
+# self.animationpool.addResourceLoader(self.animationloader)
#Set game cursor
self.cursor = self.engine.getCursor()
- self.default_cursor_image = self.imagepool.addResourceFromFile('content/gui/images/cursors/cursor.png')
- self.tearing_cursor_image = self.imagepool.addResourceFromFile('content/gui/images/cursors/cursor_tear.png')
- self.cursor.set(fife.CURSOR_IMAGE, self.default_cursor_image)
+ self.default_cursor_image = self.imagemanager.load('content/gui/images/cursors/cursor.png')
+ self.tearing_cursor_image = self.imagemanager.load('content/gui/images/cursors/cursor_tear.png')
+ self.cursor.set(self.default_cursor_image)
#init pychan
self.pychan.init(self.engine, debugPychan)
@@ -321,7 +325,7 @@
def enable_sound(self):
"""Enable all sound and start playing music."""
if self._setting.get(FIFE_MODULE, "PlaySounds"): # Set up sound if it is enabled
- self.soundclippool = self.engine.getSoundClipPool()
+ self.soundclipmanager = self.engine.getSoundClipManager()
self.emitter['bgsound'] = self.soundmanager.createEmitter()
self.emitter['bgsound'].setGain(self._setting.get(UH_MODULE, "VolumeMusic"))
self.emitter['bgsound'].setLooping(False)
@@ -382,7 +386,7 @@
assert emitter is not None, "You need to supply a initialised emitter"
assert soundfile is not None, "You need to supply a soundfile"
emitter.reset()
- emitter.setSoundClip(horizons.main.fife.soundclippool.addResourceFromFile(soundfile))
+ emitter.setSoundClip(horizons.main.fife.soundclipmanager.load(soundfile).getHandle())
emitter.play()
def set_volume(self, emitter_name, value):
Index: gui/mousetools/selectiontool.py
===================================================================
--- gui/mousetools/selectiontool.py (revision 7764)
+++ gui/mousetools/selectiontool.py (working copy)
@@ -48,13 +48,13 @@
d = fife.Point(min(self.select_begin[0], evt.getX()), \
max(self.select_begin[1], evt.getY()))
self.session.view.renderer['GenericRenderer'].addLine("select", \
- fife.GenericRendererNode(a), fife.GenericRendererNode(b), 200, 200, 200)
+ fife.RendererNode(a), fife.RendererNode(b), 200, 200, 200)
self.session.view.renderer['GenericRenderer'].addLine("select", \
- fife.GenericRendererNode(b), fife.GenericRendererNode(c), 200, 200, 200)
+ fife.RendererNode(b), fife.RendererNode(c), 200, 200, 200)
self.session.view.renderer['GenericRenderer'].addLine("select", \
- fife.GenericRendererNode(d), fife.GenericRendererNode(c), 200, 200, 200)
+ fife.RendererNode(d), fife.RendererNode(c), 200, 200, 200)
self.session.view.renderer['GenericRenderer'].addLine("select", \
- fife.GenericRendererNode(a), fife.GenericRendererNode(d), 200, 200, 200)
+ fife.RendererNode(a), fife.RendererNode(d), 200, 200, 200)
selectable = []
instances = self.session.view.cam.getMatchingInstances(\
fife.Rect(min(self.select_begin[0], evt.getX()), \
Index: gui/mousetools/tearingtool.py
===================================================================
--- gui/mousetools/tearingtool.py (revision 7764)
+++ gui/mousetools/tearingtool.py (working copy)
@@ -42,11 +42,11 @@
self.oldedges = None
self.tear_tool_active = True
self.session.gui.on_escape = self.on_escape
- horizons.main.fife.cursor.set(fife.CURSOR_IMAGE, horizons.main.fife.tearing_cursor_image)
+ horizons.main.fife.cursor.set(horizons.main.fife.tearing_cursor_image)
def end(self):
self.tear_tool_active = False
- horizons.main.fife.cursor.set(fife.CURSOR_IMAGE, horizons.main.fife.default_cursor_image)
+ horizons.main.fife.cursor.set(horizons.main.fife.default_cursor_image)
super(TearingTool, self).end()
def mouseDragged(self, evt):
Index: gui/widgets/minimap.py
===================================================================
--- gui/widgets/minimap.py (revision 7764)
+++ gui/widgets/minimap.py (working copy)
@@ -51,7 +51,7 @@
# save all GenericRendererNodes here, so they don't need to be constructed multiple times
self.renderernodes = {}
# pull dereferencing out of loop
- GenericRendererNode = fife.GenericRendererNode
+ GenericRendererNode = fife.RendererNode
fife_Point = fife.Point
for i in self.location.tuple_iter():
self.renderernodes[ i ] = GenericRendererNode( fife_Point( *i ) )
@@ -107,7 +107,7 @@
corner[1] = self.world.min_y
corner = tuple(corner)
minimap_coords = self._get_rotated_coords( self._world_coord_to_minimap_coord(corner))
- minimap_corners_as_renderer_node.append( fife.GenericRendererNode( \
+ minimap_corners_as_renderer_node.append( fife.RendererNode( \
fife.Point(*minimap_coords) ) )
for i in xrange(0, 3):
self.renderer.addLine("minimap_cam_border", minimap_corners_as_renderer_node[i], \
Index: main.py
===================================================================
--- main.py (revision 7764)
+++ main.py (working copy)
@@ -181,7 +181,7 @@
# remove cursor while loading
fife.cursor.set(fife_module.CURSOR_NONE)
fife.engine.pump()
- fife.cursor.set(fife_module.CURSOR_IMAGE, fife.default_cursor_image)
+ fife.cursor.set(fife.default_cursor_image)
# hide whatever is displayed before the game starts
_modules.gui.hide()
@@ -219,7 +219,7 @@
# remove cursor while loading
fife.cursor.set(fife_module.CURSOR_NONE)
fife.engine.pump()
- fife.cursor.set(fife_module.CURSOR_IMAGE, fife.default_cursor_image)
+ fife.cursor.set(fife.default_cursor_image)
# hide whatever is displayed before the game starts
_modules.gui.hide()
Index: util/sqliteanimationloader.py
===================================================================
--- util/sqliteanimationloader.py (revision 7764)
+++ util/sqliteanimationloader.py (working copy)
@@ -25,11 +25,10 @@
from horizons.util import ActionSetLoader
-class SQLiteAnimationLoader(fife.ResourceLoader):
+class SQLiteAnimationLoader(object):
"""Loads animations from a SQLite database.
"""
def __init__(self):
- super(SQLiteAnimationLoader, self).__init__()
self.thisown = 0
def loadResource(self, location):
@@ -44,17 +43,20 @@
- cut:
#TODO: complete documentation
"""
- commands = location.getFilename().split(':')
+ commands = location.split(':')
id = commands.pop(0)
actionset, action, rotation = id.split('-')
commands = zip(commands[0::2], commands[1::2])
- ani = fife.Animation()
+ ani = fife.SharedAnimationPointer()
+ _anim = fife.Animation()
+ _anim.thisown = 0
+ ani.reset(_anim)
+
frame_start, frame_end = 0.0, 0.0
for file in sorted(ActionSetLoader.get_action_sets()[actionset][action][int(rotation)].iterkeys()):
frame_end = ActionSetLoader.get_action_sets()[actionset][action][int(rotation)][file]
- idx = horizons.main.fife.imagepool.addResourceFromFile(file)
- img = horizons.main.fife.imagepool.getImage(idx)
+ img = horizons.main.fife.imagemanager.create(file)
for command, arg in commands:
if command == 'shift':
x, y = arg.split(',')
@@ -79,57 +81,10 @@
img.setXShift(x)
img.setYShift(y)
elif command == 'cut':
- loc = fife.ImageLocation('asdf')
- loc.setParentSource(img)
- x, y, w, h = arg.split(',')
-
- if x.startswith('left'):
- x = int(x[4:])
- elif x.startswith('right'):
- x = int(x[5:]) + img.getWidth()
- elif x.startswith(('center', 'middle')):
- x = int(x[6:]) + int(img.getWidth() / 2)
- else:
- x = int(x)
-
- if y.startswith('top'):
- y = int(y[3:])
- elif y.startswith('bottom'):
- y = int(y[6:]) - img.getHeight()
- elif y.startswith(('center', 'middle')):
- y = int(y[6:]) + int(img.getHeight() / 2)
- else:
- y = int(y)
-
- if w.startswith('left'):
- w = int(w[4:]) - x
- elif w.startswith('right'):
- w = int(w[5:]) + img.getWidth() - x
- elif w.startswith(('center', 'middle')):
- w = int(w[6:]) + int(img.getWidth() / 2) - x
- else:
- w = int(w)
-
- if h.startswith('top'):
- h = int(h[3:]) - y
- elif h.startswith('bottom'):
- h = int(h[6:]) + img.getHeight() - y
- elif h.startswith(('center', 'middle')):
- h = int(h[6:]) + int(img.getHeight() / 2) - y
- else:
- h = int(h)
-
- loc.setXShift(x)
- loc.setYShift(y)
- loc.setWidth(w)
- loc.setHeight(h)
-
- idx = horizons.main.fife.imagepool.addResourceFromLocation(loc)
- #img = horizons.main.fife.imagepool.getImage(idx)
- ani.addFrame(fife.ResourcePtr(horizons.main.fife.imagepool, idx), max(1, int((float(frame_end) - frame_start)*1000)))
+ #unused
+ pass
+
+ ani.addFrame(img, max(1, int((float(frame_end) - frame_start)*1000)))
frame_start = float(frame_end)
ani.setActionFrame(0)
- ani.thisown = 0
return ani
-
-
Index: world/building/__init__.py
===================================================================
--- world/building/__init__.py (revision 7764)
+++ world/building/__init__.py (working copy)
@@ -138,6 +138,6 @@
else:
assert False, "Bad rotation for action_set %(id)s: %(rotation)s for action: %(action_id)s" % \
{ 'id':action_set_id, 'rotation': rotation, 'action_id': action_id }
- anim_id = horizons.main.fife.animationpool.addResourceFromFile(str(action_set_id)+"-"+str(action_id)+"-"+str(rotation) + ':shift:' + command)
- action.get2dGfxVisual().addAnimation(int(rotation), anim_id)
- action.setDuration(horizons.main.fife.animationpool.getAnimation(anim_id).getDuration())
+ anim = horizons.main.fife.animationloader.loadResource(str(action_set_id)+"-"+str(action_id)+"-"+str(rotation) + ':shift:' + command)
+ action.get2dGfxVisual().addAnimation(int(rotation), anim)
+ action.setDuration(anim.getDuration())
Index: world/ground.py
===================================================================
--- world/ground.py (revision 7764)
+++ world/ground.py (working copy)
@@ -125,5 +125,5 @@
(SELECT file FROM data.animation WHERE animation_id = animation_315 LIMIT 1) \
FROM data.ground WHERE id = ?", self.id)[0]
for rotation, file in [(45, animation_45), (135, animation_135), (225, animation_225), (315, animation_315)]:
- img = horizons.main.fife.imagepool.addResourceFromFile(file)
- visual.addStaticImage(int(rotation), img)
+ img = horizons.main.fife.imagemanager.load(file)
+ visual.addStaticImage(int(rotation), img.getHandle())
Index: world/units/__init__.py
===================================================================
--- world/units/__init__.py (revision 7764)
+++ world/units/__init__.py (working copy)
@@ -84,8 +84,8 @@
action = cls._object.createAction(action_id+"_"+str(action_set_id))
fife.ActionVisual.create(action)
for rotation in action_sets[action_set_id][action_id].iterkeys():
- anim_id = horizons.main.fife.animationpool.addResourceFromFile( \
+ anim = horizons.main.fife.animationloader.loadResource( \
str(action_set_id)+"-"+str(action_id)+"-"+ \
str(rotation) + ':shift:center+0,bottom+8')
- action.get2dGfxVisual().addAnimation(int(rotation), anim_id)
- action.setDuration(horizons.main.fife.animationpool.getAnimation(anim_id).getDuration())
+ action.get2dGfxVisual().addAnimation(int(rotation), anim)
+ action.setDuration(anim.getDuration())
Index: world/units/ship.py
===================================================================
--- world/units/ship.py (revision 7764)
+++ world/units/ship.py (working copy)
@@ -176,8 +176,8 @@
coords.thisown = 1 # thisown = 1 because setLayerCoordinates will create a copy
loc.setLayerCoordinates(coords)
self.session.view.renderer['GenericRenderer'].addAnimation(
- "buoy_" + str(self.worldid), fife.GenericRendererNode(loc),
- horizons.main.fife.animationpool.addResourceFromFile("as_buoy0-idle-45")
+ "buoy_" + str(self.worldid), fife.RendererNode(loc),
+ horizons.main.fife.animationloader.loadResource("as_buoy0-idle-45")
)
self.draw_health()
if reset_cam:
@@ -232,8 +232,8 @@
coords.thisown = 0
loc.setLayerCoordinates(coords)
self.session.view.renderer['GenericRenderer'].addAnimation(
- "buoy_" + str(self.worldid), fife.GenericRendererNode(loc),
- horizons.main.fife.animationpool.addResourceFromFile("as_buoy0-idle-45")
+ "buoy_" + str(self.worldid), fife.RendererNode(loc),
+ horizons.main.fife.animationloader.loadResource("as_buoy0-idle-45")
)
def _possible_names(self):
Index: world/units/unit.py
===================================================================
--- world/units/unit.py (revision 7764)
+++ world/units/unit.py (working copy)
@@ -88,27 +88,27 @@
height = int(5 * zoom)
width = int(50 * zoom)
y_pos = int(self.health_bar_y * zoom)
- mid_node_up = fife.GenericRendererNode(self._instance, \
+ mid_node_up = fife.RendererNode(self._instance, \
fife.Point(-width/2+int(((self.health/self.max_health)*width)),\
y_pos-height)
)
- mid_node_down = fife.GenericRendererNode(self._instance, \
+ mid_node_down = fife.RendererNode(self._instance, \
fife.Point(
-width/2+int(((self.health/self.max_health)*width))
,y_pos)
)
if self.health != 0:
renderer.addQuad("health_" + str(self.worldid), \
- fife.GenericRendererNode(self._instance, \
+ fife.RendererNode(self._instance, \
fife.Point(-width/2, y_pos-height)), \
mid_node_up, \
mid_node_down, \
- fife.GenericRendererNode(self._instance, fife.Point(-width/2, y_pos)), \
+ fife.RendererNode(self._instance, fife.Point(-width/2, y_pos)), \
0, 255, 0)
if self.health != self.max_health:
renderer.addQuad("health_" + str(self.worldid), mid_node_up, \
- fife.GenericRendererNode(self._instance, fife.Point(width/2, y_pos-height)), \
- fife.GenericRendererNode(self._instance, fife.Point(width/2, y_pos)), \
+ fife.RendererNode(self._instance, fife.Point(width/2, y_pos-height)), \
+ fife.RendererNode(self._instance, fife.Point(width/2, y_pos)), \
mid_node_down, 255, 0, 0)
def hide(self):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment