def add_save_state(uuid): performance_uuid = request.form.get('performance_uuid') performance_time_index = request.form.get('performance_time_index') # Save State File to DB fields = OrderedDict( description=request.form.get('description'), game_uuid=uuid, save_state_type=u'state', emulator_name=request.form.get('emulator'), emulator_version=request.form.get('emulator_version'), emt_stack_pointer=request.form.get('emt_stack_pointer'), stack_pointer=request.form.get('stack_pointer'), time=request.form.get('time'), created_on=None, created=datetime.datetime.now() ) state_uuid = dbm.add_to_save_state_table(fts=True, **fields) # Attach performance information if present if performance_uuid: # Sometimes a state maybe linked to a performance without a specific index? # Since we are adding a new state, it is always a state save action if performance_time_index: dbm.link_save_state_to_performance(state_uuid, performance_uuid, performance_time_index, 'save') else: dbm.link_save_state_to_performance(state_uuid, performance_uuid, 0, 'save') # Retrieve save state information to get uuid and ignore blank fields save_state = dbm.retrieve_save_state(uuid=state_uuid)[0] return jsonify({'record': save_state})
def update_save_state(uuid): update_fields = json.loads(request.form.get('update_fields')) # if linking to a performance, do that and then throw away since GAME_SAVE_TABLE doesn't refer to performance if 'performance_uuid' in update_fields: performance_uuid = update_fields['performance_uuid'] performance_time_index = update_fields['performance_time_index'] action = update_fields['action'] dbm.link_save_state_to_performance(uuid, performance_uuid, performance_time_index, action) del update_fields['performance_uuid'] del update_fields['performance_time_index'] del update_fields['action'] # make sure that there are still fields to update if len(update_fields.keys()) > 0: dbm.update_table(dbm.GAME_SAVE_TABLE, update_fields.keys(),update_fields.values(), ['uuid'], [uuid]) return jsonify(dbm.retrieve_save_state(uuid=uuid)[0])