@@ -36,31 +36,46 @@ public override string Sprite
3636 get => mMySprite ;
3737 set
3838 {
39+ if ( value == mMySprite )
40+ {
41+ return ;
42+ }
43+
3944 if ( BaseResource == null )
4045 {
4146 return ;
4247 }
4348
4449 mMySprite = value ;
45- if ( IsDead && BaseResource . Exhausted . GraphicFromTileset ||
46- ! IsDead && BaseResource . Initial . GraphicFromTileset )
50+ ReloadSpriteTexture ( ) ;
51+ }
52+ }
53+
54+ private void ReloadSpriteTexture ( )
55+ {
56+ if ( BaseResource == null )
57+ {
58+ return ;
59+ }
60+
61+ if ( IsDead && BaseResource . Exhausted . GraphicFromTileset ||
62+ ! IsDead && BaseResource . Initial . GraphicFromTileset )
63+ {
64+ if ( GameContentManager . Current . TilesetsLoaded )
4765 {
48- if ( GameContentManager . Current . TilesetsLoaded )
49- {
50- Texture = Globals . ContentManager . GetTexture ( Framework . Content . TextureType . Tileset , mMySprite ) ;
51- }
52- else
53- {
54- _waitingForTilesets = true ;
55- }
66+ Texture = Globals . ContentManager . GetTexture ( Framework . Content . TextureType . Tileset , mMySprite ) ;
5667 }
5768 else
5869 {
59- Texture = Globals . ContentManager . GetTexture ( Framework . Content . TextureType . Resource , mMySprite ) ;
70+ _waitingForTilesets = true ;
6071 }
61-
62- mHasRenderBounds = false ;
6372 }
73+ else
74+ {
75+ Texture = Globals . ContentManager . GetTexture ( Framework . Content . TextureType . Resource , mMySprite ) ;
76+ }
77+
78+ mHasRenderBounds = false ;
6479 }
6580
6681 public override void Load ( EntityPacket ? packet )
@@ -114,15 +129,20 @@ public override bool Update()
114129
115130 return false ;
116131 }
117- else
132+
133+ if ( ! Maps . MapInstance . TryGet ( MapId , out var map ) || ! map . InView ( ) )
118134 {
119- var map = Maps . MapInstance . Get ( MapId ) ;
120135 LatestMap = map ;
121- if ( map == null || ! map . InView ( ) )
122- {
123- Globals . EntitiesToDispose . Add ( Id ) ;
136+ Globals . EntitiesToDispose . Add ( Id ) ;
124137
125- return false ;
138+ return false ;
139+ }
140+
141+ if ( _waitingForTilesets )
142+ {
143+ if ( GameContentManager . Current . TilesetsLoaded )
144+ {
145+ ReloadSpriteTexture ( ) ;
126146 }
127147 }
128148
@@ -172,7 +192,17 @@ public override bool Update()
172192 _ = renderList . Remove ( this ) ;
173193 }
174194
175- if ( map == null || Globals . Me == null || Globals . Me . MapInstance == null || Globals . MapGrid == default )
195+ if ( map == null )
196+ {
197+ return null ;
198+ }
199+
200+ if ( Globals . MapGrid == default )
201+ {
202+ return null ;
203+ }
204+
205+ if ( Globals . Me ? . MapInstance == null )
176206 {
177207 return null ;
178208 }
@@ -227,62 +257,70 @@ public override bool Update()
227257
228258 private void CalculateRenderBounds ( )
229259 {
230- var map = MapInstance ;
231- if ( map == null || BaseResource == default )
260+ if ( BaseResource == default )
232261 {
233262 return ;
234263 }
235264
236- if ( _waitingForTilesets && ! GameContentManager . Current . TilesetsLoaded )
265+ if ( MapInstance is not { } map )
237266 {
238267 return ;
239268 }
240269
241- if ( _waitingForTilesets && GameContentManager . Current . TilesetsLoaded )
270+ if ( _waitingForTilesets )
242271 {
243- _waitingForTilesets = false ;
244- }
245-
246- if ( Texture != null )
247- {
248- mSrcRectangle . X = 0 ;
249- mSrcRectangle . Y = 0 ;
250- if ( IsDead && BaseResource . Exhausted . GraphicFromTileset )
251- {
252- mSrcRectangle . X = BaseResource . Exhausted . X * Options . TileWidth ;
253- mSrcRectangle . Y = BaseResource . Exhausted . Y * Options . TileHeight ;
254- mSrcRectangle . Width = ( BaseResource . Exhausted . Width + 1 ) * Options . TileWidth ;
255- mSrcRectangle . Height = ( BaseResource . Exhausted . Height + 1 ) * Options . TileHeight ;
256- }
257- else if ( ! IsDead && BaseResource . Initial . GraphicFromTileset )
272+ if ( GameContentManager . Current . TilesetsLoaded )
258273 {
259- mSrcRectangle . X = BaseResource . Initial . X * Options . TileWidth ;
260- mSrcRectangle . Y = BaseResource . Initial . Y * Options . TileHeight ;
261- mSrcRectangle . Width = ( BaseResource . Initial . Width + 1 ) * Options . TileWidth ;
262- mSrcRectangle . Height = ( BaseResource . Initial . Height + 1 ) * Options . TileHeight ;
274+ _waitingForTilesets = false ;
263275 }
264276 else
265277 {
266- mSrcRectangle . Width = Texture . Width ;
267- mSrcRectangle . Height = Texture . Height ;
278+ return ;
268279 }
280+ }
269281
270- mDestRectangle . Width = mSrcRectangle . Width ;
271- mDestRectangle . Height = mSrcRectangle . Height ;
272- mDestRectangle . Y = ( int ) ( map . Y + Y * Options . TileHeight + OffsetY ) ;
273- mDestRectangle . X = ( int ) ( map . X + X * Options . TileWidth + OffsetX ) ;
274- if ( mSrcRectangle . Height > Options . TileHeight )
275- {
276- mDestRectangle . Y -= mSrcRectangle . Height - Options . TileHeight ;
277- }
282+ if ( Texture == null )
283+ {
284+ return ;
285+ }
278286
279- if ( mSrcRectangle . Width > Options . TileWidth )
280- {
281- mDestRectangle . X -= ( mSrcRectangle . Width - Options . TileWidth ) / 2 ;
282- }
287+ mSrcRectangle . X = 0 ;
288+ mSrcRectangle . Y = 0 ;
289+ if ( IsDead && BaseResource . Exhausted . GraphicFromTileset )
290+ {
291+ mSrcRectangle . X = BaseResource . Exhausted . X * Options . TileWidth ;
292+ mSrcRectangle . Y = BaseResource . Exhausted . Y * Options . TileHeight ;
293+ mSrcRectangle . Width = ( BaseResource . Exhausted . Width + 1 ) * Options . TileWidth ;
294+ mSrcRectangle . Height = ( BaseResource . Exhausted . Height + 1 ) * Options . TileHeight ;
295+ }
296+ else if ( ! IsDead && BaseResource . Initial . GraphicFromTileset )
297+ {
298+ mSrcRectangle . X = BaseResource . Initial . X * Options . TileWidth ;
299+ mSrcRectangle . Y = BaseResource . Initial . Y * Options . TileHeight ;
300+ mSrcRectangle . Width = ( BaseResource . Initial . Width + 1 ) * Options . TileWidth ;
301+ mSrcRectangle . Height = ( BaseResource . Initial . Height + 1 ) * Options . TileHeight ;
302+ }
303+ else
304+ {
305+ mSrcRectangle . Width = Texture . Width ;
306+ mSrcRectangle . Height = Texture . Height ;
307+ }
308+
309+ mDestRectangle . Width = mSrcRectangle . Width ;
310+ mDestRectangle . Height = mSrcRectangle . Height ;
311+ mDestRectangle . Y = ( int ) ( map . Y + Y * Options . TileHeight + OffsetY ) ;
312+ mDestRectangle . X = ( int ) ( map . X + X * Options . TileWidth + OffsetX ) ;
313+ if ( mSrcRectangle . Height > Options . TileHeight )
314+ {
315+ mDestRectangle . Y -= mSrcRectangle . Height - Options . TileHeight ;
316+ }
283317
284- mHasRenderBounds = true ;
318+ if ( mSrcRectangle . Width > Options . TileWidth )
319+ {
320+ mDestRectangle . X -= ( mSrcRectangle . Width - Options . TileWidth ) / 2 ;
285321 }
322+
323+ mHasRenderBounds = true ;
286324 }
287325
288326 //Rendering Resources
0 commit comments