Commit 366e232beb61f18b5242bd0f11b8d822f24cdf6b

Authored by DarkGod
1 parent 6ea01de1

Entities add_mos can have an "auto_tall" property to autoset display_y and displ…

…ay_h corresponding to the tile geometry
... ... @@ -278,13 +278,13 @@ function _M:makeMapObject(tiles, idx)
278 278
279 279 -- Texture 0 is always the normal image/ascii tile
280 280 -- we pcall it because some weird cases can not find a tile
281   - local ok, btex, btexx, btexy, bpos_x, bpos_y = pcall(tiles.get, tiles, self.display, self.color_r, self.color_g, self.color_b, self.color_br, self.color_bg, self.color_bb, self.image, self._noalpha and 255, self.ascii_outline, true)
  281 + local ok, btex, btexx, btexy = pcall(tiles.get, tiles, self.display, self.color_r, self.color_g, self.color_b, self.color_br, self.color_bg, self.color_bb, self.image, self._noalpha and 255, self.ascii_outline, true)
282 282 if ok then
283 283 if self.anim then
284   - self._mo:texture(0, btex, false, btexx / self.anim.max, btexy, bpos_x, bpos_y)
  284 + self._mo:texture(0, btex, false, btexx / self.anim.max, btexy, nil, nil)
285 285 self._mo:setAnim(0, self.anim.max, self.anim.speed or 1, self.anim.loop or -1)
286 286 else
287   - self._mo:texture(0, btex, false, btexx, btexy, bpos_x, bpos_y)
  287 + self._mo:texture(0, btex, false, btexx, btexy, nil, nil)
288 288 end
289 289 end
290 290
... ... @@ -294,16 +294,19 @@ function _M:makeMapObject(tiles, idx)
294 294 local cmo = self._mo
295 295 for i = 1, #self.add_mos do
296 296 local amo = self.add_mos[i]
  297 + local dy, dh = amo.display_y or 0, amo.display_h or 1
