From 923844fdc78591c455eda8e4539e4695181d89a4 Mon Sep 17 00:00:00 2001 From: Joni Savolainen Date: Mon, 1 Feb 2021 21:57:54 +0200 Subject: [PATCH] Remove SpriteWindowCursorRect & fix WindowCursorRect (#85) * Remove SpriteWindowCursorRect * Fix WindowCursorRect - Use super - Don't overwrite getters for x, y etc. - Use self.x instead of @x, etc. * Fix needs_update? using zeroes * Rename WindowCursorRect#isEmpty? to #empty? --- .../009_Objects and windows/003_Window.rb | 60 +++++++++--------- .../004_SpriteWindow.rb | 61 +------------------ 2 files changed, 29 insertions(+), 92 deletions(-) diff --git a/Data/Scripts/009_Objects and windows/003_Window.rb b/Data/Scripts/009_Objects and windows/003_Window.rb index 5a14e1d27..0bd0a6f01 100644 --- a/Data/Scripts/009_Objects and windows/003_Window.rb +++ b/Data/Scripts/009_Objects and windows/003_Window.rb @@ -1,59 +1,55 @@ class WindowCursorRect < Rect def initialize(window) - @window=window - @x=0 - @y=0 - @width=0 - @height=0 + super(0, 0, 0, 0) + @window = window end - attr_reader :x,:y,:width,:height - def empty - needupdate=@x!=0 || @y!=0 || @width!=0 || @height!=0 - if needupdate - @x=0 - @y=0 - @width=0 - @height=0 - @window.width=@window.width - end + return unless needs_update?(0, 0, 0, 0) + + set(0, 0, 0, 0) end - def isEmpty? - return @x==0 && @y==0 && @width==0 && @height==0 + def empty? + return self.x == 0 && self.y == 0 && self.width == 0 && self.height == 0 end - def set(x,y,width,height) - needupdate=@x!=x || @y!=y || @width!=width || @height!=height - if needupdate - @x=x - @y=y - @width=width - @height=height - @window.width=@window.width - end + def set(x, y, width, height) + return unless needs_update?(x, y, width, height) + + super(x, y, width, height) + + @window.width = @window.width end def height=(value) - @height=value; @window.width=@window.width + super(value) + @window.width = @window.width end def width=(value) - @width=value; @window.width=@window.width + super(value) + @window.width = @window.width end def x=(value) - @x=value; @window.width=@window.width + super(value) + @window.width = @window.width end def y=(value) - @y=value; @window.width=@window.width + super(value) + @window.width = @window.width + end + + private + + def needs_update?(x, y, width, height) + return self.x != x || self.y != y || self.width != width || self.height != height end end - class Window attr_reader :tone attr_reader :color @@ -309,7 +305,7 @@ class Window @cursoropacity+=8 @cursorblink=0 if @cursoropacity>=255 end - mustchange=true if !@cursor_rect.isEmpty? + mustchange=true if !@cursor_rect.empty? else mustchange=true if @cursoropacity!=128 @cursoropacity=128 diff --git a/Data/Scripts/009_Objects and windows/004_SpriteWindow.rb b/Data/Scripts/009_Objects and windows/004_SpriteWindow.rb index e4b2bae4a..a0febcb78 100644 --- a/Data/Scripts/009_Objects and windows/004_SpriteWindow.rb +++ b/Data/Scripts/009_Objects and windows/004_SpriteWindow.rb @@ -1,62 +1,3 @@ -#=============================================================================== -# -#=============================================================================== -class SpriteWindowCursorRect < Rect - def initialize(window) - @window=window - @x=0 - @y=0 - @width=0 - @height=0 - end - - attr_reader :x,:y,:width,:height - - def empty - needupdate=@x!=0 || @y!=0 || @width!=0 || @height!=0 - if needupdate - @x=0 - @y=0 - @width=0 - @height=0 - @window.width=@window.width - end - end - - def isEmpty? - return @x==0 && @y==0 && @width==0 && @height==0 - end - - def set(x,y,width,height) - needupdate=@x!=x || @y!=y || @width!=width || @height!=height - if needupdate - @x=x - @y=y - @width=width - @height=height - @window.width=@window.width - end - end - - def height=(value) - @height=value; @window.width=@window.width - end - - def width=(value) - @width=value; @window.width=@window.width - end - - def x=(value) - @x=value; @window.width=@window.width - end - - def y=(value) - @y=value; @window.width=@window.width - end -end - - - #=============================================================================== # SpriteWindow is a class based on Window which emulates Window's functionality. # This class is necessary in order to change the viewport of windows (with @@ -156,7 +97,7 @@ class SpriteWindow < Window @blend_type=0 @contents_blend_type=0 @contents_opacity=255 - @cursor_rect=SpriteWindowCursorRect.new(self) + @cursor_rect=WindowCursorRect.new(self) @cursorblink=0 @cursoropacity=255 @pause=false