Search in sources :

Example 31 with Response

use of com.lilithsthrone.game.dialogue.responses.Response in project liliths-throne-public by Innoxia.

the class Game method exportGame.

public static void exportGame(String exportFileName, boolean allowOverwrite) {
    File dir = new File("data/");
    dir.mkdir();
    dir = new File("data/saves");
    dir.mkdir();
    boolean overwrite = false;
    if (dir.isDirectory()) {
        File[] directoryListing = dir.listFiles((path, filename) -> filename.endsWith(".xml"));
        if (directoryListing != null) {
            for (File child : directoryListing) {
                if (child.getName().equals(exportFileName + ".xml")) {
                    if (!allowOverwrite) {
                        Main.game.flashMessage(Colour.GENERIC_BAD, "Name already exists!");
                        return;
                    } else {
                        overwrite = true;
                    }
                }
            }
        }
    }
    try {
        if (timeLog) {
            timeStart = System.nanoTime();
            System.out.println(timeStart);
        }
        // Starting stuff:
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document doc = docBuilder.newDocument();
        // Writing game stuff to export:
        Element game = doc.createElement("game");
        doc.appendChild(game);
        Element informationNode = doc.createElement("coreInfo");
        game.appendChild(informationNode);
        CharacterUtils.addAttribute(doc, informationNode, "version", Main.VERSION_NUMBER);
        CharacterUtils.addAttribute(doc, informationNode, "minutesPassed", String.valueOf(Main.game.minutesPassed));
        CharacterUtils.addAttribute(doc, informationNode, "debugMode", String.valueOf(Main.game.debugMode));
        CharacterUtils.addAttribute(doc, informationNode, "imperialMeasurements", String.valueOf(Main.game.imperialMeasurements));
        CharacterUtils.addAttribute(doc, informationNode, "weather", Main.game.currentWeather.toString());
        CharacterUtils.addAttribute(doc, informationNode, "nextStormTime", String.valueOf(Main.game.nextStormTime));
        CharacterUtils.addAttribute(doc, informationNode, "weatherTimeRemaining", String.valueOf(Main.game.weatherTimeRemaining));
        Element dateNode = doc.createElement("date");
        informationNode.appendChild(dateNode);
        CharacterUtils.addAttribute(doc, dateNode, "year", String.valueOf(Main.game.startingDate.getYear()));
        CharacterUtils.addAttribute(doc, dateNode, "month", String.valueOf(Main.game.startingDate.getMonthValue()));
        CharacterUtils.addAttribute(doc, dateNode, "dayOfMonth", String.valueOf(Main.game.startingDate.getDayOfMonth()));
        CharacterUtils.addAttribute(doc, dateNode, "hour", String.valueOf(Main.game.startingDate.getHour()));
        CharacterUtils.addAttribute(doc, dateNode, "minute", String.valueOf(Main.game.startingDate.getMinute()));
        Main.game.dialogueFlags.saveAsXML(game, doc);
        Element eventLogNode = doc.createElement("eventLog");
        game.appendChild(eventLogNode);
        for (EventLogEntry event : Main.game.getEventLog().subList(Math.max(0, Main.game.getEventLog().size() - 50), Main.game.getEventLog().size())) {
            event.saveAsXML(eventLogNode, doc);
        }
        Element slaveryEventLogNode = doc.createElement("slaveryEventLog");
        game.appendChild(slaveryEventLogNode);
        for (int day : Main.game.getSlaveryEventLog().keySet()) {
            Element element = doc.createElement("day");
            slaveryEventLogNode.appendChild(element);
            CharacterUtils.addAttribute(doc, element, "value", String.valueOf(day));
            for (SlaveryEventLogEntry event : Main.game.getSlaveryEventLog().get(day)) {
                event.saveAsXML(element, doc);
            }
        }
        // Add maps:
        Element mapNode = doc.createElement("maps");
        game.appendChild(mapNode);
        for (World world : Main.game.getWorlds().values()) {
            if (world != null) {
                world.saveAsXML(mapNode, doc);
            }
        }
        // Add player:
        Element characterNode = doc.createElement("playerCharacter");
        game.appendChild(characterNode);
        Main.game.getPlayer().saveAsXML(characterNode, doc);
        // Add all NPCs:
        for (GameCharacter character : Main.game.getNPCMap().values()) {
            characterNode = doc.createElement("NPC");
            game.appendChild(characterNode);
            character.saveAsXML(characterNode, doc);
        }
        // Ending stuff:
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer1 = tf.newTransformer();
        transformer1.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        StringWriter writer = new StringWriter();
        transformer1.transform(new DOMSource(doc), new StreamResult(writer));
        // Save this xml:
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        DOMSource source = new DOMSource(doc);
        String saveLocation = "data/saves/" + exportFileName + ".xml";
        StreamResult result = new StreamResult(new File(saveLocation));
        transformer.transform(source, result);
        if (!exportFileName.startsWith("AutoSave")) {
            if (overwrite) {
                Main.game.addEvent(new EventLogEntry(Main.game.getMinutesPassed(), "[style.colourGood(Game saved)]", saveLocation), false);
                Main.game.setContent(new Response("", "", Main.game.getCurrentDialogueNode()), false, Colour.GENERIC_GOOD, "Save game overwritten!");
            } else {
                Main.game.addEvent(new EventLogEntry(Main.game.getMinutesPassed(), "[style.colourGood(Game saved)]", saveLocation), false);
                Main.game.setContent(new Response("", "", Main.game.getCurrentDialogueNode()), false, Colour.GENERIC_GOOD, "Game saved!");
            }
        }
        if (timeLog) {
            System.out.println("Difference: " + (System.nanoTime() - timeStart) / 1000000000f);
        }
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (TransformerException tfe) {
        tfe.printStackTrace();
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) EventLogEntry(com.lilithsthrone.game.dialogue.eventLog.EventLogEntry) SlaveryEventLogEntry(com.lilithsthrone.game.dialogue.eventLog.SlaveryEventLogEntry) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) World(com.lilithsthrone.world.World) Response(com.lilithsthrone.game.dialogue.responses.Response) StringWriter(java.io.StringWriter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) GameCharacter(com.lilithsthrone.game.character.GameCharacter) SlaveryEventLogEntry(com.lilithsthrone.game.dialogue.eventLog.SlaveryEventLogEntry) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 32 with Response

use of com.lilithsthrone.game.dialogue.responses.Response in project liliths-throne-public by Innoxia.

the class Game method getResponsesDiv.

private String getResponsesDiv(DialogueNodeOld node, boolean withPointerReset) {
    if (withPointerReset) {
        resetResponsePointer();
    }
    choicesDialogueSB = new StringBuilder();
    choicesDialogueSB.append("<div id='RESPONSE_BOX'>");
    if (node.getResponseTabTitle(0) != null && !node.getResponseTabTitle(0).isEmpty()) {
        choicesDialogueSB.append("<div class='response-container tabs'>");
        int responsePageCounter = 0;
        while (node.getResponseTabTitle(responsePageCounter) != null) {
            choicesDialogueSB.append("<div class='response-tab" + (responseTab == responsePageCounter ? " selected'" : "'") + (isResponseTabEmpty(node, responsePageCounter) ? "style='color:" + Colour.TEXT_GREY.toWebHexString() + ";'" : (responseTab == responsePageCounter ? "" : "style='color:" + Colour.TEXT_HALF_GREY.toWebHexString() + ";'")) + " id='tab_" + responsePageCounter + "'>" + (responsePageCounter == responseTab - 1 ? "<b class='hotkey-icon'>" + (Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_PREVIOUS_TAB) == null ? "" : Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_PREVIOUS_TAB).getFullName()) + "</b>" : (responsePageCounter == responseTab + 1 ? "<b class='hotkey-icon'>" + (Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_NEXT_TAB) == null ? "" : Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_NEXT_TAB).getFullName()) + "</b>" : "")) + // + (responseTab==responsePageCounter+1?"<b class='hotkey-icon'>" + KeyboardAction.RESPOND_PREVIOUS_PAGE + "</b>" : "" )
            node.getResponseTabTitle(responsePageCounter) + "</div>");
            responsePageCounter++;
        }
        choicesDialogueSB.append("</div>");
    } else {
        responseTab = 0;
    }
    choicesDialogueSB.append("<div class='response-full-container'>");
    if (responsePage > 0) {
        choicesDialogueSB.append("<div class='response-switcher left' id='switch_left'><b class='hotkey-icon'>" + (Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_PREVIOUS_PAGE) == null ? "" : Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_PREVIOUS_PAGE).getFullName()) + "</b>&#60</div>");
    } else {
        choicesDialogueSB.append("<div class='response-switcher left disabled' id='switch_left'><b class='hotkey-icon disabled'>" + (Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_PREVIOUS_PAGE) == null ? "" : Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_PREVIOUS_PAGE).getFullName()) + "</b><span class='option-disabled'>&#60</span></div>");
    }
    choicesDialogueSB.append("<div class='response-container'>");
    Response response;
    if (responsePage == 0) {
        for (int i = 1; i < MainController.RESPONSE_COUNT; i++) {
            response = node.getResponse(responseTab, i);
            if (response != null) {
                choicesDialogueSB.append(getResponseBoxDiv(response, i));
            } else
                choicesDialogueSB.append("<div class='response-box disabled" + (responsePointer == i ? " selected" : "") + "' id='option_" + i + "'>" + "<b class='hotkey-icon disabled'>" + getResponseHotkey(i) + "</b>" + "</div>");
        }
        response = node.getResponse(responseTab, 0);
        if (response != null) {
            choicesDialogueSB.append(getResponseBoxDiv(response, 0));
        } else
            choicesDialogueSB.append("<div class='response-box disabled" + (responsePointer == 0 ? " selected" : "") + "' id='option_0'>" + "<b class='hotkey-icon disabled'>" + getResponseHotkey(0) + "</b>" + "</div>");
    } else {
        for (int i = 0; i < (MainController.RESPONSE_COUNT - 1); i++) {
            response = node.getResponse(responseTab, i + (responsePage * MainController.RESPONSE_COUNT));
            if (response != null) {
                choicesDialogueSB.append(getResponseBoxDiv(response, i + 1));
            } else {
                choicesDialogueSB.append("<div class='response-box disabled" + (responsePointer - (responsePage * MainController.RESPONSE_COUNT) == i ? " selected" : "") + "' id='option_" + (i + 1) + "'>" + "<b class='hotkey-icon disabled'>" + getResponseHotkey(i + 1) + "</b>" + "</div>");
            }
        }
        response = node.getResponse(responseTab, MainController.RESPONSE_COUNT - 1 + (responsePage * MainController.RESPONSE_COUNT));
        if (response != null) {
            choicesDialogueSB.append(getResponseBoxDiv(response, 0));
        } else {
            choicesDialogueSB.append("<div class='response-box disabled" + (responsePointer - ((responsePage + 1) * MainController.RESPONSE_COUNT) + 1 == 0 ? " selected" : "") + "' id='option_0'>" + "<b class='hotkey-icon disabled'>" + getResponseHotkey(0) + "</b>" + "</div>");
        }
    }
    choicesDialogueSB.append("</div>");
    if (node.getResponse(responseTab, ((responsePage + 1) * MainController.RESPONSE_COUNT)) != null) {
        choicesDialogueSB.append("<div class='response-switcher right' id='switch_right'><b class='hotkey-icon'>" + (Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_NEXT_PAGE) == null ? "" : Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_NEXT_PAGE).getFullName()) + "</b>" + "&#62</div>");
    } else {
        choicesDialogueSB.append("<div class='response-switcher right disabled' id='switch_right'><b class='hotkey-icon disabled'>" + (Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_NEXT_PAGE) == null ? "" : Main.getProperties().hotkeyMapPrimary.get(KeyboardAction.RESPOND_NEXT_PAGE).getFullName()) + "</b><span class='option-disabled'>&#62</span></div>");
    }
    choicesDialogueSB.append("</div>");
    choicesDialogueSB.append("</div>");
    return choicesDialogueSB.toString();
}
Also used : Response(com.lilithsthrone.game.dialogue.responses.Response)

