Re: Fight the bonemeal patrols, add belts…
Posted: Sat Oct 19, 2024 7:27 pm
I apologize for the delay. Weekdays are quite busy for me. I answer here for completeness of the thread. I'll move to Discord after this answer.
Each use, above, of player.iconID requires some analysis to make sure 1) the new logic is sound for the new purpose and 2) that it does not break anything. As I am just learning the code base, that is a bit time consuming, but tasks like this will become less cumbersome for me over time.
In A.T., the Player class inherits from (or "extends") a base class called Actor:
So does the monster class:
This allows the engine to refer both to the player and the monsters with Actor references. It needn't differentiate between the two most of the time.
The Introduction to Computer Science example for this is often a chess program. One may create an abstract base (or "parent") class Piece with members color, row and column and a function move(int row, int column). One may then derive child classes Rook, Knight, Bishop, Queen, King and Pawn from Piece, with different logic for each's move() function.
The collection of live pieces may then be stored, all together, as an array of Piece objects, instead of separately storing each player's various pieces. When the program executes an array member's move() function, the language maps it to the appropriate move() for the child class of that piece.
That is what we have in some places in A.T., e.g., in ActorStatsListeners.java:
There are not two different sets of the logic, above, one for the player and another for monsters.
But, in the A.T. code that uses the iconID, we are passing around Player and Monster references, not Actor references, even though iconID is a property of Actor, inherited by its descendants Player and Monster. See, e.g., doDrawRect_Objects() in MainView.java:
Regardless, I will do what I can to limit the scope of necessary downstream testing. But the change to allow the sprite to change and change back will, necessarily and inherently, be non-trivial.
It will be best and likely wise to test it in a beta,
— /s/ Judoka.
No. I mean like this:
Code: Select all
AndorsTrail/app/src/main/java/com/gpl/rpg/AndorsTrail/activity/fragment/HeroinfoActivity_Inventory.java: heroicon.setImageResource(HeroCollection.getHeroLargeSprite(player.iconID));
AndorsTrail/app/src/main/java/com/gpl/rpg/AndorsTrail/activity/fragment/HeroinfoActivity_Stats.java: tv.setCompoundDrawablesWithIntrinsicBounds(HeroCollection.getHeroLargeSprite(player.iconID), 0, 0, 0);
AndorsTrail/app/src/main/java/com/gpl/rpg/AndorsTrail/activity/HeroinfoActivity.java: world.tileManager.setImageViewTileForPlayer(getResources(), iv, world.model.player.iconID);
AndorsTrail/app/src/main/java/com/gpl/rpg/AndorsTrail/resource/tiles/TileManager.java: result.setBitmap(tileID_placeholder_hero, preloadedTiles.getBitmap(world.model.player.iconID));
AndorsTrail/app/src/main/java/com/gpl/rpg/AndorsTrail/resource/tiles/TileManager.java: public void setImageViewTile(Resources res, TextView textView, Player player) { setImageViewTileForPlayer(res, textView, player.iconID); }
AndorsTrail/app/src/main/java/com/gpl/rpg/AndorsTrail/resource/tiles/TileManager.java: public void setImageViewTile(Resources res, ImageView imageView, Player player) { setImageViewTileForPlayer(res, imageView, player.iconID); }
AndorsTrail/app/src/main/java/com/gpl/rpg/AndorsTrail/savegames/Savegames.java: displayInfo, world.model.player.iconID,
AndorsTrail/app/src/main/java/com/gpl/rpg/AndorsTrail/view/MainView.java: drawFromMapPosition(canvas, area, playerPosition, model.player.iconID);
AndorsTrail/app/src/main/java/com/gpl/rpg/AndorsTrail/view/MainView.java: tiles.drawTile(canvas, model.player.iconID, x, y, mPaint);
AndorsTrail/app/src/main/java/com/gpl/rpg/AndorsTrail/view/StatusView.java:// new BitmapDrawable(res, world.tileManager.preloadedTiles.getBitmap(player.iconID))
AndorsTrail/app/src/main/java/com/gpl/rpg/AndorsTrail/view/StatusView.java: world.tileManager.setImageViewTileWithOverlay(res, heroImage, TileManager.iconID_moveselect, world.tileManager.preloadedTiles.getBitmap(player.iconID), true);
Polymorphism is an object-oriented-programming (O.O.P.) abstraction concept embraced by Java, C++ and most other O.O.P. languages (some would say with negative consequences, but Android leaves little, if any, choice other than to use Java).
In A.T., the Player class inherits from (or "extends") a base class called Actor:
Code: Select all
…
public final class Player extends Actor {
…
Code: Select all
…
public final class Monster extends Actor {
…
The Introduction to Computer Science example for this is often a chess program. One may create an abstract base (or "parent") class Piece with members color, row and column and a function move(int row, int column). One may then derive child classes Rook, Knight, Bishop, Queen, King and Pawn from Piece, with different logic for each's move() function.
The collection of live pieces may then be stored, all together, as an array of Piece objects, instead of separately storing each player's various pieces. When the program executes an array member's move() function, the language maps it to the appropriate move() for the child class of that piece.
That is what we have in some places in A.T., e.g., in ActorStatsListeners.java:
Code: Select all
…
@Override
public void onActorHealthChanged(Actor actor) {
callAllListeners(this.onActorHealthChanged, actor);
}
…
But, in the A.T. code that uses the iconID, we are passing around Player and Monster references, not Actor references, even though iconID is a property of Actor, inherited by its descendants Player and Monster. See, e.g., doDrawRect_Objects() in MainView.java:
Code: Select all
…
if (!model.player.hasVFXRunning) {
drawFromMapPosition(canvas, area, playerPosition, model.player.iconID);
} else if (area.contains(playerPosition)) {
int vfxElapsedTime = (int) (System.currentTimeMillis() - model.player.vfxStartTime);
if (vfxElapsedTime > model.player.vfxDuration) vfxElapsedTime = model.player.vfxDuration;
int x = ((model.player.position.x - mapViewArea.topLeft.x) * tileSize * vfxElapsedTime + ((model.player.lastPosition.x - mapViewArea.topLeft.x) * tileSize * (model.player.vfxDuration - vfxElapsedTime))) / model.player.vfxDuration;
int y = ((model.player.position.y - mapViewArea.topLeft.y) * tileSize * vfxElapsedTime + ((model.player.lastPosition.y - mapViewArea.topLeft.y) * tileSize * (model.player.vfxDuration - vfxElapsedTime))) / model.player.vfxDuration;
tiles.drawTile(canvas, model.player.iconID, x, y, mPaint);
}
…
It will be best and likely wise to test it in a beta,
— /s/ Judoka.