297 298 -- Create a simple additional chained MO
298   - local mo = core.map.newObject(self.uid, 1 + (tiles.use_images and amo.textures and #amo.textures or 0), false, false, false, amo.display_x or 0, amo.display_y or 0, amo.display_w or 1, amo.display_h or 1, amo.display_scale or 1)
299 299 if amo.image_alter == "sdm" then
300 300 tex = tiles:get("", 0, 0, 0, 0, 0, 0, amo.image, false, false, true)
301 301 tex = tex:generateSDM(amo.sdm_double)
302   - texx, texy, pos_x, pos_y = 1,1,nil,nil
  302 + texx, texy = 1,1,nil,nil
303 303 elseif amo.image then
304   - tex, texx, texy, pos_x, pos_y = tiles:get("", 0, 0, 0, 0, 0, 0, amo.image, false, false, true)
  304 + local w, h
  305 + tex, texx, texy, w, h = tiles:get("", 0, 0, 0, 0, 0, 0, amo.image, false, false, true)
  306 + if amo.auto_tall and h > w then dy = -1 dh = 2 end
305 307 end
306   - mo:texture(0, tex, false, texx, texy, pos_x, pos_y)
  308 + local mo = core.map.newObject(self.uid, 1 + (tiles.use_images and amo.textures and #amo.textures or 0), false, false, false, amo.display_x or 0, dy, amo.display_w or 1, dh, amo.display_scale or 1)
  309 + mo:texture(0, tex, false, texx, texy, nil, nil)
307 310 if amo.particle then
308 311 local args = amo.particle_args or {}
309 312 local e = engine.Particles.new(amo.particle, 1, args)
... ...
... ... @@ -86,7 +86,7 @@ function _M:get(char, fr, fg, fb, br, bg, bb, image, alpha, do_outline, allow_ti
86 86 local s = self.repo[char][fgidx][bgidx]
87 87 return s[1], s[2], s[3], s[4], s[5]
88 88 else
89   - local s, sw, sh
  89 + local s, sw, sh, w, h
90 90 local is_image = false
91 91 if (self.use_images or not dochar) and image and #image > 4 then
92 92 if allow_tileset and self.texture then
... ... @@ -118,7 +118,7 @@ function _M:get(char, fr, fg, fb, br, bg, bb, image, alpha, do_outline, allow_ti
118 118 end
119 119
120 120 if self.texture then
121   - local w, h = s:getSize()
  121 + w, h = s:getSize()
122 122 s, sw, sh = s:glTexture()
123 123 sw, sh = w / sw, h / sh
124 124 if not is_image and do_outline then
... ... @@ -130,12 +130,13 @@ function _M:get(char, fr, fg, fb, br, bg, bb, image, alpha, do_outline, allow_ti
130 130 end
131 131 else
132 132 sw, sh = s:getSize()
  133 + w, h = sw, sh
133 134 end
134 135
135 136 self.repo[char] = self.repo[char] or {}
136 137 self.repo[char][fgidx] = self.repo[char][fgidx] or {}
137   - self.repo[char][fgidx][bgidx] = {s, sw, sh}
138   - return s, sw, sh
  138 + self.repo[char][fgidx][bgidx] = {s, sw, sh, w, h}
  139 + return s, sw, sh, w, h
139 140 end
140 141 end
141 142
... ...
... ... @@ -3064,7 +3064,7 @@ function _M:updateModdableTile()
3064 3064
3065 3065 self:triggerHook{"Actor:updateModdableTile:back", base=base, add=add}
3066 3066
3067   - i = self.inven[self.INVEN_CLOAK]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile):format("behind")..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1} end
  3067 + i = self.inven[self.INVEN_CLOAK]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile):format("behind")..".png", auto_tall=1} end
3068 3068
3069 3069 if self.shader_auras and next(self.shader_auras) then
3070 3070 for _, def in pairs(self.shader_auras) do
... ... @@ -3076,41 +3076,41 @@ function _M:updateModdableTile()
3076 3076
3077 3077 if not self:attr("disarmed") then
3078 3078 i = self.inven[self.INVEN_MAINHAND]; if i and i[1] and i[1].moddable_tile_back then
3079   - add[#add+1] = {image = base..(i[1].moddable_tile_back):format("right")..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1}
  3079 + add[#add+1] = {image = base..(i[1].moddable_tile_back):format("right")..".png", auto_tall=1}
3080 3080 end
3081 3081 i = self.inven[self.INVEN_OFFHAND]; if i and i[1] and i[1].moddable_tile_back then
3082   - add[#add+1] = {image = base..(i[1].moddable_tile_back):format("left")..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1}
  3082 + add[#add+1] = {image = base..(i[1].moddable_tile_back):format("left")..".png", auto_tall=1}
3083 3083 end
3084 3084 end
3085 3085
3086   - i = self.inven[self.INVEN_CLOAK]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile):format("shoulder")..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1} end
3087   - i = self.inven[self.INVEN_FEET]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile)..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1} end
3088   - i = self.inven[self.INVEN_BODY]; if i and i[1] and i[1].moddable_tile2 then add[#add+1] = {image = base..(i[1].moddable_tile2)..".png"}
  3086 + i = self.inven[self.INVEN_CLOAK]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile):format("shoulder")..".png", auto_tall=1} end
  3087 + i = self.inven[self.INVEN_FEET]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile)..".png", auto_tall=1} end
  3088 + i = self.inven[self.INVEN_BODY]; if i and i[1] and i[1].moddable_tile2 then add[#add+1] = {image = base..(i[1].moddable_tile2)..".png", auto_tall=1}
3089 3089 elseif not self.moddable_tile_nude then add[#add+1] = {image = base.."lower_body_01.png"} end
3090   - i = self.inven[self.INVEN_BODY]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile)..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1}
  3090 + i = self.inven[self.INVEN_BODY]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile)..".png", auto_tall=1}
