Skip to content

Commit

Permalink
add buyConstructionInstance logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hundun000 committed Sep 17, 2023
1 parent 24ddcc3 commit c32de4f
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import java.util.Map;

import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt;
import hundun.gdxgame.idledemo.logic.ConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.DemoConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.GameArea;
import hundun.gdxgame.idledemo.logic.DemoAchievementId;
import hundun.gdxgame.idledemo.logic.ResourceType;
import hundun.gdxgame.idledemo.ui.screen.DemoMenuScreen;
import hundun.gdxgame.idledemo.ui.screen.CookiePlayScreen;
Expand All @@ -26,15 +25,15 @@ public DemoChildGameConfig() {

Map<String, List<String>> areaControlableConstructionVMPrototypeIds = new HashMap<>();
areaControlableConstructionVMPrototypeIds.put(GameArea.AREA_COOKIE, JavaFeatureForGwt.arraysAsList(
ConstructionPrototypeId.COOKIE_CLICK_PROVIDER,
ConstructionPrototypeId.COOKIE_AUTO_PROVIDER,
ConstructionPrototypeId.COOKIE_AUTO_SELLER
DemoConstructionPrototypeId.COOKIE_CLICK_PROVIDER,
DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER,
DemoConstructionPrototypeId.COOKIE_AUTO_SELLER
));
this.setAreaControlableConstructionVMPrototypeIds(areaControlableConstructionVMPrototypeIds);

Map<String, List<String>> areaControlableConstructionPrototypeVMPrototypeIds = new HashMap<>();
areaControlableConstructionPrototypeVMPrototypeIds.put(GameArea.AREA_FOREST, JavaFeatureForGwt.listOf(
ConstructionPrototypeId.EMPTY_CELL
DemoConstructionPrototypeId.EMPTY_CELL
));
this.setAreaControlableConstructionPrototypeVMPrototypeIds(areaControlableConstructionPrototypeVMPrototypeIds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Map<String, AbstractAchievement> getProviderMap(Language language) {
DemoAchievementId.STEP_1,
textMap,
JavaFeatureForGwt.mapOf(
ConstructionPrototypeId.COOKIE_AUTO_PROVIDER, new SimpleEntry<>(1, 2)
DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER, new SimpleEntry<>(1, 2)
),
DemoAchievementId.STEP_2,
new ResourcePair(ResourceType.COIN, 1000L)
Expand All @@ -62,7 +62,7 @@ public Map<String, AbstractAchievement> getProviderMap(Language language) {
DemoAchievementId.STEP_2,
textMap,
JavaFeatureForGwt.mapOf(
ConstructionPrototypeId.COOKIE_AUTO_SELLER, new SimpleEntry<>(1, 2)
DemoConstructionPrototypeId.COOKIE_AUTO_SELLER, new SimpleEntry<>(1, 2)
),
null,
new ResourcePair(ResourceType.COIN, 1000L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class DemoBuiltinConstructionsLoader implements IBuiltinConstructionsLoad
@Override
public Map<String, AbstractConstructionPrototype> getProviderMap(Language language) {
Map<String, AbstractConstructionPrototype> result = new HashMap<>();
result.put(ConstructionPrototypeId.EMPTY_CELL, new DirtPrototype(language));
result.put(ConstructionPrototypeId.COOKIE_CLICK_PROVIDER, new CookieClickProviderPrototype(language));
result.put(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER, new CookieAutoProviderPrototype(language));
result.put(ConstructionPrototypeId.COOKIE_AUTO_SELLER, new CookieAutoSellerPrototype(language));
result.put(DemoConstructionPrototypeId.EMPTY_CELL, new DirtPrototype(language));
result.put(DemoConstructionPrototypeId.COOKIE_CLICK_PROVIDER, new CookieClickProviderPrototype(language));
result.put(DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER, new CookieAutoProviderPrototype(language));
result.put(DemoConstructionPrototypeId.COOKIE_AUTO_SELLER, new CookieAutoSellerPrototype(language));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@



public class ConstructionPrototypeId {
public class DemoConstructionPrototypeId {

public static final String COOKIE_CLICK_PROVIDER = "ENUM_CSTR@COOKIE_CLICK_PROVIDER";
public static final String COOKIE_AUTO_PROVIDER = "ENUM_CSTR@COOKIE_AUTO_PROVIDER";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ public String constructionPrototypeIdToShowName(Language language, String constr
switch (language) {
case CN:
switch (constructionId) {
case ConstructionPrototypeId.COOKIE_CLICK_PROVIDER:
case DemoConstructionPrototypeId.COOKIE_CLICK_PROVIDER:
return "点击器";
case ConstructionPrototypeId.COOKIE_AUTO_PROVIDER:
case DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER:
return "自动点击器";
case ConstructionPrototypeId.COOKIE_AUTO_SELLER:
case DemoConstructionPrototypeId.COOKIE_AUTO_SELLER:
return "自动出售器";
default:
return "口口";
}
default:
switch (constructionId) {
case ConstructionPrototypeId.COOKIE_CLICK_PROVIDER:
case DemoConstructionPrototypeId.COOKIE_CLICK_PROVIDER:
return "Clicker";
case ConstructionPrototypeId.COOKIE_AUTO_PROVIDER:
case DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER:
return "AutoClicker";
case ConstructionPrototypeId.COOKIE_AUTO_SELLER:
case DemoConstructionPrototypeId.COOKIE_AUTO_SELLER:
return "AutoSeller";
default:
return "[dic lost]";
Expand All @@ -48,18 +48,18 @@ public String constructionPrototypeIdToDetailDescroptionConstPart(Language langu
switch (language) {
case CN:
switch (constructionId) {
case ConstructionPrototypeId.COOKIE_AUTO_PROVIDER:
case DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER:
return "自动获得饼干";
case ConstructionPrototypeId.EMPTY_CELL:
case DemoConstructionPrototypeId.EMPTY_CELL:
return "空位置";
default:
return "[dic lost]";
}
default:
switch (constructionId) {
case ConstructionPrototypeId.COOKIE_AUTO_PROVIDER:
case DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER:
return "Auto gain some cookie";
case ConstructionPrototypeId.EMPTY_CELL:
case DemoConstructionPrototypeId.EMPTY_CELL:
return "Empty";
default:
return "[dic lost]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import hundun.gdxgame.idleshare.gamelib.framework.data.GameplaySaveData;
import hundun.gdxgame.idleshare.gamelib.framework.data.SystemSettingSaveData;
import hundun.gdxgame.idleshare.gamelib.framework.model.grid.GridPosition;
import hundun.gdxgame.idleshare.gamelib.framework.model.manager.AchievementManager;
import hundun.gdxgame.idleshare.gamelib.framework.model.manager.AchievementManager.AchievementSaveData;
import hundun.gdxgame.idleshare.gamelib.framework.model.manager.AchievementManager.AchievementState;
import hundun.gdxgame.idleshare.gamelib.framework.util.text.Language;
Expand All @@ -31,27 +30,27 @@ protected RootSaveData genereateStarterRootSaveData() {
Map<String, ConstructionSaveData> map = new HashMap<>();

map.put(
ConstructionPrototypeId.COOKIE_CLICK_PROVIDER + "_" + UUID.randomUUID(),
DemoConstructionPrototypeId.COOKIE_CLICK_PROVIDER + "_" + UUID.randomUUID(),
ConstructionSaveData.builder()
.prototypeId(ConstructionPrototypeId.COOKIE_CLICK_PROVIDER)
.prototypeId(DemoConstructionPrototypeId.COOKIE_CLICK_PROVIDER)
.level(0)
.workingLevel(0)
.position( new GridPosition(0, 0))
.build()
);
map.put(
ConstructionPrototypeId.COOKIE_AUTO_PROVIDER + "_" + UUID.randomUUID(),
DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER + "_" + UUID.randomUUID(),
ConstructionSaveData.builder()
.prototypeId(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER)
.prototypeId(DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER)
.level(1)
.workingLevel(1)
.position( new GridPosition(0, 1))
.build()
);
map.put(
ConstructionPrototypeId.COOKIE_AUTO_SELLER + "_" + UUID.randomUUID(),
DemoConstructionPrototypeId.COOKIE_AUTO_SELLER + "_" + UUID.randomUUID(),
ConstructionSaveData.builder()
.prototypeId(ConstructionPrototypeId.COOKIE_AUTO_SELLER)
.prototypeId(DemoConstructionPrototypeId.COOKIE_AUTO_SELLER)
.level(1)
.workingLevel(0)
.position( new GridPosition(1, 0))
Expand All @@ -64,9 +63,9 @@ protected RootSaveData genereateStarterRootSaveData() {
);
dirtGridPositions.forEach(it -> {
map.put(
ConstructionPrototypeId.EMPTY_CELL + "_" + UUID.randomUUID(),
DemoConstructionPrototypeId.EMPTY_CELL + "_" + UUID.randomUUID(),
ConstructionSaveData.builder()
.prototypeId(ConstructionPrototypeId.EMPTY_CELL)
.prototypeId(DemoConstructionPrototypeId.EMPTY_CELL)
.level(0)
.workingLevel(0)
.position(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void lazyInitOnGameCreateStage2() {
Texture texture = new Texture(Gdx.files.internal("constructionEntities.png"));
TextureRegion[][] regions = TextureRegion.split(texture, 32, 32);
//constructionEntityMap.put(ConstructionId.COOKIE_CLICK_PROVIDER, regions[0][0]);
constructionEntityMap.put(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER, regions[0][1]);
constructionEntityMap.put(DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER, regions[0][1]);
//constructionEntityMap.put(ConstructionPrototypeId.COOKIE_SELLER, regions[0][2]);
//constructionEntityMap.put(ConstructionId.WIN_PROVIDER, regions[0][3]);
}
Expand All @@ -65,10 +65,10 @@ public void lazyInitOnGameCreateStage2() {
Texture texture = new Texture(Gdx.files.internal("CellIcons.png"));
TextureRegion[][] regions = TextureRegion.split(texture, 128, 128);
defaultAreaBack = regions[0][1];
constructionHexImageMap.put(ConstructionPrototypeId.EMPTY_CELL, regions[0][0]);
constructionHexImageMap.put(ConstructionPrototypeId.COOKIE_CLICK_PROVIDER, regions[0][1]);
constructionHexImageMap.put(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER, regions[0][2]);
constructionHexImageMap.put(ConstructionPrototypeId.COOKIE_AUTO_SELLER, regions[0][3]);
constructionHexImageMap.put(DemoConstructionPrototypeId.EMPTY_CELL, regions[0][0]);
constructionHexImageMap.put(DemoConstructionPrototypeId.COOKIE_CLICK_PROVIDER, regions[0][1]);
constructionHexImageMap.put(DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER, regions[0][2]);
constructionHexImageMap.put(DemoConstructionPrototypeId.COOKIE_AUTO_SELLER, regions[0][3]);
//gameAreaBackMap.put(GameArea.AREA_WIN, regions[0][3]);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hundun.gdxgame.idledemo.logic.prototype;

import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt;
import hundun.gdxgame.idledemo.logic.ConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.DemoConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.DemoBuiltinConstructionsLoader;
import hundun.gdxgame.idledemo.logic.ResourceType;
import hundun.gdxgame.idledemo.logic.construction.BaseIdleDemoConstruction;
Expand Down Expand Up @@ -39,7 +39,7 @@ public class CookieAutoProviderPrototype extends AbstractConstructionPrototype {

public CookieAutoProviderPrototype(Language language) {
super(
ConstructionPrototypeId.COOKIE_AUTO_PROVIDER,
DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hundun.gdxgame.idledemo.logic.prototype;

import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt;
import hundun.gdxgame.idledemo.logic.ConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.DemoConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.DemoBuiltinConstructionsLoader;
import hundun.gdxgame.idledemo.logic.ResourceType;
import hundun.gdxgame.idledemo.logic.construction.BaseIdleDemoConstruction;
Expand Down Expand Up @@ -39,7 +39,7 @@ public class CookieAutoSellerPrototype extends AbstractConstructionPrototype {

public CookieAutoSellerPrototype(Language language) {
super(
ConstructionPrototypeId.COOKIE_AUTO_SELLER,
DemoConstructionPrototypeId.COOKIE_AUTO_SELLER,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hundun.gdxgame.idledemo.logic.prototype;

import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt;
import hundun.gdxgame.idledemo.logic.ConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.DemoConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.DemoBuiltinConstructionsLoader;
import hundun.gdxgame.idledemo.logic.ResourceType;
import hundun.gdxgame.idledemo.logic.construction.BaseIdleDemoConstruction;
Expand Down Expand Up @@ -35,7 +35,7 @@ public class CookieClickProviderPrototype extends AbstractConstructionPrototype

public CookieClickProviderPrototype(Language language) {
super(
ConstructionPrototypeId.COOKIE_CLICK_PROVIDER,
DemoConstructionPrototypeId.COOKIE_CLICK_PROVIDER,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hundun.gdxgame.idledemo.logic.prototype;

import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt;
import hundun.gdxgame.idledemo.logic.ConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.DemoConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.DemoBuiltinConstructionsLoader;
import hundun.gdxgame.idledemo.logic.construction.BaseIdleDemoConstruction;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.AbstractConstructionPrototype;
Expand All @@ -27,7 +27,7 @@ public class DirtPrototype extends AbstractConstructionPrototype {

public DirtPrototype(Language language) {
super(
ConstructionPrototypeId.EMPTY_CELL,
DemoConstructionPrototypeId.EMPTY_CELL,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hundun.gdxgame.idledemo.ui.entity;

import hundun.gdxgame.idledemo.logic.ConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.DemoConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.ResourceType;
import hundun.gdxgame.idledemo.ui.screen.CookiePlayScreen;
import hundun.gdxgame.idleshare.core.framework.model.entity.BaseGameEntityFactory;
Expand All @@ -25,7 +25,7 @@ public GameEntityFactory(PlayScreenLayoutConst layoutConst, CookiePlayScreen par

public GameEntity newConstructionEntity(String id, int index) {
switch (id) {
case ConstructionPrototypeId.COOKIE_AUTO_PROVIDER:
case DemoConstructionPrototypeId.COOKIE_AUTO_PROVIDER:
return this.rowStableConstructionEntity(id, index, 1);
default:
// no need GameEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import hundun.gdxgame.idledemo.ui.world.HexAreaVM;
import hundun.gdxgame.idledemo.ui.world.WorldCellDetailBoardVM;
import hundun.gdxgame.idleshare.core.framework.model.CameraDataPackage;
import hundun.gdxgame.idleshare.gamelib.framework.callback.IConstructionCollectionListener;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;

import java.util.List;
Expand All @@ -20,7 +21,7 @@
* @author hundun
* Created on 2021/11/02
*/
public class WorldPlayScreen extends BaseDemoPlayScreen {
public class WorldPlayScreen extends BaseDemoPlayScreen implements IConstructionCollectionListener {

HexAreaVM hexAreaVM;
protected OrthographicCamera deskCamera;
Expand Down Expand Up @@ -102,4 +103,11 @@ protected InputProcessor provideDefaultInputProcessor() {
public void onDeskClicked(HexCellVM vm) {
worldCellDetailBoardVM.updateDetail(vm != null ? vm.getDeskData() : null);
}

@Override
public void onConstructionCollectionChange() {
List<BaseConstruction> constructions = game.getIdleGameplayExport().getGameplayContext().getConstructionManager()
.getConstructions();
hexAreaVM.updateDeskDatas(constructions);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hundun.gdxgame.idledemo.ui.world;

import hundun.gdxgame.idledemo.logic.ConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.DemoConstructionPrototypeId;
import hundun.gdxgame.idledemo.ui.screen.WorldPlayScreen;
import hundun.gdxgame.idleshare.gamelib.framework.callback.IConstructionCollectionListener;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.AbstractConstructionPrototype;
Expand All @@ -13,7 +13,7 @@
public class WorldCellDetailBoardVM extends BaseCellDetailBoardVM implements IConstructionCollectionListener {
@Getter
@Setter
public BaseConstruction data;
public BaseConstruction detailingConstruction;


public WorldCellDetailBoardVM(WorldPlayScreen parent)
Expand All @@ -24,7 +24,7 @@ public WorldCellDetailBoardVM(WorldPlayScreen parent)

public void updateDetail(BaseConstruction construction)
{
this.data = construction;
this.detailingConstruction = construction;
if (construction == null)
{
updateAsEmpty();
Expand All @@ -33,7 +33,7 @@ public void updateDetail(BaseConstruction construction)

switch (construction.getPrototypeId())
{
case ConstructionPrototypeId.EMPTY_CELL:
case DemoConstructionPrototypeId.EMPTY_CELL:
updateAsConstructionPrototypeDetail(construction);
break;
default:
Expand Down Expand Up @@ -81,10 +81,10 @@ private void updateAsConstructionPrototypeDetail(BaseConstruction construction)
@Override
public void onConstructionCollectionChange()
{
if (data != null)
if (detailingConstruction != null)
{
data = parent.getGame().getIdleGameplayExport().getGameplayContext().getConstructionManager().getConstructionAt(data.getPosition());
updateDetail(data);
detailingConstruction = parent.getGame().getIdleGameplayExport().getGameplayContext().getConstructionManager().getConstructionAt(detailingConstruction.getPosition());
updateDetail(detailingConstruction);
}
}
}
Loading

0 comments on commit c32de4f

Please sign in to comment.