Beispiel #1
0
def quit(data):
    """Quit the game."""
    data["want_to_play"] = False
    printer.p(
        "{.BLUE}[Goodbye!]{.ENDC}".format(printer.PColors, printer.PColors),
        "Saving game! See you later!")
    prep_data_on_close(data)
Beispiel #2
0
def recieve_treasures(data):
    temp = "{.TREASURE}[TREASURE]{.ENDC}".format(printer.PColors,
                                                 printer.PColors)
    for treasure in data["pending_treasures"]:
        printer.p(
            temp,
            "{0} gave you a treasure! {1}!!!".format(treasure[0], treasure[1]))
    def get_selection(self):
        """
        Returns the sublime region corresponding to the selected module path
        """
        selections = self.view.sel()

        if not selections:
            return None

        region = selections[0]

        row, col = self.view.rowcol(region.a)

        p('clicked row: ', row)
        p('clicked col: ', col)
        p('region: ', region)

        line = self.view.substr(self.view.line(region))
        p('line: ', line)
        p('line length: ', len(line))

        return {
            "clicked_position": col,
            "line": line
        }
Beispiel #4
0
def check_treasures(data):
    temp = "{.TREASURE}[TREASURE]{.ENDC}".format(printer.PColors,
                                                 printer.PColors)
    for cat in [cat for cat in data["cats"] if cat["given_treasure"]]:
        printer.p(
            temp, "You have a treasure from {0}! {1}!!!".format(
                cat["name"], cat["treasure"]))
Beispiel #5
0
def node_bridge(bin, args, node_path=None):
    env = None
    if IS_OSX:
        # GUI apps in OS X don't contain .bashrc/.zshrc set paths
        env = os.environ.copy()

        if not node_path:
            node_path = ':/usr/local/bin'

        p('Node path: ' + node_path)

        env['PATH'] += node_path

    try:
        cmd = ['node', bin] + args

        p('Executing: ', ' '.join(cmd))

        proc = Popen(cmd, stdout=PIPE, stdin=PIPE, stderr=PIPE, env=env, shell=IS_WINDOWS)

    except OSError:
        raise Exception('Couldn\'t find Node.js. Make sure it\'s in your $PATH by running `node -v` in your command-line.')

    stdout, stderr = proc.communicate(input=''.encode('utf-8'))
    stdout = stdout.decode('utf-8')
    stderr = stderr.decode('utf-8')

    if stderr:
        raise Exception('Error: %s' % stderr)
    else:
        return stdout
Beispiel #6
0
def recieve_treasures(data):
    if len(data["pending_treasures"]) is 0:
        return
    temp = "{.TREASURE}[TREASURE]{.ENDC}".format(
            printer.PColors, printer.PColors)
    for treasure in data["pending_treasures"]:
        printer.p(temp, "{0} gave you a treasure! {1}!!!".format(
                 treasure[0], treasure[1]))
    data["pending_treasures"] = []
Beispiel #7
0
def check_treasures(data):
    temp = "{.TREASURE}[TREASURE]{.ENDC}".format(
            printer.PColors, printer.PColors)
    treasures = [cat for cat in data["cats"].itervalues() if cat["given_treasure"]]
    if treasures:
        for cat in treasures:
            printer.p(temp, "You have a treasure from {0}! {1}!!!".format(
                    cat["name"], cat["treasure"]))
    else:
        printer.p(temp, "Aww, no cats have given you treasures yet.. But don't worry! Keep trying and I'm sure they will!!")
Beispiel #8
0
    def get_function_name(self):
        selections = self.view.sel()
        if selections:
            region = selections[0]
            if region.a == region.b:
                selected_word = self.view.substr(self.view.word(region))

                p('selected word: ', selected_word)
                return selected_word

        return None
Beispiel #9
0
    def get_drivers(self):
        """
        Asks the node tool for the drivers of the current module
        """
        args = {'filename': self.view.filename, 'command': 'find-drivers'}

        drivers = [d for d in backend(args).split('\n') if d]

        p(len(drivers), 'drivers found:\n' + '\n'.join(drivers))

        return drivers
Beispiel #10
0
    def get_function_name(self):
        selections = self.view.sel()
        if selections:
            region = selections[0]
            if region.a == region.b:
                selected_word = self.view.substr(self.view.word(region))

                p('selected word: ', selected_word)
                return selected_word

        return None
