Пример #1
0
def _check_features(value, file_json):
    """
    check that the keys in the features are correct
    and that all verbs that are part of those features are also correct
    """
    feature_keys = dict_keys().get_feature_keys()
    verbs = dict_keys().get_verbs()
    verb_keys = dict_keys().get_verb_keys()
    use_keys = dict_keys().get_additional_use_keys()

    response = dict()

    #if the feature e.g. 1 or 2 does not exist don't check the contents
    if value not in file_json["features"]:
        response.update({"features": {value: "missing object: " + value}})
    else:
        #first we'll check the contents of the feature
        result = dict()
        result.update(
            {value: _compare_dict(file_json["features"][value], feature_keys)})
        if result[value]:
            response = _merge_two_dicts(response, result)
        #now we'll check that the feature has all the correct verbs
        result = dict()
        result.update({
            "feature " + value + " verbs":
            _compare_dict(file_json["features"][value]["verbs"], verbs)
        })
        if result["feature " + value + " verbs"]:
            response = _merge_two_dicts(response, result)
        #validate the structure of the verbs in the feature
        for verb in file_json["features"][value]["verbs"]:
            result = dict()
            if verb == "use":
                result.update({
                    "feature " + value + " " + verb:
                    _compare_dict(file_json["features"][value]["verbs"][verb],
                                  use_keys + verb_keys)
                })
            else:
                result.update({
                    "feature " + value + " " + verb:
                    _compare_dict(file_json["features"][value]["verbs"][verb],
                                  verb_keys)
                })
            if result["feature " + value + " " + verb]:
                response = _merge_two_dicts(response, result)

    return response
Пример #2
0
def _match_keys_items(file_json):
    """
    checks the passed in json object against the official structure expected of 
    and item
    """
    item_keys = dict_keys().get_item_keys()
    res = dict()

    result = _compare_dict(file_json, item_keys)
    res = _merge_two_dicts(res, result)
    result = _check_verbs(file_json)
    res = _merge_two_dicts(res, result)
    return res
Пример #3
0
def _check_verbs(file_json):
    """
    checks the verb structure
    """
    verbs = dict_keys().get_verbs()
    verb_keys = dict_keys().get_verb_keys()
    use_keys = dict_keys().get_additional_use_keys()
    response = dict()
    response = _compare_dict(file_json['verbs'], verbs)
    for verb in file_json["verbs"]:
        result = dict()
        if verb == "use":
            result.update({
                verb:
                _compare_dict(file_json["verbs"][verb], use_keys + verb_keys)
            })
        else:
            result.update(
                {verb: _compare_dict(file_json["verbs"][verb], verb_keys)})
        if result[verb]:
            response = _merge_two_dicts(response, result)
    return response
Пример #4
0
def _check_connected_rooms(file_json):
    """
    check that the structure connected_rooms has all the correct keys
    because the connected rooms are unstructured objects meaning without
    keys, then only collect the keys that are missing, but we'll need to 
    check manually which connected_room it came from
    """
    response = dict()
    keys = dict_keys().get_connected_room_keys()
    if "connected_rooms" in file_json:
        for room in file_json["connected_rooms"]:
            obj = file_json['connected_rooms'][room]
            result = dict()
            result = _compare_dict(obj, keys)
            if result:
                response.update(result)
    if response:
        response = {"connected_rooms": response}
    return response
Пример #5
0
def _match_keys_room(file_json):
    """
    checks the passed in json object against the official structure expected and if it
    is different returns true if they keys match
    """
    room_keys = dict_keys().get_room_keys()
    response = dict()

    #check the top level of the room file
    result = _compare_dict(file_json, room_keys)
    response = _merge_two_dicts(response, result)
    #check the features structure
    for feature in file_json['features']:
        result = _check_features(feature, file_json)
        response = _merge_two_dicts(response, result)
    result = _check_connected_rooms(file_json)
    response = _merge_two_dicts(response, result)

    return response
Пример #6
0
Add a key to a type of file: room, item
Delete a key to a type of file: room, item
Edit a key to a type of file: room, item
"""
from collections import OrderedDict
from name_lists import room_info
from name_lists import item_info
from name_lists import dict_keys
from name_lists import save_info
import file_handler.data_entry as mod_files
import file_handler.file_lib as files
import json
import os

FILES_TO_IGNORE = ["Rooms.md", "Items.md"]
OPTIONAL_KEYS = dict_keys().get_opt_keys()
ROOMS_DIR = room_info().get_dir()
TEMP_ROOMS_DIR = save_info().get_temp_save_dir_rooms()
ITEMS_DIR = item_info().get_dir()
ITEMS_TEMP_DIR = save_info().get_temp_save_dir_items()
ROOM_TITLES = room_info().get_titles()
ITEM_TITLES = item_info().get_titles()


def _list_keys(option):
    """
    This function will iterate through all the room or item template files
    located in the /data/rooms/ or /data/items/ and check that all the files 
    have the same structure.  It will report what rooms are different if any
    and then list all the keys in the room structure
    """