mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
Updated mkxp-z to 2.2.0, added support for animated gifs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Using mkxp-z v2.1.2 - https://gitlab.com/mkxp-z/mkxp-z/-/releases/v2.1.2
|
||||
# Using mkxp-z v2.2.0 - https://gitlab.com/mkxp-z/mkxp-z/-/releases/v2.2.0
|
||||
$VERBOSE = nil
|
||||
Font.default_shadow = false if Font.respond_to?(:default_shadow)
|
||||
Graphics.frame_rate = 40
|
||||
|
||||
@@ -280,10 +280,10 @@ end
|
||||
# Note: pbGetFileChar checks anything added in MKXP's RTP setting,
|
||||
# and matching mount points added through System.mount
|
||||
def pbRgssExists?(filename)
|
||||
filename = canonicalize(filename)
|
||||
if safeExists?("./Game.rgssad")
|
||||
return pbGetFileChar(filename)!=nil
|
||||
else
|
||||
filename = canonicalize(filename)
|
||||
return safeExists?(filename)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -103,6 +103,7 @@ module RPG
|
||||
end
|
||||
|
||||
|
||||
|
||||
class BitmapWrapper < Bitmap
|
||||
attr_reader :refcount
|
||||
attr_accessor :never_dispose
|
||||
|
||||
@@ -1,35 +1,6 @@
|
||||
# Disabling animated GIF stuff because gif.dll is awful,
|
||||
# but leaving the code here just in case someone wants
|
||||
# to make Linux and macOS versions of it for some reason
|
||||
=begin
|
||||
module GifLibrary
|
||||
@@loadlib = Win32API.new("Kernel32.dll", "LoadLibrary", 'p', '')
|
||||
if safeExists?("gif.dll")
|
||||
PngDll = @@loadlib.call("gif.dll")
|
||||
GifToPngFiles = Win32API.new("gif.dll", "GifToPngFiles", 'pp', 'l')
|
||||
GifToPngFilesInMemory = Win32API.new("gif.dll", "GifToPngFilesInMemory", 'plp', 'l')
|
||||
CopyDataString = Win32API.new("gif.dll", "CopyDataString", 'lpl', 'l')
|
||||
FreeDataString = Win32API.new("gif.dll", "FreeDataString", 'l', '')
|
||||
else
|
||||
PngDll = nil
|
||||
end
|
||||
|
||||
def self.getDataFromResult(result)
|
||||
datasize = CopyDataString.call(result, "", 0)
|
||||
ret = nil
|
||||
if datasize != 0
|
||||
data = "0" * datasize
|
||||
CopyDataString.call(result, data, datasize)
|
||||
ret = data.unpack("V*")
|
||||
end
|
||||
FreeDataString.call(result)
|
||||
return ret
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class AnimatedBitmap
|
||||
def initialize(file, hue = 0)
|
||||
raise "Filename is nil (missing graphic)." if file.nil?
|
||||
@@ -54,7 +25,6 @@ class AnimatedBitmap
|
||||
def each; @bitmap.each { |item| yield item }; end
|
||||
def bitmap; @bitmap.bitmap; end
|
||||
def currentIndex; @bitmap.currentIndex; end
|
||||
def frameDelay; @bitmap.frameDelay; end
|
||||
def totalFrames; @bitmap.totalFrames; end
|
||||
def disposed?; @bitmap.disposed?; end
|
||||
def update; @bitmap.update; end
|
||||
@@ -63,8 +33,9 @@ class AnimatedBitmap
|
||||
def copy; @bitmap.copy; end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class PngAnimatedBitmap
|
||||
attr_accessor :frames
|
||||
|
||||
@@ -170,138 +141,51 @@ class PngAnimatedBitmap
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#internal class
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class GifBitmap
|
||||
attr_accessor :gifbitmaps # internal
|
||||
attr_accessor :gifdelays # internal
|
||||
attr_accessor :bitmap
|
||||
|
||||
# Creates a bitmap from a GIF file with the specified
|
||||
# optional viewport. Can also load non-animated bitmaps.
|
||||
# Creates a bitmap from a GIF file. Can also load non-animated bitmaps.
|
||||
def initialize(dir, filename, hue = 0)
|
||||
@gifbitmaps = []
|
||||
@gifdelays = []
|
||||
@totalframes = 0
|
||||
@framecount = 0
|
||||
@currentIndex = 0
|
||||
@disposed = false
|
||||
bitmap = nil
|
||||
filestring = nil
|
||||
filestrName = nil
|
||||
filename = "" if !filename
|
||||
full_path = canonicalize(dir + filename)
|
||||
@bitmap = nil
|
||||
@disposed = false
|
||||
filename = "" if !filename
|
||||
begin
|
||||
bitmap = RPG::Cache.load_bitmap(dir, filename, hue)
|
||||
@bitmap = RPG::Cache.load_bitmap(dir, filename, hue)
|
||||
rescue
|
||||
bitmap = nil
|
||||
end
|
||||
if !bitmap || (bitmap.width == 32 && bitmap.height == 32)
|
||||
if !full_path || full_path.length < 1 || full_path[full_path.length - 1] != 0x2F
|
||||
if (filestring = pbGetFileChar(full_path))
|
||||
filestrName = full_path
|
||||
elsif (filestring = pbGetFileChar(full_path + ".gif"))
|
||||
filestrName = full_path + ".gif"
|
||||
elsif (filestring = pbGetFileChar(full_path + ".png"))
|
||||
filestrName = full_path + ".png"
|
||||
# elsif (filestring = pbGetFileChar(full_path + ".jpg"))
|
||||
# filestrName = full_path + ".jpg"
|
||||
# elsif (filestring = pbGetFileChar(full_path + ".bmp"))
|
||||
# filestrName = full_path + ".bmp"
|
||||
end
|
||||
end
|
||||
end
|
||||
if bitmap && filestring && filestring[0].ord == 0x47 &&
|
||||
bitmap.width == 32 && bitmap.height == 32
|
||||
# File.open("debug.txt","ab") { |f| f.puts("rejecting bitmap") }
|
||||
bitmap.dispose
|
||||
bitmap = nil
|
||||
end
|
||||
# Note: MKXP can open .gif files just fine, first frame only
|
||||
if bitmap
|
||||
# File.open("debug.txt","ab") { |f| f.puts("reusing bitmap") }
|
||||
# Have a regular non-animated bitmap
|
||||
@totalframes = 1
|
||||
@framecount = 0
|
||||
@gifbitmaps = [bitmap]
|
||||
@gifdelays = [1]
|
||||
else
|
||||
=begin
|
||||
tmpBase = File.basename(full_path) + "_tmp_"
|
||||
filestring = pbGetFileString(filestrName) if filestring
|
||||
Dir.chdir(ENV["TEMP"]) { # navigate to temp folder since game might be on a CD-ROM
|
||||
if filestring && filestring[0] == 0x47 && GifLibrary::PngDll
|
||||
result = GifLibrary::GifToPngFilesInMemory.call(filestring,
|
||||
filestring.length, tmpBase)
|
||||
else
|
||||
result = 0
|
||||
end
|
||||
if result >0
|
||||
@gifdelays = GifLibrary.getDataFromResult(result)
|
||||
@totalframes = @gifdelays.pop
|
||||
for i in 0...@gifdelays.length
|
||||
@gifdelays[i] = [@gifdelays[i], 1].max
|
||||
bmfile = sprintf("%s%d.png", tmpBase, i)
|
||||
if safeExists?(bmfile)
|
||||
gifbitmap = BitmapWrapper.new(bmfile)
|
||||
@gifbitmaps.push(gifbitmap)
|
||||
bmfile.hue_change(hue) if hue != 0
|
||||
if hue == 0 && @gifdelays.length == 1
|
||||
RPG::Cache.setKey(full_path, gifbitmap)
|
||||
end
|
||||
File.delete(bmfile)
|
||||
else
|
||||
@gifbitmaps.push(BitmapWrapper.new(32, 32))
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
=end
|
||||
if @gifbitmaps.length == 0
|
||||
@gifbitmaps = [BitmapWrapper.new(32, 32)]
|
||||
@gifdelays = [1]
|
||||
end
|
||||
if @gifbitmaps.length == 1
|
||||
RPG::Cache.setKey(full_path, @gifbitmaps[0])
|
||||
end
|
||||
@bitmap = nil
|
||||
end
|
||||
@bitmap = BitmapWrapper.new(32, 32) if @bitmap.nil?
|
||||
@bitmap.play if @bitmap&.animated?
|
||||
end
|
||||
|
||||
def [](index)
|
||||
return @gifbitmaps[index]
|
||||
def [](_index)
|
||||
return @bitmap
|
||||
end
|
||||
|
||||
def deanimate
|
||||
for i in 1...@gifbitmaps.length
|
||||
@gifbitmaps[i].dispose
|
||||
end
|
||||
@gifbitmaps = [@gifbitmaps[0]]
|
||||
@currentIndex = 0
|
||||
return @gifbitmaps[0]
|
||||
end
|
||||
|
||||
def bitmap
|
||||
return @gifbitmaps[@currentIndex]
|
||||
@bitmap&.goto_and_stop(0) if @bitmap&.animated?
|
||||
return @bitmap
|
||||
end
|
||||
|
||||
def currentIndex
|
||||
return @currentIndex
|
||||
end
|
||||
|
||||
def frameDelay(index)
|
||||
return @gifdelay[index] / 2 # Due to frame count being incremented by 2
|
||||
return @bitmap&.current_frame || 0
|
||||
end
|
||||
|
||||
def length
|
||||
return @gifbitmaps.length
|
||||
return @bitmap&.frame_count || 1
|
||||
end
|
||||
|
||||
def each
|
||||
@gifbitmaps.each { |item| yield item }
|
||||
yield @bitmap
|
||||
end
|
||||
|
||||
def totalFrames
|
||||
return @totalframes / 2 # Due to frame count being incremented by 2
|
||||
f_rate = @bitmap.frame_rate
|
||||
f_rate = 1 if f_rate.nil? || f_rate == 0
|
||||
return (@bitmap) ? (@bitmap.frame_count / f_rate).floor : 1
|
||||
end
|
||||
|
||||
def disposed?
|
||||
@@ -309,47 +193,32 @@ class GifBitmap
|
||||
end
|
||||
|
||||
def width
|
||||
return (@gifbitmaps.length == 0) ? 0 : @gifbitmaps[0].width
|
||||
return @bitmap&.width || 0
|
||||
end
|
||||
|
||||
def height
|
||||
return (@gifbitmaps.length == 0) ? 0 : @gifbitmaps[0].height
|
||||
return @bitmap&.height || 0
|
||||
end
|
||||
|
||||
# This function must be called in order to animate the GIF image.
|
||||
def update
|
||||
return if disposed?
|
||||
if @gifbitmaps.length > 0
|
||||
@framecount += 2
|
||||
@framecount = (@totalframes <= 0) ? 0 : @framecount % @totalframes
|
||||
frametoshow = 0
|
||||
for i in 0...@gifdelays.length
|
||||
frametoshow = i if @gifdelays[i] <= @framecount
|
||||
end
|
||||
@currentIndex = frametoshow
|
||||
end
|
||||
end
|
||||
# Gifs are animated automatically by mkxp-z. This function does nothing.
|
||||
def update; end
|
||||
|
||||
def dispose
|
||||
if !@disposed
|
||||
@gifbitmaps.each { |b| b.dispose }
|
||||
end
|
||||
return if @disposed
|
||||
@bitmap.dispose
|
||||
@disposed = true
|
||||
end
|
||||
|
||||
def copy
|
||||
x = self.clone
|
||||
x.gifbitmaps = x.gifbitmaps.clone
|
||||
x.gifdelays = x.gifdelays.clone
|
||||
for i in 0...x.gifbitmaps.length
|
||||
x.gifbitmaps[i] = x.gifbitmaps[i].copy
|
||||
end
|
||||
x.bitmap = @bitmap.copy if @bitmap
|
||||
return x
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def pbGetTileBitmap(filename, tile_id, hue, width = 1, height = 1)
|
||||
return RPG::Cache.tileEx(filename, tile_id, hue, width, height) { |f|
|
||||
AnimatedBitmap.new("Graphics/Tilesets/" + filename).deanimate
|
||||
|
||||
Reference in New Issue
Block a user