Vendily

zoom out map conn

Mar 2nd, 2018
130
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def createTinimap(mapid) # new (Edit all *1 with desired scale) and yes I am aware I misspelt it
  2.   map=load_data(sprintf("Data/Map%03d.rxdata",mapid)) rescue nil
  3.   return BitmapWrapper.new(32,32) if !map
  4.   bitmap=BitmapWrapper.new(map.width*1,map.height*1)
  5.   black=Color.new(0,0,0)
  6.   tilesets=load_data("Data/Tilesets.rxdata")
  7.   tileset=tilesets[map.tileset_id]
  8.   return bitmap if !tileset
  9.   helper=TileDrawingHelper.fromTileset(tileset)
  10.   for y in 0...map.height
  11.     for x in 0...map.width
  12.       for z in 0..2
  13.         id=map.data[x,y,z]
  14.         id=0 if !id
  15.         helper.bltSmallTile(bitmap,x*1,y*1,1,1,id) # change 1,1 to be same as scale
  16.       end
  17.     end
  18.   end
  19.   bitmap.fill_rect(0,0,bitmap.width,1,black) #get rid of these lines if you don't want the black outline
  20.   bitmap.fill_rect(0,bitmap.height-1,bitmap.width,1,black)
  21.   bitmap.fill_rect(0,0,1,bitmap.height,black)
  22.   bitmap.fill_rect(bitmap.width-1,0,1,bitmap.height,black)
  23.   return bitmap
  24. end
  25.  
  26.   def getMapSprite(id)
  27.     if !@mapsprites[id]
  28.       @mapsprites[id]=Sprite.new(@viewport)
  29.       @mapsprites[id].z=0
  30.       @mapsprites[id].bitmap=nil
  31.     end
  32.     if !@mapsprites[id].bitmap || @mapsprites[id].bitmap.disposed?
  33.       @mapsprites[id].bitmap=createTinimap(id) #edited
  34.     end
  35.     return @mapsprites[id]
  36.   end
  37.  
  38.     def putNeighbors(id,sprites)
  39.     conns=@mapconns
  40.     mapsprite=getMapSprite(id)
  41.     dispx=mapsprite.x
  42.     dispy=mapsprite.y
  43.     for conn in conns
  44.       if conn[0]==id
  45.         b=sprites.any? {|i| i==conn[3] }
  46.         if !b
  47.           x=(conn[1]-conn[4])*1+dispx
  48.           y=(conn[2]-conn[5])*1+dispy
  49.           setMapSpritePos(conn[3],x,y)
  50.           sprites.push(conn[3])
  51.           putNeighbors(conn[3],sprites)
  52.         end
  53.       elsif conn[3]==id
  54.         b=sprites.any? {|i| i==conn[0] }
  55.         if !b
  56.           x=(conn[4]-conn[1])*1+dispx # same as before, change *1 with desired scale
  57.           y=(conn[5]-conn[2])*1+dispy
  58.           setMapSpritePos(conn[0],x,y)
  59.           sprites.push(conn[3])
  60.           putNeighbors(conn[0],sprites)
  61.         end
  62.       end
  63.     end
  64.   end
  65.  
  66.     def generateConnectionData
  67.     ret=[]
  68.     # Create a clone of current map connection
  69.     for conn in @mapconns
  70.       ret.push(conn.clone)
  71.     end
  72.     keys=@mapsprites.keys
  73.     return ret if keys.length<2
  74.     # Remove all connections containing any sprites on the canvas from the array
  75.     for i in keys
  76.       removeOldConnections(ret,i)
  77.     end
  78.     # Rebuild connections
  79.     for i in keys
  80.       refs=getDirectConnections(keys,i)
  81.       for refmap in refs
  82.         othersprite=getMapSprite(i)
  83.         refsprite=getMapSprite(refmap)
  84.         c1=(refsprite.x-othersprite.x)/1 # you know the drill, 1 changes to your scale
  85.         c2=(refsprite.y-othersprite.y)/1
  86.         conn=[refmap,0,0,i,c1,c2]
  87.         j=0;while j<ret.length && !connectionsSymmetric?(ret[j],conn)
  88.           j+=1
  89.         end
  90.         if j==ret.length
  91.           ret.push(conn)
  92.         end
  93.       end
  94.     end
  95.     return ret
  96.   end
RAW Paste Data