Beispiel #11
0
def desc_yard(data):
    """Describe current yard situation."""
    toys = [item for item in data["yard"]]
    printer.p(
        data["prefix"], "You have {0} total spaces on your lawn".format(6))
    # TODO: have this reflect size
    for toy in toys:
        occupants = toy["occupant"] or ["no one"]
        printer.p(
            data["prefix"], "You have a {0} being used by {1}".format(
                toy["name"], ", and ".join(occupants)))
Beispiel #12
0
def desc_yard(data):
    """Describe current yard situation."""
    toys = [item for item in data["yard"]]
    printer.p(data["prefix"],
              "You have {0} total spaces on your lawn".format(6))
    # TODO: have this reflect size
    for toy in toys:
        occupants = toy["occupant"] or ["no one"]
        printer.p(
            data["prefix"], "You have a {0} being used by {1}".format(
                toy["name"], ", and ".join(occupants)))
Beispiel #13
0
    def run(self):
        p('Extracted click position', self.view.click_position)

        file_to_open = backend({
            'filename': self.view.filename,
            'click_position': self.view.click_position,
            'command': 'jump-to-definition'
        }).strip()

        p('After jump to definition lookup', file_to_open)

        self.open_file(file_to_open)
Beispiel #14
0
    def run(self):
        if not super(GetPathCommand, self).run():
            return

        path = backend({
            'filename': self.view.filename,
            'command': 'get-path'
        }).strip()

        p('Path:', path)

        sublime.set_clipboard(path)
Beispiel #15
0
def collect_money(data):
    """Collect money left by cats."""
    if len(data["pending_money"]) == 0:
        printer.p("{.YELLOW}[$$$$$$]{.ENDC}".format(
            printer.PColors,
            printer.PColors), "Sorry, no cats have left you anything")
        return
    for i in range(len(data["pending_money"])):
        money = data["pending_money"].pop()
        printer.p("{.GREEN}[$$$$$$]{.ENDC}".format(
            printer.PColors,
            printer.PColors), "Yes! {0} left you {1} fish!".format(
            money[0], str(money[1])))
        data["s_fish"] += money[1]
Beispiel #16
0
    def get_drivers(self):
        """
        Asks the node tool for the drivers of the current module
        """
        args = {
            'filename': self.view.filename,
            'command': 'find-drivers'
        }

        drivers = [d for d in backend(args).split('\n') if d]

        p(len(drivers), 'drivers found:\n' + '\n'.join(drivers))

        return drivers
Beispiel #17
0
def collect_money(data):
    """Collect money left by cats."""
    if len(data["pending_money"]) == 0:
        printer.p(
            "{.YELLOW}[$$$$$$]{.ENDC}".format(printer.PColors,
                                              printer.PColors),
            "Sorry, no cats have left you anything")
        return
    for i in range(len(data["pending_money"])):
        money = data["pending_money"].pop()
        printer.p(
            "{.GREEN}[$$$$$$]{.ENDC}".format(printer.PColors, printer.PColors),
            "Yes! {0} left you {1} fish!".format(money[0], str(money[1])))
        data["s_fish"] += money[1]
Beispiel #18
0
    def run(self, modifier='', edit=None):
        setup_was_successful = command_setup(self)

        if not setup_was_successful:
            p('Setup was not successful')

        if modifier:
            self.view.modifier = modifier
        else:
            self.view.modifier = None

        if edit:
            self.view.edit = edit

        return setup_was_successful
Beispiel #19
0
    def run(self, modifier='', edit=None):
        setup_was_successful = command_setup(self)

        if not setup_was_successful:
            p('Setup was not successful')

        if modifier:
            self.view.modifier = modifier
        else:
            self.view.modifier = None

        if edit:
            self.view.edit = edit

        return setup_was_successful
Beispiel #20
0
def check_treasures(data):
    temp = "{.TREASURE}[TREASURE]{.ENDC}".format(printer.PColors,
                                                 printer.PColors)
    treasures = [
        cat for cat in data["cats"].itervalues() if cat["given_treasure"]
    ]
    if treasures:
        for cat in treasures:
            printer.p(
                temp, "You have a treasure from {0}! {1}!!!".format(
                    cat["name"], cat["treasure"]))
    else:
        printer.p(
            temp,
            "Aww, no cats have given you treasures yet.. But don't worry! Keep trying and I'm sure they will!!"
        )
