From c2d7240688971b8ca9fa8da6142c908fbbd304ca Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sat, 29 May 2010 04:33:15 +0300 Subject: [PATCH] Subtitle library Useful for doing those subtitle scripts (rerecord counts, lengths and authors from the emulator). --- Changelog.utf8 | 5 +- build-files/start-jpcrr.bat | 2 +- build-files/start-jpcrr.sh | 2 +- lua/subtitles.lua | 144 +++++++++++++++++++++++++++++++++++++++ lua/subtitletest.lua | 23 +++++++ lua/textrender.lua | 2 +- org/jpc/j2se/JPCApplication.java | 2 +- 7 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 lua/subtitles.lua create mode 100644 lua/subtitletest.lua diff --git a/Changelog.utf8 b/Changelog.utf8 index c5fa8a9..aaf5992 100644 --- a/Changelog.utf8 +++ b/Changelog.utf8 @@ -1,5 +1,5 @@ -Changes since JPC-RR Release 10.8: -================================== +Changes from JPC-RR Release 10.8 to JPC-RR Release 10.9: +======================================================== - Redesign author editor dialog. - Fix some savestate errors. - Add support for author nicknames. @@ -10,6 +10,7 @@ Changes since JPC-RR Release 10.8: - Clean up Misc.parseString(). - Clean up ConstantTableLayout. - Keyboard layouts support and new default layout. +- Subtitle library. Changes from JPC-RR Release 10.7 to JPC-RR Release 10.8: ======================================================== diff --git a/build-files/start-jpcrr.bat b/build-files/start-jpcrr.bat index 74c966f..f8d470d 100644 --- a/build-files/start-jpcrr.bat +++ b/build-files/start-jpcrr.bat @@ -1 +1 @@ -java -jar jpcrr-r10.8.jar +java -jar jpcrr-r10.9.jar diff --git a/build-files/start-jpcrr.sh b/build-files/start-jpcrr.sh index 861d7f6..e25dda7 100755 --- a/build-files/start-jpcrr.sh +++ b/build-files/start-jpcrr.sh @@ -1,2 +1,2 @@ #!/bin/sh -java -jar jpcrr-r10.8.jar +java -jar jpcrr-r10.9.jar diff --git a/lua/subtitles.lua b/lua/subtitles.lua new file mode 100644 index 0000000..d38c74a --- /dev/null +++ b/lua/subtitles.lua @@ -0,0 +1,144 @@ +do + local old_set_font_file = set_font_file; + local old_text_metrics = text_metrics; + local old_render_text = render_text; + + + dofile("textrender.lua"); + + local new_set_font_file = set_font_file; + local new_text_metrics = text_metrics; + local new_render_text = render_text; + + font, err = io.open_arch_read("subtitle-font"); + if not font then + error("Can't open font: " .. err); + end + new_set_font_file(font); + + + set_font_file = old_set_font_file; + text_metrics = old_text_metrics; + render_text = old_render_text; + + tasvideos_subtitle_this_is_TAS = function() + return "This is a tool-assisted recording.\nFor details, visit http://TASVideos.org/"; + end + + tasvideos_subtitle_this_is_TAS_fast = function() + return "This was a tool-assisted recording.\nFor details, visit http://TASVideos.org/"; + end + + for_each_header = function(callback) + local headers = jpcrr.movie_headers(); + local hdrnum, hdr, ret; + + for hdrnum, hdr in ipairs(headers) do + ret = callback(hdr); + if(ret ~= nil) then + return ret; + end + end + end + + get_gamename = function() + return for_each_header(function(header) + if header[1] == "GAMENAME" then + return header[2]; + else + return nil; + end + end); + end + + get_authors = function(long_form) + local ret = {}; + local i; + + for_each_header(function(header) + if header[1] == "AUTHORS" or header[1] == "AUTHORNICKS" then + for i = 2, #header do + ret[#ret + 1] = header[i]; + end + elseif header[1] == "AUTHORFULL" then + if long_form then + ret[#ret + 1] = header[2]; + else + ret[#ret + 1] = header[3]; + end + end + end); + return ret; + end + + get_long_authors = function() + return get_authors(true); + end + + get_short_authors = function() + return get_authors(false); + end + + format_runtime = function() + local length = jpcrr.movie_length(); + local subseconds = length % 1000000000; + local seconds = (length - subseconds) / 1000000000; + subseconds = math.ceil(subseconds / 1000000); + local minutes = (seconds - seconds % 60) / 60; + seconds = seconds % 60; + local hours = (minutes - minutes % 60) / 60; + minutes = minutes % 60; + if hours > 0 then + return tostring(hours) .. ":" .. tostring(minutes) .. ":" .. tostring(seconds) .. "." .. tostring(subseconds); + else + return tostring(minutes) .. ":" .. tostring(seconds) .. "." .. tostring(subseconds); + end + end + + subtitle_runinfo = function() + + local w, h, x, y, wr, hr, old_w; + wr, hr = jpcrr.vga_resolution(); + + ret = (get_gamename() or "") .. " in " .. format_runtime() .. "\n"; + ret = ret .. "by "; + local k, v, rettmp; + for k, v in ipairs(get_short_authors()) do + if k > 1 then + ret = ret .. " & "; + end + rettmp = ret .. v; + old_w = w; + w, h = new_text_metrics(rettmp); + if w > 550 and w > old_w then + ret = ret .. "\n" .. v; + else + ret = rettmp; + end + end + ret = ret .. "\nRerecord count: " .. tostring(jpcrr.movie_rerecords()); + return ret; + end + + render_subtitle_text = function(text, to_top, fr, fg, fb, fa, br, bg, bb, ba) + + local w, h, x, y, wr, hr; + + w, h = new_text_metrics(text); + wr, hr = jpcrr.vga_resolution(); + x = math.floor((wr - w) / 2); + if to_top then + y = 0; + else + y = hr - h; + end + + new_render_text(3, x, y, text, false, fr, fg, fb, fa, br, bg, bb, ba); + end + +end + + +--- Title in hh:mm:ss.ss +--- by PlayerName +--- Rerecord count: number diff --git a/lua/subtitletest.lua b/lua/subtitletest.lua new file mode 100644 index 0000000..b0a0a93 --- /dev/null +++ b/lua/subtitletest.lua @@ -0,0 +1,23 @@ +dofile("subtitles.lua"); +print("Game:" .. (get_gamename() or "")); + +print("Short authors:"); +for k, v in ipairs(get_short_authors()) do + print(v); +end + +print(""); +print("Long authors:"); +for k, v in ipairs(get_long_authors()) do + print(v); +end + + +print(""); +info = subtitle_runinfo(); +print(info); + +while true do + jpcrr.next_frame(); + render_subtitle_text(info, true, 255, 255, 255); +end diff --git a/lua/textrender.lua b/lua/textrender.lua index fe4bed6..1941cfa 100644 --- a/lua/textrender.lua +++ b/lua/textrender.lua @@ -73,7 +73,7 @@ local load_codepoint = function(codepoint) metric_w = w1; l = #raw - 1; end - metric_h = (l - l % metric_w) / metric_w; + metric_h = ((8 * l) - (8 * l) % metric_w) / metric_w; bitmap = raw; end file2:close(); diff --git a/org/jpc/j2se/JPCApplication.java b/org/jpc/j2se/JPCApplication.java index 545ff7c..0c69179 100644 --- a/org/jpc/j2se/JPCApplication.java +++ b/org/jpc/j2se/JPCApplication.java @@ -373,7 +373,7 @@ public class JPCApplication System.err.println("Warning: System Look-and-Feel not loaded" + e.getMessage()); } - System.out.println("JPC-RR: Rerecording PC emulator based on JPC PC emulator. Release 10.8"); + System.out.println("JPC-RR: Rerecording PC emulator based on JPC PC emulator. Release 10.9"); System.out.println("Revision: " + getRevision()); System.out.println("Based on JPC PC emulator."); System.out.println("Copyright (C) 2007-2009 Isis Innovation Limited"); -- 2.11.4.GIT