3091 3091 elseif not self.moddable_tile_nude then add[#add+1] = {image = base.."upper_body_01.png"} end
3092   - i = self.inven[self.INVEN_HEAD]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile)..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1} end
3093   - i = self.inven[self.INVEN_HANDS]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile)..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1} end
3094   - i = self.inven[self.INVEN_CLOAK]; if i and i[1] and i[1].moddable_tile_hood then add[#add+1] = {image = base..(i[1].moddable_tile):format("hood")..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1} end
  3092 + i = self.inven[self.INVEN_HEAD]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile)..".png", auto_tall=1} end
  3093 + i = self.inven[self.INVEN_HANDS]; if i and i[1] and i[1].moddable_tile then add[#add+1] = {image = base..(i[1].moddable_tile)..".png", auto_tall=1} end
  3094 + i = self.inven[self.INVEN_CLOAK]; if i and i[1] and i[1].moddable_tile_hood then add[#add+1] = {image = base..(i[1].moddable_tile):format("hood")..".png", auto_tall=1} end
3095 3095 if not self:attr("disarmed") then
3096 3096 i = self.inven[self.INVEN_MAINHAND]; if i and i[1] and i[1].moddable_tile then
3097   - add[#add+1] = {image = base..(i[1].moddable_tile):format("right")..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1}
  3097 + add[#add+1] = {image = base..(i[1].moddable_tile):format("right")..".png", auto_tall=1}
3098 3098 if i[1].moddable_tile_particle then
3099 3099 add[#add].particle = i[1].moddable_tile_particle[1]
3100 3100 add[#add].particle_args = i[1].moddable_tile_particle[2]
3101 3101 end
3102   - if i[1].moddable_tile_ornament then add[#add+1] = {image = base..(i[1].moddable_tile_ornament):format("right")..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1} end
  3102 + if i[1].moddable_tile_ornament then add[#add+1] = {image = base..(i[1].moddable_tile_ornament):format("right")..".png", auto_tall=1} end
3103 3103 end
3104 3104 i = self.inven[self.INVEN_OFFHAND]; if i and i[1] and i[1].moddable_tile then
3105   - add[#add+1] = {image = base..(i[1].moddable_tile):format("left")..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1}
3106   - if i[1].moddable_tile_ornament then add[#add+1] = {image = base..(i[1].moddable_tile_ornament):format("left")..".png", display_y=i[1].moddable_tile_big and -1 or 0, display_h=i[1].moddable_tile_big and 2 or 1} end
  3105 + add[#add+1] = {image = base..(i[1].moddable_tile):format("left")..".png", auto_tall=1}
  3106 + if i[1].moddable_tile_ornament then add[#add+1] = {image = base..(i[1].moddable_tile_ornament):format("left")..".png", auto_tall=1} end
3107 3107 end
3108 3108 end
3109 3109
3110 3110 self:triggerHook{"Actor:updateModdableTile:front", base=base, add=add}
3111 3111
3112   - if self.moddable_tile_ornament and self.moddable_tile_ornament[self.female and "female" or "male"] then add[#add+1] = {image = base..self.moddable_tile_ornament[self.female and "female" or "male"]..".png"} end
3113   - if self.moddable_tile_ornament2 and self.moddable_tile_ornament2[self.female and "female" or "male"] then add[#add+1] = {image = base..self.moddable_tile_ornament2[self.female and "female" or "male"]..".png"} end
  3112 + if self.moddable_tile_ornament and self.moddable_tile_ornament[self.female and "female" or "male"] then add[#add+1] = {image = base..self.moddable_tile_ornament[self.female and "female" or "male"]..".png", auto_tall=1} end
  3113 + if self.moddable_tile_ornament2 and self.moddable_tile_ornament2[self.female and "female" or "male"] then add[#add+1] = {image = base..self.moddable_tile_ornament2[self.female and "female" or "male"]..".png", auto_tall=1} end
3114 3114
3115 3115 if self.x and game.level then game.level.map:updateMap(self.x, self.y) end
3116 3116 end
... ...
... ... @@ -223,7 +223,7 @@ function _M:step()
223 223
224 224 -- Ping every minute, lest the server kills us
225 225 local time = os.time()
226   - if time - self.last_ping > 60 then
  226 + if time - self.last_ping > 60 and self.sock then
227 227 self.last_ping = time
228 228 self:orderPing()
229 229 end
... ...