From c580c1fb3744142be001ae09cb343463ee6b98c1 Mon Sep 17 00:00:00 2001 From: jlew Date: Tue, 26 Oct 2010 19:14:49 +0000 Subject: Removed links to make windows devs happy --- diff --git a/MAFH2/Items.py b/MAFH2/Items.py index aedca8d..3c4cb20 120000..100644 --- a/MAFH2/Items.py +++ b/MAFH2/Items.py @@ -1 +1,112 @@ -../MAFH.activity/Items.py \ No newline at end of file +from gettext import gettext as _ + +class InvalidItemException(Exception): pass + +WEAPONS = { + '1':{'name':_("Ancient Amulet"),'power':3,'path':'Weapon.gif'}, + '2':{'name':_("Rusted Blade"),'power':9,'path':'Weapon.gif'}, + '3':{'name':_("Great Sword"),'power':15,'path':'Weapon.gif'}, + '4':{'name':_("Crescent Sword"),'power':25,'path':'Weapon.gif'}, + '5':{'name':_("Cardinal"),'power':35,'path':'Weapon.gif'}, + '6':{'name':_("Sun Moon"),'power':50,'path':'Weapon.gif'} +} + +ARMOR = { + '7':{'name':_("Earth Vest"),'power':8,'path':'Armor.gif'}, + '8':{'name':_("Wind Breaker"),'power':15,'path':'Armor.gif'}, + '9':{'name':_("Flame Leggings"),'power':25,'path':'Armor.gif'}, + 'a':{'name':_("Dark Cowl"),'power':35,'path':'Armor.gif'}, + 'b':{'name':_("Celestial Armor"),'power':50,'path':'Armor.gif'} +} + +ACCESSORY = { + 'c':{'name':_("Jewel Shard"),'power':10,'path':'noItem.gif'}, + 'd':{'name':_("Broken Hourglass"),'power':10,'path':'noItem.gif'}, + 'e':{'name':_("Radiant Vial"),'power':20,'path':'noItem.gif'}, + 'f':{'name':_("Honor Tome"),'power':.2,'path':'noItem.gif'}, + 'g':{'name':_("Valor Tome"),'power':.2,'path':'noItem.gif'} + } + +USABLE = { + 'h':{'name':_("Ruby"),'sell':500,'path':'Ruby.gif'}, + 'i':{'name':_("Sapphire"),'sell':500,'path':'Sapphire.gif'}, + 'j':{'name':_("Emerald"),'sell':500,'path':'Emerald.gif'}, + 'k':{'name':_("Diamond"),'sell':500,'path':'Diamond.gif'}, + 'l':{'name':_("Remedy"),'sell':6,'buy':20,'power':.30,'path':'Remedy.gif'}, + 'm':{'name':_("Elixir"),'sell':15,'buy':60,'power':.5,'path':'Elixir.gif'}, + 'n':{'name':_("Panacea"),'sell':50,'buy':100,'power':1.0,'path':'Panacea.gif'}, + 'o':{'name':_("High Elixir"),'sell':30,'buy':300,'power':.65,'path':'High Elixir.gif'}, + 'p':{'name':_("Nostrum"),'sell':100,'buy':200,'power':.75,'path':'Nostrum.gif'}, +} +KEYS = { + 'q':{'name':_("Small Key"),'path':'Small Key.gif'}, + 'r':{'name':_("Big Key"),'path':'Big Key.gif'} +} + +SPECIAL = { + 's':{'name':_("Calculator"),'path':'noItem.gif'} +} + +class Item: + def __init__(self, name, id, type, path='noItem.gif'): + self.name = name + self.id = id + self.type = type + self.power=0 + self.buyVal=0 + self.path=path + self.sellVal=1 + self.hidden=False + self.battle=False + +class Key(Item): + def __init__(self, key): + Item.__init__(self, KEYS[key]['name'], key, 'key', KEYS[key]['path']) + +class Weapon(Item): + def __init__(self, key): + Item.__init__(self, WEAPONS[key]['name'], key, 'Weapon', WEAPONS[key]['path']) + self.power = WEAPONS[key]['power'] + +class Armor(Item): + def __init__(self, key): + Item.__init__(self, ARMOR[key]['name'], key, 'Armor', ARMOR[key]['path']) + self.power = ARMOR[key]['power'] + +class Usable(Item): + def __init__(self, key): + Item.__init__(self, USABLE[key]['name'], key, 'Usable', USABLE[key]['path']) + + if USABLE[key].has_key( 'sell' ): + self.sellVal = USABLE[key]['sell'] + + if USABLE[key].has_key( 'buy' ): + self.buyVal = USABLE[key]['buy'] + + if USABLE[key].has_key( 'power' ): + self.power = USABLE[key]['power'] + +class Accessory(Item): + def __init__(self, key): + Item.__init__(self, ACCESSORY[key]['name'], key, 'Accessory', ACCESSORY[key]['path']) + self.power = ACCESSORY[key]['power'] + +class Special(Item): + def __init__(self, key): + Item.__init__(self, SPECIAL[key]['name'], key, 'Special', SPECIAL[key]['path']) + +def get_item(key): + if key in WEAPONS: + return Weapon( key ) + elif key in ARMOR: + return Armor( key ) + elif key in ACCESSORY: + return Accessory( key ) + elif key in USABLE: + return Usable( key ) + elif key in KEYS: + return Key( key ) + elif key in SPECIAL: + return Special( key ) + else: + raise InvalidItemException() diff --git a/MAFH2/JournalIntegration.py b/MAFH2/JournalIntegration.py index f743c2e..aa3fb9e 120000..100644 --- a/MAFH2/JournalIntegration.py +++ b/MAFH2/JournalIntegration.py @@ -1 +1,133 @@ -../MAFH.activity/JournalIntegration.py \ No newline at end of file +try: + from sugar.datastore import datastore +except: + print "**Warning**: Not running in sugar env" + print "\t* Sugar datastore required for custom map functionality" + print "\t* Trying to load custom map or export will cause crash" +import os +import re +class BadInputException(Exception):pass + +FILE_MIME = "application/x-fortune-map" +FM_VERSION = '1' #Must be string for dict + + +def export_textfile(activity, filename, dungeon_id, filetext=''): + """ + Exports text to journal (in fortune map format) + Requires activity instance, file name, dungeon id, and text + + @Returns: a DSObject representing the file in the datastore. + """ + ds_objects, num_objects = datastore.find({'title':filename,'FortuneMaker_VERSION':FM_VERSION}) + + if num_objects == 0: + # Create a datastore object + file_dsobject = datastore.create() + + else: + file_dsobject = ds_objects[0] + + # Store unique id for easy search of journal + file_dsobject.metadata['FM_UID'] = dungeon_id + + # Write any metadata (here we specifically set the title of the file and + # specify that this is a plain text file). + file_dsobject.metadata['title'] = filename + file_dsobject.metadata['mime_type'] = FILE_MIME + file_dsobject.metadata['FortuneMaker_VERSION'] = FM_VERSION + + #Write the actual file to the data directory of this activity's root. + file_path = os.path.join(activity.get_activity_root(), 'instance', filename) + f = open(file_path, 'w') + try: + f.write(filetext) + finally: + f.close() + + #Set the file_path in the datastore. + file_dsobject.set_file_path(file_path) + + datastore.write(file_dsobject) + file_dsobject.destroy() + + +def list_fh_files(): + ds_objects, num_objects = datastore.find({'FortuneMaker_VERSION':FM_VERSION}) + file_list = [] + for i in xrange(0, num_objects, 1): + if ds_objects[i].metadata.has_key('FM_UID'): + file_list.append( ds_objects[i] ) + else: + #TODO: Attempt to read uid from file? + pass + return file_list + +def load_dungeon_by_id(id): + ds_objects, num_objects = datastore.find({'FortuneMaker_VERSION':FM_VERSION,'FM_UID':id}) + + if num_objects == 0: + return False + + return load_dungeon(ds_objects[0]) + +def load_dungeon(file_data): + """ + Gets dungeon data dictionary from journal file object + + Internally opens file from xo journal object and calls do_load + + Throws BadInputException if failed to parse parts of the file + """ + dgnFile=open(file_data.get_file_path(),'r') + dungeon_data = do_load( dgnFile ) + dngFile.close() + + return dungeon_data + +def do_load( dgnFile ): + """ + Gets dungeon data dictionary from file stream + + Throws BadInputException if failed to parse parts of the file + """ + grab = 0 + room_str = [] + for line in dgnFile: + if grab == 0: + name = line.strip() + grab = 1 + + elif grab == 1: + d_id = line.strip() + grab = 2 + + elif grab == 2: + match = re.match('(\d+)x(\d+)',line) + if match: + x = int(match.group(1)) + y = int(match.group(2)) + grab = 3 + else: + raise BadInputException() + + elif grab == 3: + theme = int(line) + grab = 4 + + elif grab == 4: + next = line.strip() + grab = 5 + + elif grab == 5: + room_str.append(line.strip()) + + if grab == 5: + dungeon_dict = { + 'name': name, 'theme': theme, 'next': next, + 'x': x, 'y': y, 'roomstr': room_str, 'd_id': d_id + } + return dungeon_dict + + else: + raise BadInputException() diff --git a/MAFH2/constants.py b/MAFH2/constants.py index 2c67878..91441ad 120000..100644 --- a/MAFH2/constants.py +++ b/MAFH2/constants.py @@ -1 +1,114 @@ -../MAFH.activity/constants.py \ No newline at end of file +import os.path +from gettext import gettext as _ + +BASE_PATH = os.path.dirname(__file__) + "/assets/" +#BASE_PATH = "/home/liveuser/GIT_REPOS/MAFH/mainline/MAFH.activity/assets/" +SOUND_PATH = BASE_PATH + "sound/" +MAP_PATH = BASE_PATH + "map/" +MENU_PATH = BASE_PATH + "image/menu/" +HUD_PATH = BASE_PATH + "image/hud/" +ENV_PATH = BASE_PATH + "image/environment/" +ITEM_PATH = BASE_PATH + "image/item/" +PUZZLE_PATH = BASE_PATH + "image/puzzle/" +FMC_PATH = BASE_PATH + "fmc/" +TOUR_PATH = BASE_PATH + "image/tutorial/" +CHAR_PATH = BASE_PATH + "image/character/" + +DOOR_ORDER = ['N','S','E','W'] +DOOR_INDEX = { + 'N':_('North'), + 'S':_('South'), + 'E':_('East'), + 'W':_('West') + } + + +UNLOCKED_DOOR = 'u' +LOCKED_DOOR = 'l' +PUZZLE_DOOR = 'p' +LOCKED_PUZZLE_DOOR = 'b' +ENTRANCE_DOOR = 'e' +EXIT_DOOR = 'x' + +DOOR_FLAGS = { + '0':_('None'), + UNLOCKED_DOOR:_('Unlocked'), + LOCKED_DOOR:_('Locked'), + PUZZLE_DOOR:_('Puzzle'), + LOCKED_PUZZLE_DOOR:_('Locked Puzzle'), + ENTRANCE_DOOR:_('Entrance'), + EXIT_DOOR:_('Exit') + } + +SPEC_FLAGS = { + '0':_('None'), + 'M':_('Merchant'), + 'P':_('Puzzle') + } + +ENEM_INDEX = { + '0':_('None'), + '1':_('Wizard Adept'), + '2':_('Goblin'), + '3':_('Orc'), + '4':_('Stone Golem'), + '5':_('Serratula'), + '6':_('Feren') + } + +ITEM_INDEX = { + '0':_('None'), + '1':_("Ancient Amulet"), + '2':_("Rusted Blade"), + '3':_("Great Sword"), + '4':_("Crescent Sword"), + '5':_("Cardinal"), + '6':_("Sun Moon"), + '7':_("Earth Vest"), + '8':_("Wind Breaker"), + '9':_("Flame Leggings"), + 'a':_("Dark Cowl"), + 'b':_("Celestial Armor"), + 'c':_("Jewel Shard"), + 'd':_("Broken Hourglass"), + 'e':_("Radiant Vial"), + 'f':_("Honor Tome"), + 'g':_("Valor Tome"), + 'h':_("Ruby"), + 'i':_("Sapphire"), + 'j':_("Emerald"), + 'k':_("Diamond"), + 'l':_("Remedy"), + 'm':_("Elixir"), + 'n':_("Panacea"), + 'o':_("High Elixir"), + 'p':_("Nostrum"), + 'q':_("Small Key"), + 'r':_("Big Key"), +} + +ITEM_FLAGS = { + '0':_('None'), + 'v':_('Visible'), + 'h':_('Hidden'), + 'b':_('Battle') +} + +# Integer Driven +THEME_NAME = [ + _('Default Theme'), + _('Ice'), + _('Fire'), + _('Ice'), + _('Jungle'), + _('Desert'), + _('Astral') + ] + +NORTH=1 +SOUTH=3 +EAST=0 +WEST=2 + +RIGHT = 4 +LEFT = 5 -- cgit v0.9.1