Aggregations

Response (com.lilithsthrone.game.dialogue.responses.Response)32 DialogueNodeOld (com.lilithsthrone.game.dialogue.DialogueNodeOld)9 ListValue (com.lilithsthrone.utils.Util.ListValue)7 File (java.io.File)7 EventTarget (org.w3c.dom.events.EventTarget)7 TestNPC (com.lilithsthrone.game.character.npc.dominion.TestNPC)6 Vector2i (com.lilithsthrone.utils.Vector2i)6 GameCharacter (com.lilithsthrone.game.character.GameCharacter)5 NPC (com.lilithsthrone.game.character.npc.NPC)5 ResponseEffectsOnly (com.lilithsthrone.game.dialogue.responses.ResponseEffectsOnly)5 Fetish (com.lilithsthrone.game.character.fetishes.Fetish)4 GenericAndrogynousNPC (com.lilithsthrone.game.character.npc.GenericAndrogynousNPC)4 GenericFemaleNPC (com.lilithsthrone.game.character.npc.GenericFemaleNPC)4 GenericMaleNPC (com.lilithsthrone.game.character.npc.GenericMaleNPC)4 InventorySelectedItemEventListener (com.lilithsthrone.controller.eventListeners.InventorySelectedItemEventListener)3 InventoryTooltipEventListener (com.lilithsthrone.controller.eventListeners.InventoryTooltipEventListener)3 TooltipInformationEventListener (com.lilithsthrone.controller.eventListeners.TooltipInformationEventListener)3 Game (com.lilithsthrone.game.Game)3 WorldType (com.lilithsthrone.world.WorldType)3 ArrayList (java.util.ArrayList)3