コード例 #1
0
    def writeRule(self):

        #Make our new rule folder, should none exist
        if not os.path.isdir(self._path):
            os.mkdir(self._path)

        modificationspath = self._path + "/Modifications/"

        if not os.path.isdir(modificationspath):
            os.mkdir(modificationspath)
        """
        Write our base XML file for the Rewrite Rule
        """
        #Write our root head
        root = ET.Element('rule')
        root.attrib['name'] = self._rule.get_name()
        root.attrib['type'] = "Rewrite_Rule"

        if (self._rule.get_apply_once()):
            root.attrib['applyonce'] = 'true'
        else:
            root.attrib['applyonce'] = 'false'

        social_condition_name = self._rule.get_name() + "_Social_Condition"
        social_condition = ET.SubElement(root, 'socialcondition')
        social_condition.text = str(social_condition_name)

        story_condition_name = self._rule.get_name() + "_Story_Condition"
        story_condition = ET.SubElement(root, 'storycondition')
        story_condition.text = str(story_condition_name)

        story_modification_name = self._rule.get_name() + "_Story_Modification"
        story_modification = ET.SubElement(root, 'storymodification')
        story_modification.text = str(story_modification_name)

        #Write our xml to a file
        tree = ET.ElementTree(root)
        tree.write(self._path + "/" + self._rule.get_name() + ".xml")

        #Write the social graph
        social_condition_writer = XMLSocialGraphWriter(
            self._path + "/" + social_condition_name,
            self._rule.get_social_condition())
        social_condition_writer.writeGraph()

        story_condition_writer = XMLStoryGraphWriter(
            self._path + "/", story_condition_name,
            self._rule.get_story_condition())
        story_condition_writer.writeGraph()

        story_modification_writer = XMLStoryGraphWriter(
            self._path + "/", story_modification_name,
            self._rule.get_story_modification())
        story_modification_writer.writeGraph()
コード例 #2
0
    def writeRule(self):
        
        #Make our new rule folder, should none exist
        if not os.path.isdir(self._path):
            os.mkdir(self._path)
        
        modificationspath = self._path + "/Modifications/"

        if not os.path.isdir(modificationspath):
            os.mkdir(modificationspath)
        
        """
        Write our base XML file for the Rewrite Rule
        """
        #Write our root head
        root = ET.Element('rule')
        root.attrib['name'] = self._rule.get_name()
        root.attrib['type'] = "Rewrite_Rule"

        if (self._rule.get_apply_once()):
            root.attrib['applyonce'] = 'true'
        else:
            root.attrib['applyonce'] = 'false'
            
        social_condition_name = self._rule.get_name() + "_Social_Condition"
        social_condition = ET.SubElement(root, 'socialcondition')
        social_condition.text = str(social_condition_name)
        
        story_condition_name = self._rule.get_name() + "_Story_Condition"
        story_condition = ET.SubElement(root, 'storycondition')
        story_condition.text = str(story_condition_name)
        
        story_modification_name = self._rule.get_name() + "_Story_Modification"
        story_modification = ET.SubElement(root, 'storymodification')
        story_modification.text = str(story_modification_name)
        
        
        #Write our xml to a file
        tree = ET.ElementTree(root)
        tree.write(self._path + "/" + self._rule.get_name() + ".xml")
        
        #Write the social graph
        social_condition_writer = XMLSocialGraphWriter(self._path + "/" + social_condition_name, self._rule.get_social_condition())
        social_condition_writer.writeGraph()
        
        story_condition_writer = XMLStoryGraphWriter(self._path + "/", story_condition_name, self._rule.get_story_condition())
        story_condition_writer.writeGraph()
        
        story_modification_writer = XMLStoryGraphWriter(self._path + "/", story_modification_name, self._rule.get_story_modification())
        story_modification_writer.writeGraph()
コード例 #3
0
ファイル: PrettyPrint.py プロジェクト: BenKybartas/ReGEN
#                     b.connect(node, {'Enemies' : 'Lawful'}, node_2)
#                     b.connect(node_2, {'Enemies' : 'Chaotic'}, node)
#                 elif node.get_attributes()['alignment_lnc'] == 'Chaotic' and node_2.get_attributes()['alignment_lnc'] == 'Chaotic':
#                     b.connect(node, {'Allies' : 'Chaotic'}, node_2)
#                 elif node.get_attributes()['alignment_lnc'] == 'Lawful' and node_2.get_attributes()['alignment_lnc'] == 'Lawful':
#                     b.connect(node, {'Allies' : 'Lawful'}, node_2)
#             if 'wealth' in node.get_attributes().keys() and 'wealth' in node_2.get_attributes().keys():
#                 if (node.get_attributes()['wealth'] == 'Rich' or node.get_attributes()['wealth'] == 'Wealthy') and node_2.get_attributes()['wealth'] == 'Poor':
#                     b.connect(node, {'Distrust' : 'Poor'}, node_2)
#                     b.connect(node_2, {'Distrust' : 'Rich'}, node)
#             if 'male' in node.get_attributes().keys() and 'male' in node_2.get_attributes().keys():
#                 if not node.get_attributes()['male'] == node_2.get_attributes()['male']:
#                     rand_num = random.randint(0, 10)
#                     if rand_num >= 5:
#                         if rand_num >= 8:
#                             b.connect(node, {'Desires' : 'Looks'}, node_2)
#                         else:
#                             b.connect(node, {'Repulsed' : 'Looks'}, node_2)

#b.plot('FantasyWorld')
#print "Done"

c = XMLSocialGraphWriter('../../Data/SocialGraphs/Fantasy_World_Autogen', b)
c.writeGraph()

xml = xml.dom.minidom.parse('../../Data/SocialGraphs/Fantasy_World_Autogen.xml')
pretty_xml = xml.toprettyxml()

f = open('../../Data/SocialGraphs/Fantasy_World_Improved_Autogen.xml', 'w')
f.write(pretty_xml)