Beispiel #21
0
def collect_money(data):
    """Collect money left by cats."""
    if len(data["pending_money"]) == 0:
        printer.p(
            "{.YELLOW}[$$$$$$]{.ENDC}".format(printer.PColors,
                                              printer.PColors),
            "Sorry, no cats have left you anything")
        return
    for i in range(len(data["pending_money"])):
        money = data["pending_money"].pop()
        currency = money[2]
        printer.p(
            "{.GREEN}[$$$$$$]{.ENDC}".format(printer.PColors, printer.PColors),
            "Yes! {0} left you {1}{2} fish!".format(
                money[0], str(money[1]),
                " gold" if currency == "g" else " silver"))
        data[currency + "_fish"] += money[1]
Beispiel #22
0
    def get_callers(self, function_name):
        """
        Asks the node tool for the drivers of the current module
        """
        args = {
            'filename': self.view.filename,
            'path': function_name,
            'command': 'find-callers'
        }

        fetch_time = time.time()

        callers = [c for c in backend(args) if c]

        p('Fetch time:', time.time() - fetch_time)
        p(len(callers), 'callers found:\n' + '\n'.join(callers))

        return callers
Beispiel #23
0
    def get_callers(self, function_name):
        """
        Asks the node tool for the drivers of the current module
        """
        args = {
            'filename': self.view.filename,
            'path': function_name,
            'command': 'find-callers'
        }

        fetch_time = time.time()

        callers = [c for c in backend(args) if c]

        p('Fetch time:', time.time() - fetch_time)
        p(len(callers), 'callers found:\n' + '\n'.join(callers))

        return callers
def backend(options):
    args = []

    if 'filename' in options:
        args.append('--filename=' + options['filename'])

    if is_ST2:
        editor = 'ST2'
    else:
        editor = 'ST3'
    args.append('--editor=' + editor)

    if 'command' in options:
        args.append('--' + options['command'])

    # TODO: Deprecate when JumpToDependency combines with JumpToDefinition
    if 'lookup_position' in options:
        args.append('--lookup-position=' + str(options['lookup_position']))

    if 'click_position' in options:
        args.append('--click-position=' + str(options['click_position']))

    if 'path' in options:
        args.append(options['path'])

    try:
        node_path = get_project_settings(options['filename']).get('node_path')
        p('node_path from settings: ', node_path)

        # TODO: It's not great to hardcode the Package name here but __file__ isn't consistent between Python 2 and 3
        bin_path = sublime.packages_path(
        ) + '/Dependents/node_modules/dependents-editor-backend/bin/cli.js'
        p('bin path', bin_path)

        return node_bridge(bin_path, args, node_path)

    except Exception as e:
        traceback.print_exc()
        show_error(
            'An error occurred. Please file an issue with the following:\n\n' +
            str(e), True)

    return ''
    def run(self):
        """
        Jumps to the file identified by the string under the cursor
        """

        selection = self.view.selection

        p('Extracted Selection', selection)

        file_to_open = backend({
            'filename': self.view.filename,
            'path': selection.get('line'),
            'lookup_position': selection.get('clicked_position'),
            'command': 'lookup'
        }).strip()

        p('After cabinet lookup', file_to_open)

        self.open_file(file_to_open)
Beispiel #26
0
def print_help(data):
    """Print the game help."""
    temp = "{.HELP}[Help!]{.ENDC}".format(
        printer.PColors, printer.PColors)
    printer.p(temp, "Welcome to Neko Atsume!")
    printer.p(temp, "In this game cats come to visit you and you feed them")
    printer.p(temp, "it's pretty cool, so you should play more")
def backend(options):
    args = []

    if 'filename' in options:
        args.append('--filename=' + options['filename'])

    if is_ST2:
        editor = 'ST2'
    else:
        editor = 'ST3'
    args.append('--editor=' + editor)

    if 'command' in options:
        args.append('--' + options['command'])

    # TODO: Deprecate when JumpToDependency combines with JumpToDefinition
    if 'lookup_position' in options:
        args.append('--lookup-position=' + str(options['lookup_position']))

    if 'click_position' in options:
        args.append('--click-position=' + str(options['click_position']))

    if 'path' in options:
        args.append(options['path'])

    try:
        node_path = get_project_settings(options['filename']).get('node_path')
        p('node_path from settings: ', node_path)

        # TODO: It's not great to hardcode the Package name here but __file__ isn't consistent between Python 2 and 3
        bin_path = sublime.packages_path() + '/Dependents/node_modules/dependents-editor-backend/bin/cli.js'
        p('bin path', bin_path)

        return node_bridge(bin_path, args, node_path)

    except Exception as e:
        traceback.print_exc()
        show_error('An error occurred. Please file an issue with the following:\n\n' + str(e), True)

    return ''
