RMXP MACL 2.4 (bug-fixing the previous version)

Started by Wecoc, September 10, 2014, 07:02:52 pm

Previous topic - Next topic

Wecoc

September 10, 2014, 07:02:52 pm Last Edit: September 10, 2014, 07:17:24 pm by Wecoc
I'm not sure if there is an official 2.4 version (I was searching for it and I didn't found anything) but the old version 2.3 had some bugs so I decided to fix them. Also, I added some easy features.

Bugfixes:

- Underline and Strikethrough were not working properly
- Align feature now compatible with underline and strikethrough
- Gradient text was being drawn over a normal text (alpha problems)

Addons:

- Underline and Strikethrough 'height' feature
- Underline and Strikethrough 'double' feature
- Shadow 'x' / 'y' (default: 2, 2)
- Array method missing ; if you call a missing method to an array it will check if it can be applied in any object inside the array

And that's all, I know it's not so much. There could be more bugs to fix, if you know any please contact me.

MACL Complete 2.4.txt

MACL is full of interesting methods for hidden classes. I have thousands of them too, in a compilation I did for my own (some are written by me). Some of them could be added on MACL, but I should have to check them between the current ones, and I CAN'T do that.

I will probably choose the interesting ones and post on another project, but not sure when I will be able to do it.

If there is any problem with this post or the MACL author's rules or... ANYTHING, please sorry.

If you use this version don't credit me, but the real authors.

LiTTleDRAgo

this :

Spoiler: ShowHide
Quote
  #---------------------------------------------------------------------------
  # * Name      : Product
  #   Info      : Returns the product of all values in the array
  #   Author    : Trickster
  #   Call Info : No Arguments
  #---------------------------------------------------------------------------
  def product
    # Setup N initialize to 1
    n = 1
    # Run Through and Find Product
    each {|num| n *= num}
    # Return Product
    return n
  end


has conflict with RGSS3 / XPA

MACL :
p [1,2,3,4].product #=> 24

RGSS3 (Without MACL) :
p [1,2,3,4].product #=> [[1],[2],[3],[4]]

http://www.ruby-doc.org/core-1.8.7/Array.html#method-i-product



also for some reason keyboard input in MACL makes the game lags.

Wecoc

Not sure if better:

This is a product I made long time ago, it's only implemented for 0, 1 and 2 arguments and it works like the RGSS3's product.

class Array
  #--------------------------------------------------------------------------
  # product
  #--------------------------------------------------------------------------
  # [1,2,3].product([4,5]) #=> [[1,4],[1,5],[2,4],[2,5],[3,4],[3,5]]
  #
  # [1,2].product([3,4],[5,6]) #=>[[1,3,5],[1,3,6],[1,4,5],[1,4,6],
  #                            #  [2,3,5],[2,3,6],[2,4,5],[2,4,6]]
  #--------------------------------------------------------------------------
  def product_2(array)
    a = result = []
    if array.is_a?(Numeric)
      for i in 0...self.length
        result[i] = self[i] * array
      end
      return result
    end
    return [] if array.length == 0
    if array.length == 1
      for i in 0...self.length
        result[i] = self[i] * array[0]
      end
      return result
    end
    for i in 0..self.length-1
      a = [self[i],array].flatten
      result += a.combination(array.length)
      result.pop
    end
    return result
  end

  def product(*args)
    result = []
    if args.length == 0
      self.map! {|item| item.to_a }
      return self
    end
    if args.length == 1
      return self.product_2(*args)
    end
    if args.length == 2
      resprev = self.product_2(args[0])
      for i in 0..resprev.length-1
        for j in 0..args[1].length-1
          result.push resprev[i]+args[1][j].to_a
        end
      end
      return result
    end
    raise "args.length > 2 not implemented"
  end
 
  #--------------------------------------------------------------------------
  # powerset
  #--------------------------------------------------------------------------
  # x = [1, 2, 3]
  # y = x.powerset #=> [[], [1], [2], [1,2], [3], [1,3], [2,3], [1,2,3]]
  #--------------------------------------------------------------------------
 
  def powerset
    num = 2**size
    ps = Array.new(num, [])
    self.each_index do |i|
      a = 2**i
      b = 2**(i+1) - 1
      j = 0
      while j < num-1
        for j in j+a..j+b
          ps[j] += [self[i]]
        end
        j += 1
      end
    end
    ps
  end
 
  #--------------------------------------------------------------------------
  # combination
  #--------------------------------------------------------------------------
  # x = [1, 2, 3]
  # y = x.combination(1) #=> [[1], [2], [3]]
  # y = x.combination(2) #=> [[1,2], [1,3], [2,3]]
  # y = x.combination(3) #=> [[1,2,3]]
  #--------------------------------------------------------------------------
 
  def combination(n)
    result = []
    power = self.powerset
    return if n > power.length
    return [[]] if n == 0
    for i in 0..power.length
      if power[i].to_a.length == n
        result.push power[i]
      end
    end
    return result
  end
 
  #--------------------------------------------------------------------------
  # num_prod
  #--------------------------------------------------------------------------
  # [1,2,3,4].num_prod #=> 24
  #--------------------------------------------------------------------------

  def num_prod
    n = 1
    each {|num| n *= num}
    return n
  end
