SHARE
TWEET

pastemap

polectron May 9th, 2020 1,242 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Template
  2.   attr_accessor :id
  3.   attr_accessor :width
  4.   attr_accessor :height
  5.   attr_accessor :map
  6.   attr_accessor :pattern
  7.  
  8.   def initialize(id, width, height, pattern)
  9.     @id = id
  10.     @width = width
  11.     @height = height
  12.     @pattern = pattern
  13.     readTemplate()
  14.   end
  15.  
  16.   def readTemplate()
  17.     @map = load_data(sprintf("Data/Map%03d.rxdata",@id))
  18.   end
  19. end
  20.  
  21. def mergeArrays(a, b, x, y, mask)
  22.  
  23.   tp = b.map
  24.    
  25.   x_limit = b.width
  26.   y_limit = b.height
  27.  
  28.  
  29.   for j in y..y_limit+y
  30.     for k in x..x_limit+x
  31.       for l in 0..2
  32.         begin
  33.           if tp.data[k-x,j-y,l] != 0  && tp.data[k-x,j-y,l] != nil
  34.             a.data[k,j,l] = tp.data[k-x,j-y,l]
  35.             #p mask[k]
  36.             mask[j][k] = 1
  37.           end
  38.         rescue => exception
  39.           #p exception
  40.         end
  41.       end
  42.     end
  43.   end
  44. end
  45.  
  46. def placeMapOn(template, x, y, mapid)
  47.   map = load_data(sprintf("Data/Map%03d.rxdata",mapid))
  48.   mask = Array.new(map.height){Array.new(map.width){0}}
  49.   mergeArrays(map, template, x, y, mask)
  50.   save_data(map, sprintf("Data/Map%03d.rxdata", mapid))
  51. end
  52.  
  53. def placeTest()
  54.   t = Template.new(4, 8, 4, nil)
  55.   placeMapOn(t, 3, 4, 2)
  56. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top