Beispiel #28
0
    def get_selection(self):
        """
        Returns the sublime region corresponding to the selected module path
        """
        selections = self.view.sel()

        if not selections:
            return None

        region = selections[0]

        row, col = self.view.rowcol(region.a)

        p('clicked row: ', row)
        p('clicked col: ', col)
        p('region: ', region)

        line = self.view.substr(self.view.line(region))
        p('line: ', line)
        p('line length: ', len(line))

        return {"clicked_position": col, "line": line}
Beispiel #29
0
    def run(self):
        """
        Finds the dependents of the current file and jumps to that file or shows a panel of dependent files
        """
        dependents = self.get_dependents()
        p('fetched dependents: ', dependents)

        self.dependents = trim_paths_of_root(dependents, self.window.config['directory'])

        if self.view.modifier == 'OPEN_ALL':
            for dep in self.dependents:
                self.open_file(dep)

        elif self.view.modifier == 'COPY_ALL':
            extLess = map(lambda d: os.path.splitext(d)[0], self.dependents)
            sublime.set_timeout(lambda: sublime.set_clipboard('\n'.join(extLess)), 100)

        elif len(self.dependents) == 1:
            p('Opening the only dependent: ', self.dependents[0])
            self.open_file(self.dependents[0])

        else:
            sublime.set_timeout(self.show_quick_panel, 10)
Beispiel #30
0
    def open_file(self, filename):
        """
        Opens the passed file or shows an error error message
        if the file cannot be found
        """
        p('Opening:', filename)

        location_less = filename
        location_colon_index = filename.find(':')

        if location_colon_index != -1:
            location_less = filename[:location_colon_index]

        p('Location-less filename: ' + location_less)

        if not filename or not os.path.isfile(location_less):
            cant_find_file()
            return

        def open():
            self.window.open_file(filename, sublime.ENCODED_POSITION)

        sublime.set_timeout(open, 10)
Beispiel #31
0
    def run(self):
        """
        Jumps to the file identified by the string under the cursor
        """

        selection = self.view.selection

        p('Extracted Selection', selection)

        file_to_open = backend({
            'filename':
            self.view.filename,
            'path':
            selection.get('line'),
            'lookup_position':
            selection.get('clicked_position'),
            'command':
            'lookup'
        }).strip()

        p('After cabinet lookup', file_to_open)

        self.open_file(file_to_open)
Beispiel #32
0
    def open_file(self, filename):
        """
        Opens the passed file or shows an error error message
        if the file cannot be found
        """
        p('Opening:', filename)

        location_less = filename
        location_colon_index = filename.find(':')

        if location_colon_index != -1:
            location_less = filename[:location_colon_index]

        p('Location-less filename: ' + location_less)

        if not filename or not os.path.isfile(location_less):
            cant_find_file()
            return

        def open():
            self.window.open_file(filename, sublime.ENCODED_POSITION)

        sublime.set_timeout(open, 10)
Beispiel #33
0
    def get_selection(self):
        selections = self.view.sel()

        if not selections:
            return None

        region = selections[0]

        row, col = self.view.rowcol(region.a)

        p('clicked row: ', row)
        p('clicked col: ', col)
        p('region: ', region)

        # +1s to go from 0-based to 1-based line info
        return str(row + 1) + ',' + str(col + 1)
Beispiel #34
0
def print_help(data):
    """Print the game help."""
    temp = "{.HELP}[Help!]{.ENDC}".format(printer.PColors, printer.PColors)
    printer.p(temp, "Welcome to Neko Atsume!")
    printer.p(temp, "In this game cats come to visit you and you feed them")
    printer.p(temp, "it's pretty cool, so you should play more")
Beispiel #35
0
def quit(data):
    """Quit the game."""
    data["want_to_play"] = False
    printer.p("{.BLUE}[Goodbye!]{.ENDC}".format(
        printer.PColors, printer.PColors), "Saving game! See you later!")
    prep_data_on_close(data)