Render world map with more details

Changed SpellSmithScene to not display empty edition and fixed edition filter.
This commit is contained in:
Grimm
2022-09-16 02:28:43 +02:00
parent f9de0c1678
commit 5bae834f09
23 changed files with 318 additions and 147 deletions

View File

@@ -69,10 +69,12 @@ public class RewardData {
private static Iterable<PaperCard> allCards;
private static Iterable<PaperCard> allEnemyCards;
private void initializeAllCards(){
static private void initializeAllCards(){
RewardData legals = Config.instance().getConfigData().legalCards;
if(legals==null) allCards = FModel.getMagicDb().getCommonCards().getUniqueCardsNoAlt();
else allCards = Iterables.filter(FModel.getMagicDb().getCommonCards().getUniqueCardsNoAlt(), new CardUtil.CardPredicate(legals, true));
if(legals==null)
allCards = FModel.getMagicDb().getCommonCards().getUniqueCardsNoAlt();
else
allCards = Iterables.filter(FModel.getMagicDb().getCommonCards().getUniqueCardsNoAlt(), new CardUtil.CardPredicate(legals, true));
//Filter out specific cards.
allCards = Iterables.filter(allCards, new Predicate<PaperCard>() {
@Override
@@ -92,7 +94,7 @@ public class RewardData {
});
}
public Iterable<PaperCard> getAllCards() {
static public Iterable<PaperCard> getAllCards() {
if(allCards == null) initializeAllCards();
return allCards;
}

View File

@@ -24,6 +24,7 @@ public class WorldData implements Serializable {
public float playerStartPosY;
public float noiseZoomBiome;
public int tileSize;
public int miniMapTileSize;
public BiomeData roadTileset;
public String biomesSprites;
public float maxRoadDistance;

View File

@@ -93,8 +93,8 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
gold = 0;
maxLife = 20;
life = 20;
maxMana = 100;
mana = 100;
maxMana = 10;
mana = 10;
clearDecks();
inventoryItems.clear();
equippedItems.clear();

View File

@@ -132,7 +132,6 @@ public class ArenaScene extends UIScene implements IAfterMatch {
private void startButton() {
if(roundsWon ==0)
{
goldLabel.setVisible(false);
startDialog.show(stage);
}
else
@@ -143,6 +142,7 @@ public class ArenaScene extends UIScene implements IAfterMatch {
int roundsWon =0;
private void startArena() {
goldLabel.setVisible(false);
arenaStarted=true;
startButton.setText(Forge.getLocalizer().getMessage("lblContinue"));
doneButton.setText(Forge.getLocalizer().getMessage("lblConcede"));
@@ -152,26 +152,26 @@ public class ArenaScene extends UIScene implements IAfterMatch {
}
@Override
public void setWinner(boolean winner) {
Array<Actor> winners=new Array<>();
Array<EnemySprite> winnersEnemies=new Array<>();
for(int i=0;i<fighters.size-2;i+=2)
Array<Actor> winners=new Array<>();
Array<EnemySprite> winnersEnemies=new Array<>();
for(int i=0;i<fighters.size-2;i+=2)
{
boolean leftWon=rand.nextBoolean();
if(leftWon)
{
boolean leftWon=rand.nextBoolean();
if(leftWon)
{
winners.add(fighters.get(i));
winnersEnemies.add(enemies.get(i));
moveFighter(fighters.get(i),true);
markLostFighter(fighters.get(i+1));
}
else
{
markLostFighter(fighters.get(i));
moveFighter(fighters.get(i+1),false);
winners.add(fighters.get(i+1));
winnersEnemies.add(enemies.get(i+1));
}
winners.add(fighters.get(i));
winnersEnemies.add(enemies.get(i));
moveFighter(fighters.get(i),true);
markLostFighter(fighters.get(i+1));
}
else
{
markLostFighter(fighters.get(i));
moveFighter(fighters.get(i+1),false);
winners.add(fighters.get(i+1));
winnersEnemies.add(enemies.get(i+1));
}
}
if(winner)
{
markLostFighter(fighters.get(fighters.size-2));
@@ -286,10 +286,10 @@ public class ArenaScene extends UIScene implements IAfterMatch {
doneButton.setText(Forge.getLocalizer().getMessage("lblDone"));
arenaData=data;
//rand.setSeed(seed); allow to reshuffle arena enemies for now
enemies.clear();
for(Actor fighter:fighters)
arenaPlane.removeActor(fighter);
fighters.clear();
arenaPlane.clear();
roundsWon =0;
int numberOfEnemies= (int) (Math.pow(2f, data.rounds)-1);

View File

@@ -19,6 +19,7 @@ import forge.adventure.util.RewardActor;
import forge.card.CardEdition;
import forge.card.ColorSet;
import forge.item.PaperCard;
import forge.model.FModel;
import forge.util.MyRandom;
import java.util.*;
@@ -59,7 +60,14 @@ public class SpellSmithScene extends UIScene {
List<CardEdition> editions = StaticData.instance().getSortedEditions();
editions = editions.stream().filter(input -> {
if(input == null) return false;
if(input == null)
return false;
if(input.getType()== CardEdition.Type.REPRINT||input.getType()== CardEdition.Type.PROMO||input.getType()== CardEdition.Type.COLLECTOR_EDITION)
return false;
List<PaperCard> it = StreamSupport.stream(RewardData.getAllCards().spliterator(), false)
.filter(input2 -> input2.getEdition().equals(input.getCode())).collect(Collectors.toList());
if(it.size()==0)
return false;
return(!Arrays.asList(Config.instance().getConfigData().restrictedEditions).contains(input.getCode()));
}).collect(Collectors.toList());
editionList = ui.findActor("BSelectPlane");
@@ -222,8 +230,7 @@ public class SpellSmithScene extends UIScene {
public void filterResults() {
RewardData R = new RewardData();
Iterable<PaperCard> P = R.getAllCards();
Iterable<PaperCard> P = RewardData.getAllCards();
goldLabel.setText("Gold: "+ Current.player().getGold());
float totalCost = basePrice * Current.player().goldModifier();
final List<String> colorFilter = new ArrayList<>();
@@ -251,7 +258,9 @@ public class SpellSmithScene extends UIScene {
P = StreamSupport.stream(P.spliterator(), false).filter(input -> {
//L|Basic Land, C|Common, U|Uncommon, R|Rare, M|Mythic Rare, S|Special, N|None
if (input == null) return false;
if(!edition.isEmpty()) if (!input.getEdition().equals(edition)) return false;
final CardEdition cardEdition = FModel.getMagicDb().getEditions().get(edition);
if(cardEdition!=null&&cardEdition.getCardInSet(input.getName()).size()==0) return false;
if(colorFilter.size() > 0) if(input.getRules().getColor() != ColorSet.fromNames(colorFilter)) return false;
if(!rarity.isEmpty()) if (!input.getRarity().toString().equals(rarity)) return false;
if(cost_low > -1) {

View File

@@ -154,6 +154,18 @@ public static ConsoleCommandInterpreter getInstance()
Current.player().giveGold(amount);
return "Added "+amount+" gold";
});
registerCommand(new String[]{"give", "mana"}, s -> {
if(s.length<1) return "Command needs 1 parameter: Amount.";
int amount;
try {
amount=Integer.parseInt(s[0]);
}
catch (Exception e) {
return "Can not convert " + s[0] + " to number";
}
Current.player().addMaxMana(amount);
return "Added " + amount + " max mana";
});
registerCommand(new String[]{"give", "life"}, s -> {
if(s.length<1) return "Command needs 1 parameter: Amount.";
int amount;

View File

@@ -283,7 +283,9 @@ public class CardUtil {
if(reward.getType()== Reward.Type.Life)
return reward.getCount()*500;
if(reward.getType()== Reward.Type.Mana)
return reward.getCount()*50;
return reward.getCount()*500;
if(reward.getType()== Reward.Type.Gold)
return reward.getCount();
return 1000;
}

View File

@@ -24,9 +24,9 @@ public abstract class DrawOnPixmap {
textureData.prepare();
}
on.drawPixmap(textureData.consumePixmap(), x, y, from.getRegionX(), from.getRegionY(), from.getRegionWidth(), from.getRegionHeight());
}
public static void drawText(Pixmap drawingMap, String itemText, int x, int y, float width, boolean bigText, Color color) {
//used for big numbers on Gold/Life for reward...
BitmapFont font = bigText ? Controls.getBitmapFont("big") : Controls.getBitmapFont("default");

View File

@@ -32,8 +32,7 @@ import java.util.*;
* Class that will create the world from the configuration
*/
public class World implements Disposable, SaveFileContent {
private WorldData data;
static final private int hudMapScale=4;
private WorldData data;
private Pixmap biomeImage;
private long[][] biomeMap;
private int[][] terrainMap;
@@ -292,6 +291,9 @@ public class World implements Disposable, SaveFileContent {
long startTime = System.currentTimeMillis();
loadWorldData();
//////////////////
///////// initialize
//////////////////
if (seed == 0) {
seed = random.nextLong();
@@ -306,7 +308,6 @@ public class World implements Disposable, SaveFileContent {
//save at all data
biomeMap = new long[width][height];
terrainMap = new int[width][height];
Pixmap pix = new Pixmap(width*hudMapScale, height*hudMapScale, Pixmap.Format.RGBA8888);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
@@ -315,13 +316,13 @@ public class World implements Disposable, SaveFileContent {
}
}
pix.setColor(1, 0, 0, 1);
pix.fill();
final int[] biomeIndex = {-1};
currentTime[0] = measureGenerationTime("loading data", currentTime[0]);
HashMap<BiomeStructureData, BiomeStructure> structureDataMap = new HashMap<>();
//////////////////
///////// calculation structure position with wavefunctioncollapse
//////////////////
for (BiomeData biome : data.GetBiomes()) {
if (biome.structures != null) {
int biomeWidth = (int) Math.round(biome.width * (double) width);
@@ -338,6 +339,10 @@ public class World implements Disposable, SaveFileContent {
}
}
}
//////////////////
///////// calculation each biome position based on noise and radius
//////////////////
FThreads.invokeInEdtNowOrLater(() -> {
for (BiomeData biome : data.GetBiomes()) {
@@ -371,9 +376,6 @@ public class World implements Disposable, SaveFileContent {
color.toHsv(hsv);
int count = (int) ((noiseValue - 0.5) * 10 / 4);
//hsv[2]+=(count*0.2);
color.fromHsv(hsv);
pix.setColor(color.r, color.g, color.b, 1);
pix.fillRectangle(x*hudMapScale, y*hudMapScale,hudMapScale,hudMapScale);
biomeMap[x][y] |= (1L << biomeIndex[0]);
int terrainCounter = 1;
terrainMap[x][y] = 0;
@@ -382,6 +384,7 @@ public class World implements Disposable, SaveFileContent {
float terrainNoise = ((float) noise.eval(x / (float) width * (noiseZoom * terrain.resolution), y / (float) height * (noiseZoom * terrain.resolution)) + 1) / 2;
if (terrainNoise >= terrain.min && terrainNoise <= terrain.max) {
terrainMap[x][y] = terrainCounter;
//pix.fillRectangle(x*data.miniMapTileSize, y*data.miniMapTileSize,data.miniMapTileSize,data.miniMapTileSize);
}
terrainCounter++;
}
@@ -404,8 +407,8 @@ public class World implements Disposable, SaveFileContent {
int structureIndex = structure.objectID(structureXStart, structureYStart);
if (structureIndex >= 0) {
pix.setColor(data.mappingInfo[structureIndex].getColor());
pix.fillRectangle(x*hudMapScale, y*hudMapScale,hudMapScale,hudMapScale);
//pix.setColor(data.mappingInfo[structureIndex].getColor());
//pix.fillRectangle(x*data.miniMapTileSize, y*data.miniMapTileSize,data.miniMapTileSize,data.miniMapTileSize);
terrainMap[x][y] = terrainCounter + structureIndex;
if (structure.collision(structureXStart, structureYStart))
terrainMap[x][y] |= collisionBit;
@@ -423,6 +426,9 @@ public class World implements Disposable, SaveFileContent {
}
currentTime[0] = measureGenerationTime("biomes in total", currentTime[0]);
//////////////////
///////// set poi placement
//////////////////
mapPoiIds = new PointOfInterestMap(getChunkSize(), data.tileSize, data.width / getChunkSize(), data.height / getChunkSize());
List<PointOfInterest> towns = new ArrayList<>();
List<PointOfInterest> notTowns = new ArrayList<>();
@@ -505,8 +511,8 @@ public class World implements Disposable, SaveFileContent {
if(marker!=null)
{
int xInPixels= (int) ((x / data.tileSize)*hudMapScale);
int yInPixels= (int) ((height-(y / data.tileSize))*hudMapScale);
int xInPixels= (int) ((x / data.tileSize)*data.miniMapTileSize);
int yInPixels= (int) ((height-(y / data.tileSize))*data.miniMapTileSize);
xInPixels-=(marker.getRegionWidth() /2);
yInPixels-=(marker.getRegionHeight() /2);
drawPixmapLater(mapMarkerPixmap,marker.getRegionX(),marker.getRegionY(),
@@ -527,7 +533,9 @@ public class World implements Disposable, SaveFileContent {
}
currentTime[0] = measureGenerationTime("poi placement", currentTime[0]);
//sort towns
//////////////////
///////// sort towns and build roads in between
//////////////////
List<Pair<PointOfInterest, PointOfInterest>> allSortedTowns = new ArrayList<>();
HashSet<Long> usedEdges = new HashSet<>();//edge is first 32 bits id of first id and last 32 bits id of second
@@ -583,7 +591,6 @@ public class World implements Disposable, SaveFileContent {
allPOIPathsToNextTown.add(Pair.of(poi, towns.get(smallestIndex)));
}
biomeIndex[0]++;
pix.setColor(0.8f, 0.8f, 0.9f, 1f);
//reset terrain path to the next town
for (Pair<PointOfInterest, PointOfInterest> poiToTown : allPOIPathsToNextTown) {
@@ -635,11 +642,10 @@ public class World implements Disposable, SaveFileContent {
int sy = startY < y1 ? 1 : -1;
int err = dx - dy;
int e2;
while (true) {
for (int i=0;i<1000;i++) {
if (startX < 0 || startY <= 0 || startX >= width || startY > height) continue;
biomeMap[startX][height - startY] |= (1L << biomeIndex[0]);
terrainMap[startX][height - startY] = 0;
pix.fillRectangle(startX*hudMapScale, (height - startY)*hudMapScale,hudMapScale,hudMapScale);
if (startX == x1 && startY == y1)
break;
@@ -655,6 +661,70 @@ public class World implements Disposable, SaveFileContent {
}
currentTime[0] = measureGenerationTime("roads", currentTime[0]);
//////////////////
///////// draw mini map
//////////////////
Pixmap pix = new Pixmap(width*data.miniMapTileSize, height*data.miniMapTileSize, Pixmap.Format.RGBA8888);
pix.setColor(1, 0, 0, 1);
pix.fill();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if(highestBiome(biomeMap[x][y])>=data.GetBiomes().size())
{
Pixmap smallPixmap=createSmallPixmap(data.roadTileset.tilesetAtlas,data.roadTileset.tilesetName,0);
pix.drawPixmap(smallPixmap,x*data.miniMapTileSize, y*data.miniMapTileSize);
}
else
{
BiomeData biome=data.GetBiomes().get( highestBiome(biomeMap[x][y]));
int terrainIndex=terrainMap[x][y]&~terrainMask;
if(terrainIndex>biome.terrain.length)
{
Pixmap smallPixmap=createSmallPixmap(biome.tilesetAtlas,biome.tilesetName,0);
pix.drawPixmap(smallPixmap,x*data.miniMapTileSize, y*data.miniMapTileSize);
terrainIndex-=biome.terrain.length;
terrainIndex--;
for(BiomeStructureData structData:biome.structures)
{
if(terrainIndex>=structData.mappingInfo.length)
{
terrainIndex-=structData.mappingInfo.length;
continue;
}
smallPixmap=createSmallPixmap(structData.structureAtlasPath,structData.mappingInfo[terrainIndex].name,0);
pix.drawPixmap(smallPixmap,x*data.miniMapTileSize, y*data.miniMapTileSize);
break;
}
}
else
{
Pixmap smallPixmap=createSmallPixmap(biome.tilesetAtlas,biome.tilesetName,terrainIndex);
pix.drawPixmap(smallPixmap,x*data.miniMapTileSize, y*data.miniMapTileSize);
}
}
}
}
for(Map.Entry<String, Pair<Pixmap, HashMap<String, Pixmap>>> entry:pixmapHash.entrySet())
{
entry.getValue().getLeft().dispose();
for(Map.Entry<String, Pixmap> pairEntry:entry.getValue().getRight().entrySet())
{
pairEntry.getValue().dispose();
}
}
drawPixmapNow(pix);
currentTime[0] = measureGenerationTime("mini map", currentTime[0]);
//////////////////
///////// distribute small rocks and trees across the map
//////////////////
mapObjectIds = new SpritesDataMap(getChunkSize(), data.tileSize, data.width / getChunkSize());
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
@@ -685,7 +755,6 @@ public class World implements Disposable, SaveFileContent {
}
}
}
drawPixmapNow(pix);
mapMarkerPixmap.dispose();
biomeImage = pix;
measureGenerationTime("sprites", currentTime[0]);
@@ -699,6 +768,42 @@ public class World implements Disposable, SaveFileContent {
return this;
}
HashMap<String,Pair<Pixmap,HashMap<String,Pixmap>>> pixmapHash=new HashMap<>();
private Pixmap createSmallPixmap(String tilesetName, String key, int i) {
if(i>2)i=2;
String tileSetNameWithIndex;
if(i==0)
tileSetNameWithIndex=(key);
else
tileSetNameWithIndex=(key+"_"+i);
if(!pixmapHash.containsKey(tilesetName))
{
TextureAtlas.AtlasRegion region;
TextureAtlas atlas=Config.instance().getAtlas(tilesetName);
region=atlas.findRegion(tileSetNameWithIndex);
TextureData data=region.getTexture().getTextureData();
if (!data.isPrepared()) {
data.prepare();
}
pixmapHash.put(tilesetName,Pair.of(data.consumePixmap(),new HashMap<>()));
}
Pair<Pixmap,HashMap<String,Pixmap>> pair=pixmapHash.get(tilesetName);
if(!pair.getRight().containsKey(tileSetNameWithIndex))
{
TextureAtlas atlas=Config.instance().getAtlas(tilesetName);
TextureAtlas.AtlasRegion region=atlas.findRegion(tileSetNameWithIndex);
int tileSize=data.tileSize;
Pixmap smallPixmap=new Pixmap(data.miniMapTileSize,data.miniMapTileSize, Pixmap.Format.RGBA8888);
smallPixmap.setColor(0,0,0,0);
smallPixmap.fill();
smallPixmap.drawPixmap(pair.getLeft(),0,0,region.getRegionX(),region.getRegionY(),data.miniMapTileSize,data.miniMapTileSize);
pair.getRight().put(tileSetNameWithIndex,smallPixmap);
}
return pair.getRight().get(tileSetNameWithIndex);
}
class DrawInfo
{
Pixmap mapMarkerPixmap;