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.

User:Button/BAMM

From Dwarf Fortress Wiki
< User:Button
Revision as of 19:28, 22 May 2015 by Button (talk | contribs) (Created page with "== About == === Features === === Planned Features === == Usage Instructions == === Download === You can [https://github.com/BoomButton/DF-BAMM download the script] from G...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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._
	"""