v50 Steam/Premium information for editors
- v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
- Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.
Difference between revisions of "User:Button/BAMM"
Jump to navigation
Jump to search
(Created page with "== About == === Features === === Planned Features === == Usage Instructions == === Download === You can [https://github.com/BoomButton/DF-BAMM download the script] from G...") |
(→Button's Workspace: Came up with a solution for the GROWTH_PRINT $,$ vs $,& problem) |
||
Line 87: | Line 87: | ||
self._ | self._ | ||
"""</pre> | """</pre> | ||
+ | |||
+ | <pre> | ||
+ | OBJECT:PLANT|PLANT:$|GROWTH:$|GROWTH_PRINT:?(5,5):$(2,2):&(0,1) | ||
+ | OBJECT:PLANT|PLANT:$|GROWTH:$|GROWTH_PRINT:?(5,5):ALL:&(0,1) | ||
+ | OBJECT:PLANT|PLANT:$|GROWTH:$|GROWTH_PRINT:?(5,5):NONE:&(0,1) | ||
+ | |||
+ | def get_best_match(template_tokens_bag): | ||
+ | if not template_tokens_bag: # empty bag returns false | ||
+ | return None | ||
+ | elif len(template_tokens_bag) == 1: | ||
+ | return template_tokens_bag[0] | ||
+ | else: | ||
+ | best_currently = template_tokens_bag[0] | ||
+ | best_tokens = 0 | ||
+ | for tag in template_tokens_bag: | ||
+ | challenger_tokens = 0 | ||
+ | for token in tag: | ||
+ | if token != '?' and token != '&' and token != '$': | ||
+ | challenger_tokens = challenger-tokens + 1 | ||
+ | if challenger_tokens > best_tokens: | ||
+ | best_currently = tag | ||
+ | best_tokens = challenger_tokens | ||
+ | return best_currently | ||
+ | |||
+ | </pre> |
Revision as of 17:16, 28 May 2015
About
Features
Planned Features
Usage Instructions
Download
You can download the script from GitHub.
Python 3
Configuration
Button's Workspace
Sometimes I'm on a computer I can't put a git client on.
class TreeNode(): """Parent class for the other Node classes. Contains default implementations of common Tree functionality. Members: self._parent = the parent TreeNode of this TreeNode. Any given subclass of TreeNode should only have TreeNodes of its own type as _parent. self._tag = The string that this node represents. This should be overridden and re-defined by subclasses. self._children = A dict of type string:TreeNode, where the key is the child's ._tag property. Functions: self.__init__(self,parent=None) """ def __init__(self,parent=None): """Create a TreeNode. Sets self._parent to argument parent, initializes an empty dict for self._children, and sets self._tag = None. """ self._parent = parent self._children = {} self._tag = None #if parent != None: # parent.add_child(self) def add_child(self, child_node): """Add a child to this TreeNode.""" self._children[child_node._tag] = child_node def find_match(self, tag): """Find a TreeNode related to this TreeNode which has the given tag. tag is a value corresponding to the ._tag field of TreeNode you're calling this on. REMEMBER: Different TreeNode subclasses have different formats of ._tags! The return value is a TreeNode with the specified ._tag value, or None. The TreeNodes searched are this node's immediate children, and its direct ancestors' immediate children. """ curr_node = self matching_node = None out_of_parents = False while matching_node is None and not out_of_parents: #matching_node = curr_node.get_template_match(tag)[0] #if matching_node == None: matching_node = curr_node.get_child(tag) if curr_node._parent is None: out_of_parents = True else: curr_node = curr_node._parent return matching_node def get_child(self, tag): """Return an immediate child with the given tag, or None if no such child exists.""" if tag in self._children.keys(): return self._children[tag] else: return None class TemplateNode(TreeNode): """An implementation of TreeNode specialized for holding tag templates. Members: self._parent = the parent TemplateNode of this TemplateNode. self._tag = the string representing a valid format of raw tag. Literals are themselves; colons separate tokens; $s indicate identifiers; ?s indicate graphics information; and &s indicate non-identifier, non-graphics information. For more fluidly-formatted tags, the following format indicates more than one tag: x(#,#) , where the x is a $, ? or &, the #s are a min/max pair, and the max is optional. See templates.config self._is_graphics_tag = The template config file is formatted in such a way that which tags are graphics tags is straightforward. This is a bool retaining that information. It is set to False by default, then later set to True where appropriate by the template loading function. self._ """
OBJECT:PLANT|PLANT:$|GROWTH:$|GROWTH_PRINT:?(5,5):$(2,2):&(0,1) OBJECT:PLANT|PLANT:$|GROWTH:$|GROWTH_PRINT:?(5,5):ALL:&(0,1) OBJECT:PLANT|PLANT:$|GROWTH:$|GROWTH_PRINT:?(5,5):NONE:&(0,1) def get_best_match(template_tokens_bag): if not template_tokens_bag: # empty bag returns false return None elif len(template_tokens_bag) == 1: return template_tokens_bag[0] else: best_currently = template_tokens_bag[0] best_tokens = 0 for tag in template_tokens_bag: challenger_tokens = 0 for token in tag: if token != '?' and token != '&' and token != '$': challenger_tokens = challenger-tokens + 1 if challenger_tokens > best_tokens: best_currently = tag best_tokens = challenger_tokens return best_currently