def cleanupProtoRule(self, r, allPrototypes): # have to uniquify in this round about way because lists # aren't hashable and we need them for ListRef. if type(r["extras"]) == dict: r["extras"] = r["extras"].values() newExtras = [] for e in r["extras"]: if isinstance(e, protocol.Integer): newExtras.append(dfly.Integer(e.name, e.min, e.max)) elif isinstance(e, protocol.Dictation): newExtras.append(dfly.Dictation(e.name)) elif isinstance(e, protocol.Repetition): if e.rule_ref not in self.concreteRules: self.cleanupProtoRule(allPrototypes[e.rule_ref], allPrototypes) # Dragonfly wants RuleRef to take a RuleRef rather than an actual # Rule, so we just make one rather than forcing the server to # handle this, see protocol.py comments. concrete = self.concreteRules[e.rule_ref] log.info("concrete type: [%s]" % type(concrete)) newExtras.append( dfly.Repetition(dfly.RuleRef(rule=concrete), e.min, e.max, e.name)) elif isinstance(e, protocol.RuleRef): if e.rule_ref not in self.concreteRules: self.cleanupProtoRule(allPrototypes[e.rule_ref], allPrototypes) newExtras.append( dfly.RuleRef(self.concreteRules[e.rule_ref], e.name)) elif isinstance(e, protocol.ListRef): self.concreteWordLists[e.name] = List(e.name + "ConcreteList") # self.concreteWordLists[e.name].set(e.words) newExtras.append( dfly.ListRef(e.ref_name, self.concreteWordLists[e.name])) else: raise Exception("Unknown extra type: [%s]" % e) r["extras"] = newExtras self.concreteStartTime = time.time() self.buildConcreteRule(r) self.concreteEndTime = time.time() self.concreteTime += (self.concreteEndTime - self.concreteStartTime) r["built"] = True return True
location = player_status["location"] path_tiles = await server.request("PATH_TO_EDGE", {"direction": direction}) if path_tiles: path = game.Path(path_tiles, location) await path.travel(stream) async def pet_farm_pet(): pass numrep2 = df.Sequence( [ df.Choice(None, rules.nonZeroDigitMap), df.Repetition(df.Choice(None, rules.digitMap), min=0, max=10) ], name="n2", ) num2 = df.Modifier(numrep2, rules.parse_numrep) debris = { "(stones | rocks)": constants.STONE, "(wood | twigs)": constants.TWIG, "weeds": constants.WEEDS, "debris": "debris", } mapping = { "<direction_keys>": objective.objective_action(objective.HoldKeyObjective, "direction_keys"),
} nonZeroDigitMap = { "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9, } def parse_numrep(rep): first, rest = rep numstr = str(first) + "".join(str(d) for d in rest) return int(numstr) def index_choice_from_list(name: str, l): return df.Choice(name, {k: i for (i, k) in enumerate(l)}) positive_digits = df.Sequence( [df.Choice(None, nonZeroDigitMap), df.Repetition(df.Choice(None, digitMap), min=0, max=2)], name="positive_digits", ) positive_num = df.Alternative([df.Modifier(positive_digits, parse_numrep), df.Choice(None, ten_through_twelve)], name="positive_num") positive_index = df.RuleWrap("positive_index", df.Modifier(positive_num, lambda x: x - 1)) positive_index2 = df.RuleWrap("positive_index2", df.Modifier(positive_num, lambda x: x - 1))
def flatten_list(rep): flattened = [] for l in rep: flattened.extend(l) return flattened all_chars_choice = df.Choice(None, { **letter_map, **capital_letter_map, **keys, **numbers }) letters_and_keys = df.Repetition(all_chars_choice, name="letters_and_keys", min=1, max=16) def type_characters(letters: str): shift_down = False for char in letters: shift_char = char.isupper() char = char.lower() if shift_char and not shift_down: pydirectinput.keyDown('shift') shift_down = True elif not shift_char and shift_down: pydirectinput.keyUp('shift') shift_down = False pydirectinput.press(char)
extras = [ fly.IntegerRef('n', 1, 100), fly.Dictation('text'), ] defaults = { 'n': 1, } alternatives = [] alternatives.append(fly.RuleRef(rule=KeystrokeRule())) if FormatRule: alternatives.append(fly.RuleRef(rule=FormatRule())) single_action = fly.Alternative(alternatives) sequence = fly.Repetition(single_action, min=1, max=16, name='sequence') class RepeatRule(fly.CompoundRule): # Here we define this rule's spoken-form and special elements. spec = '<sequence> [[[and] repeat [that]] <n> times]' extras = [ sequence, # Sequence of actions defined above. fly.IntegerRef('n', 1, 100), # Times to repeat the sequence. ] defaults = { 'n': 1, # Default repeat count. } def _process_recognition(self, node, extras):