def DeleteChoice(node: ChoiceNode): if len(node.outcomes) < 1: return choices = node.getOutcomesAsObjects() altDeleteChoice = CreateNewPrompt(edit.DeleteChoice) EditPrompt(altDeleteChoice, 0, 'choices', choices) values: dict = prompt(altDeleteChoice) node.deleteOutcome(values['Index'], OnDelete(values['OnDelete']))
def EditChoice(node: ChoiceNode): if len(node.outcomes) < 1: return choices = node.getOutcomesAsObjects() altEditChoice = CreateNewPrompt(edit.EditChoice) EditPrompt(altEditChoice, 0, 'choices', choices) values: dict = prompt(altEditChoice) node.editOutcome(values['Index'], values['Value'])
def InitEditor(): editManager: EditManager = None newOrEdit = prompt(edit.NewOrEditChoice) # Create new if newOrEdit['NewOrEditChoice'] == '1': newStory = prompt(edit.CreateStory) editManager = EditManager(newStory['Name'], newStory['Path'], newStory['Description'], ChoiceNode(None, newStory['FirstNarration'])) # Edit existing else: while True: result = prompt(utils.SelectFile) if os.path.exists(result['Value']) and \ os.path.isfile(result['Value']): break else: print('Error: Invalid path provided.', ' Needs to be a valid file') editManager = LoadEditManager(result['Value']) if editManager is None: print(f'Error: could not load story file {result["Value"]}') return None editManager.currentNode = editManager.startNode return editManager
def multipleChoiceNode(): node: ChoiceNode = ChoiceNode('One') node.addOutcome('Two') node.addOutcome('Three') node.outcomes[0].addOutcome('Four') node.outcomes[0].addOutcome('Five') node.outcomes[1].addOutcome('Six') node.outcomes[1].addOutcome('Seven') return node
def EditNarration(node: ChoiceNode): altEditNarration = CreateNewPrompt(edit.EditNarration) EditPrompt(altEditNarration, 0, 'default', node.narration) userInput = prompt(altEditNarration) value = userInput['Value'] if len(value) > 0: node.narration = value else: print('Error: cannot set narration to an empty value.\n')
def test_seralization(): node = ChoiceNode('Text') src: EditManager = EditManager('TestName', './', 'Desc', node) path = src.storyPath + '/' + src.storyName + '.test.his' SerializeEditManager(src, path) dst: EditManager = LoadEditManager(path) assert src.storyName == dst.storyName assert src.storyPath == dst.storyPath assert src.storyDesc == dst.storyDesc assert src.startNode.choiceText == dst.startNode.choiceText assert len(src.startNode.outcomes) == len(dst.startNode.outcomes) os.remove(path)
def emptyManager(): node: ChoiceNode = ChoiceNode('Text') manager: EditManager = EditManager('Name', './', 'Desc', node) return manager
def AddChoice(node: ChoiceNode): choiceText: dict = prompt(edit.AddChoice) node.addOutcome(choiceText['Value'])
def ConfirmNode(node: ChoiceNode): if node.outcomes is None or len(node.outcomes) < 1: value: dict = prompt(edit.AddDefaultChoice) if value['Value'] == 0: node.addOutcome('Continue...')
def testNode(): node: ChoiceNode = ChoiceNode(testName, testNarration) return node
def emptyNode(): node: ChoiceNode = ChoiceNode(testName) return node