Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
2.7 kB · 72 lines
Java
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273package TemplateCompiler;
import java.util.ArrayList;import java.util.LinkedList;import java.util.List;
import facade.util.PrintUtilities;
/** * Remembers the last few lines Trip and Grace were told to speak. * * Written by the character threads (via the patched Push*DialogAnimation acts) * and read by the NLU thread when the player types, hence the locking. Java 1.4 * only: see the note in JevBridge. No inner classes, so the patch stays one * class file per source file. */public final class JevDialogueLog { private static final int MAX_LINES = 4; private static final long MAX_AGE_MS = 45000L; /** Entries are Object[] { String scriptName, Long timeSpoken }. */ private static final LinkedList lines = new LinkedList();
private JevDialogueLog() { }
/** scriptIds are the act's Integer arguments; -1 marks an unused slot. */ public static void record(int character, Object[] scriptIds) { try { Long now = new Long(System.currentTimeMillis()); // Resolve names before taking the lock: no game code runs under it. List spoken = new ArrayList(); for (int i = 0; i < scriptIds.length; i++) { int id = ((Integer) scriptIds[i]).intValue(); if (id == -1) { continue; } String name = PrintUtilities.dialogScript_EnumToString(character, id); if (name == null || name.length() == 0) { continue; } // The game's helper strips the "etripScript_dialog_" prefix, // so say who spoke: "TRIP|FASKDRINKT1NTPA_how1_does_a_...". spoken.add(new StringBuffer(character == 1 ? "TRIP|" : "GRACE|").append(name).toString()); } synchronized (lines) { for (int i = 0; i < spoken.size(); i++) { lines.addLast(new Object[] { spoken.get(i), now }); } while (lines.size() > MAX_LINES) { lines.removeFirst(); } } } catch (Throwable ignored) { // Never let bookkeeping break a line of dialogue. } }
/** Script names of recent lines, oldest first. */ public static List recent() { List names = new ArrayList(); long cutoff = System.currentTimeMillis() - MAX_AGE_MS; synchronized (lines) { for (int i = 0; i < lines.size(); i++) { Object[] line = (Object[]) lines.get(i); if (((Long) line[1]).longValue() >= cutoff) { names.add(line[0]); } } } return names; }}