end


Maybe other methods will be incompatible with RGSS3 / XPA... sort_by for example.

LiTTleDRAgo

September 11, 2014, 07:16:01 am #3 Last Edit: September 11, 2014, 07:23:54 am by LiTTleDRAgo
class Array
  unless method_defined?(:product)
    def product(*arrays)
      (e = "(result = []) and self.each {|i0| ") &&
      (a = arrays.size).times {|i| e += "arrays[#{i}].each {|i#{i+1}| " }
      (e += "result.push([i0,") and a.times {|i| e += "i#{i+1}," }
      (e += "])}" + "}" * a + " and result"  )
      return eval(e)
    end
  end
end


Quote from: Wecoc on September 11, 2014, 06:32:27 am
Maybe other methods will be incompatible with RGSS3 / XPA... sort_by for example.


you probably should add a condition to prevent existing method to be overwritten
unless method_defined?(:CLASS_NAME)

Wecoc

September 11, 2014, 02:58:56 pm #4 Last Edit: September 11, 2014, 03:00:24 pm by Wecoc
Ok, thank you LiTTleDRAgo :) That product method is great.

You can't deactivate the full script with =begin // =end because it uses the string '=end' inside the methods :load_next_line and :load_data_from_txt (I have no idea why xD)

The most simple way to fix that is using for example '=' + 'end' instead of '=end'

Anyway I was looking for other possible problems, because some of the new methods are pre-defined in RGSS3.
I found those:

Array -->  :find_index, :sort_by!
String --> :clear
Font --> :shadow, :shadow=, :outline, :outline=

I'll search more and try to fix them.

LiTTleDRAgo

September 11, 2014, 07:55:52 pm #5 Last Edit: September 11, 2014, 08:26:34 pm by LiTTleDRAgo
replace find_index method with
method_defined?(:find_index) || alias_method(:find_index, :index)


then replace
copy.find_index(copy.compact.min).each do |index|

with
copy.all_indexes(copy.compact.min).each do |index|


about sort_by! and clear, you can do it like this
class String
  unless method_defined?(:clear)
    def clear
      replace('')
    end
  end
end

class Array
  unless method_defined?(:sort_by!)
    def sort_by!(&block)
      # Sort & Modify Original Array, if Changes Made Return self else nil
      self.dup == replace(sort_by(&block)) ? nil : self
    end
  end
end

Wecoc

Done! The dropbox file was updated.
I already checked all the hidden class methods, and I didn't found any other incompatibility with RGSS3. The script is only compatible with XP because of all the other specific XP classes... So the only thing left to do is check it with XPA and get all the bugs out.

whitespirits

Hey guys, I noticed MACL is in the house decoration system I posted in requests, I'm looking for RMX-OS compatibity, maybe adding ur fixed up MACL and then just removing SDK from the house system could work?

LiTTleDRAgo

found one more error

class Array
  def geometric_average(float = false)
    # Return 0 if empty
    return 0 if empty?
    # Get Geometric Average
    average = product ** (1.0 / size)
    # If Float return average else convert to integer
    return (float ? average : average.to_i)
  end
end


how it should be :

class Array
  def geometric_average(float = false)
    # Get Geometric Average, Return 0 if empty
    average = empty? ? 0 : num_product ** (1.0 / size)
    # If Float return average else convert to integer
    return (float ? average : average.to_i)
  end
 
  def num_product
    # Run Through and Find Product
    self.inject(1) {|r, n| r *= n} 
  end
end


^ :num_product is replacement for old MACL :product method

Wecoc

whiteflute: Yes, your system uses MACL 2.3 divided in three scripts. You can udapte to 2.4 but it will not fix the incompatibilities with RMX-OS, first because I didn't change anything about that for the new version, and second and most important, because the major incompatibilities are from the House System by itself.

I dare say you have not been answered in the other topic because you are asking for something hard to solve. I don't know how the RMX-OS "global" events and switches work exactly, but that system should be rewritten to support that. It's the only way.

LiTTleDRAgo: I see, because of the :product replacement. Thank you again for all those contributions.

Quote from: LiTTleDRAgoalso for some reason keyboard input in MACL makes the game lags


Maybe Keyboard.update can be simplified... That bug is too difficult to solve right now xD

LiTTleDRAgo

@^ lol, since when WF joined chaos-project?


@whitespirits; you don't have to use MACL as a whole, just copy any part you need for your game.

Wecoc

LOL sorry, I meant WhiteRose (???)

Well, after check the script a bit more, I didn't found new bugs. That means this version is officially concluded. If in a future someone find other bugs, lacks or important incompatibilities the script will be uploaded again, to 2.5.

Thank you LD for helping me on this.