Skip to content

Commit

Permalink
update logic: buyInstanceCostPack into ExistenceComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
hundun000 committed Oct 22, 2023
1 parent fa4a41f commit e368eeb
Show file tree
Hide file tree
Showing 28 changed files with 138 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ public DemoChildGameConfig() {
this.setConstructionConfig(
ConstructionConfig.builder()
.mainClickerConstructionPrototypeId(DemoConstructionPrototypeId.SINGLETON_COOKIE_MAIN_CLICKER)
.emptyConstructionConfig(EmptyConstructionConfig.builder()
.prototypeId(DemoConstructionPrototypeId.EMPTY_CELL)
.buyCandidatePrototypeIds(JavaFeatureForGwt.listOf(
DemoConstructionPrototypeId.COOKIE_SIMPLE_AUTO_PROVIDER,
DemoConstructionPrototypeId.COOKIE_COMPLEX_AUTO_PROVIDER
))
.build()
)
.singletonPrototypeIds(JavaFeatureForGwt.listOf(
DemoConstructionPrototypeId.SINGLETON_COOKIE_AUTO_SELLER
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public class CookieComplexAutoProviderPrototype extends AbstractConstructionProt
public CookieComplexAutoProviderPrototype(Language language) {
super(
DemoConstructionPrototypeId.COOKIE_COMPLEX_AUTO_PROVIDER,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
language
);
switch (language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public class CookieMainClickerPrototype extends AbstractConstructionPrototype {
public CookieMainClickerPrototype(Language language) {
super(
DemoConstructionPrototypeId.SINGLETON_COOKIE_MAIN_CLICKER,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
language
);
switch (language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public class CookieSimpleAutoProviderPrototype extends AbstractConstructionProto
public CookieSimpleAutoProviderPrototype(Language language) {
super(
DemoConstructionPrototypeId.COOKIE_SIMPLE_AUTO_PROVIDER,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
language
);
switch (language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public class CookieSingletonAutoSellerPrototype extends AbstractConstructionProt
public CookieSingletonAutoSellerPrototype(Language language) {
super(
DemoConstructionPrototypeId.SINGLETON_COOKIE_AUTO_SELLER,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
language
);
switch (language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class DirtPrototype extends AbstractConstructionPrototype {
public DirtPrototype(Language language) {
super(
DemoConstructionPrototypeId.EMPTY_CELL,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
language
);
switch (language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,32 @@
import hundun.gdxgame.corelib.base.util.DrawableFactory;
import hundun.gdxgame.idledemo.ui.screen.BaseDemoPlayScreen;
import hundun.gdxgame.idleshare.core.starter.ui.screen.play.PlayScreenLayoutConst;
import hundun.gdxgame.idleshare.gamelib.framework.data.ChildGameConfig.ConstructionBuyCandidateConfig;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;

public class WorldBuyConstructionInfoNodeVM extends Table {
BaseDemoPlayScreen parent;
BaseConstruction model;
Label constructionNameLabel;
TextButton buyButton;
String buyTargetConstructionPrototypeId;
ConstructionBuyCandidateConfig constructionBuyCandidateConfig;

public WorldBuyConstructionInfoNodeVM(
BaseDemoPlayScreen parent,
BaseConstruction model,
String buyTargetConstructionPrototypeId
ConstructionBuyCandidateConfig constructionBuyCandidateConfig
) {
super();
final PlayScreenLayoutConst playScreenLayoutConst = parent.getLayoutConst();
this.parent = parent;
this.buyTargetConstructionPrototypeId = buyTargetConstructionPrototypeId;
this.constructionBuyCandidateConfig = constructionBuyCandidateConfig;
this.model = model;

int CHILD_WIDTH = playScreenLayoutConst.CONSTRUCION_CHILD_WIDTH;
int CHILD_HEIGHT = playScreenLayoutConst.CONSTRUCION_CHILD_BUTTON_HEIGHT;
int NAME_CHILD_HEIGHT = playScreenLayoutConst.CONSTRUCION_CHILD_NAME_HEIGHT;

this.constructionNameLabel = new Label(buyTargetConstructionPrototypeId, parent.getGame().getMainSkin());
this.constructionNameLabel = new Label(constructionBuyCandidateConfig.getPrototypeId(), parent.getGame().getMainSkin());
constructionNameLabel.setWrap(true);

this.buyButton = new TextButton("buy", parent.getGame().getMainSkin());
Expand All @@ -42,7 +43,7 @@ public WorldBuyConstructionInfoNodeVM(
public void changed(ChangeEvent event, Actor actor) {
parent.getGame().getIdleGameplayExport().getGameplayContext()
.getConstructionManager()
.buyInstanceOfPrototype(buyTargetConstructionPrototypeId, model.getPosition());
.buyInstanceOfPrototype(constructionBuyCandidateConfig, model.getPosition());
}
});

Expand Down Expand Up @@ -73,14 +74,14 @@ public void update() {
.getGameDictionary()
.constructionPrototypeIdToShowName(
parent.getGame().getIdleGameplayExport().getLanguage(),
buyTargetConstructionPrototypeId
constructionBuyCandidateConfig.getPrototypeId()
)
);

// ------ update clickable-state ------
boolean canBuyInstanceOfPrototype = parent.getGame().getIdleGameplayExport().getGameplayContext()
.getConstructionManager()
.canBuyInstanceOfPrototype(buyTargetConstructionPrototypeId, model.getPosition());
.canBuyInstanceOfPrototype(constructionBuyCandidateConfig, model.getPosition());
if (!canBuyInstanceOfPrototype) {
buyButton.setDisabled(false);
buyButton.getLabel().setColor(Color.WHITE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,10 @@ private void updateAsConstructionPrototypeDetail(BaseConstruction construction)
this.clearChildren();
contents.clear();

AbstractConstructionPrototype constructionPrototype = screen.getGame().getIdleGameplayExport()
.getGameplayContext()
.getConstructionManager()
.getEmptyConstructionPrototype();


WorldConstructionPrototypeCellDetailNode innerBoardVM = new WorldConstructionPrototypeCellDetailNode(screen);
innerBoardVM.updateAsConstructionPrototype(construction, constructionPrototype, construction.getSaveData().getPosition());
innerBoardVM.updateAsConstructionPrototype(construction, construction.getSaveData().getPosition());
this.add(innerBoardVM);
contents.add(innerBoardVM);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import hundun.gdxgame.corelib.base.util.DrawableFactory;
import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt;
Expand Down Expand Up @@ -127,7 +124,7 @@ private void update() {
upgradeButton.setDisabled(true);
upgradeButton.getLabel().setColor(Color.RED);
}
if (model.getExistenceComponent().canDestory())
if (model.getExistenceComponent().canDestroy())
{
destoryButton.setDisabled(false);
destoryButton.getLabel().setColor(Color.WHITE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import hundun.gdxgame.idledemo.ui.screen.BaseDemoPlayScreen;
import hundun.gdxgame.idledemo.ui.shared.BaseCellDetailNodeVM;
import hundun.gdxgame.idleshare.core.starter.ui.screen.play.PlayScreenLayoutConst;
import hundun.gdxgame.idleshare.gamelib.framework.data.ChildGameConfig.ConstructionBuyCandidateConfig;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.AbstractConstructionPrototype;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
import hundun.gdxgame.idleshare.gamelib.framework.model.grid.GridPosition;
Expand All @@ -20,7 +21,7 @@
*/
public class WorldConstructionPrototypeCellDetailNode extends BaseCellDetailNodeVM {
BaseDemoPlayScreen parent;
AbstractConstructionPrototype constructionPrototype;
BaseConstruction construction;
GridPosition position;
Label constructionNameLabel;

Expand Down Expand Up @@ -56,7 +57,7 @@ public WorldConstructionPrototypeCellDetailNode(

private void update() {
// ------ update show-state ------
if (constructionPrototype == null) {
if (construction == null) {
setVisible(false);
//textButton.setVisible(false);
//Gdx.app.log("ConstructionView", this.hashCode() + " no model");
Expand All @@ -76,7 +77,7 @@ private void update() {
.getGameDictionary()
.constructionPrototypeIdToDetailDescriptionConstPart(
parent.getGame().getIdleGameplayExport().getLanguage(),
constructionPrototype.getPrototypeId()
construction.getPrototypeId()
),
position.getX(),
position.getY()
Expand All @@ -93,20 +94,16 @@ public void subLogicFrame() {

public void updateAsConstructionPrototype(
BaseConstruction construction,
AbstractConstructionPrototype constructionPrototype,
GridPosition position
) {
this.constructionPrototype = constructionPrototype;
this.construction = construction;
this.position = position;

List<String> buyCandidateConstructionPrototypeIds = parent.getGame().getIdleGameplayExport().getGameplayContext()
.getConstructionManager()
.getByCandidatePrototypeIds();
buyCandidateConstructionPrototypeIds.forEach(constructionPrototypeId -> {
construction.getExistenceComponent().getBuyCandidateConfigs().forEach(constructionBuyCandidateConfig -> {
WorldBuyConstructionInfoNodeVM vm = new WorldBuyConstructionInfoNodeVM(
parent,
construction,
constructionPrototypeId
constructionBuyCandidateConfig
);
vm.update();
this.add(vm);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package hundun.gdxgame.idledemo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt;
Expand All @@ -22,13 +20,6 @@ public DemoChildGameConfig() {
this.setConstructionConfig(
ConstructionConfig.builder()
.mainClickerConstructionPrototypeId(DemoConstructionPrototypeId.MAIN_MUSHROOM)
.emptyConstructionConfig(EmptyConstructionConfig.builder()
.prototypeId(DemoConstructionPrototypeId.EPOCH_1_EMPTY_CELL)
.buyCandidatePrototypeIds(JavaFeatureForGwt.listOf(
DemoConstructionPrototypeId.EPOCH_1_MUSHROOM_AUTO_PROVIDER
))
.build()
)
.singletonPrototypeIds(JavaFeatureForGwt.listOf(
DemoConstructionPrototypeId.MUSHROOM_AUTO_SELLER,
DemoConstructionPrototypeId.EPOCH_COUNTER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public class AutoProviderPrototype extends AbstractConstructionPrototype {
public AutoProviderPrototype(String prototypeId, RootEpochConfig rootEpochConfig, Language language) {
super(
prototypeId,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
language
);
this.rootEpochConfig = rootEpochConfig;
switch (language)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public class AutoSellerPrototype extends AbstractConstructionPrototype {
public AutoSellerPrototype(Language language) {
super(
DemoConstructionPrototypeId.MUSHROOM_AUTO_SELLER,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
language
);
switch (language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt;
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;
import hundun.gdxgame.idleshare.gamelib.framework.data.ChildGameConfig.ConstructionBuyCandidateConfig;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.AbstractConstructionPrototype;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.DescriptionPackage;
Expand All @@ -30,8 +32,7 @@ public class DirtPrototype extends AbstractConstructionPrototype {
public DirtPrototype(Language language) {
super(
DemoConstructionPrototypeId.EPOCH_1_EMPTY_CELL,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
language
);
switch (language)
{
Expand All @@ -57,6 +58,22 @@ public BaseConstruction getInstance(GridPosition position) {
SimpleAutoOutputComponent outputComponent = new SimpleAutoOutputComponent(thiz);
thiz.setOutputComponent(outputComponent);


switch (prototypeId) {
case DemoConstructionPrototypeId.EPOCH_1_EMPTY_CELL:
thiz.getExistenceComponent().setBuyCandidateConfigs(JavaFeatureForGwt.listOf(
ConstructionBuyCandidateConfig.builder()
.prototypeId(DemoConstructionPrototypeId.EPOCH_1_MUSHROOM_AUTO_PROVIDER)
.buyCostPack(DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf(
ResourceType.MUSHROOM, 50
)))
.build()
));
break;
default:
}


return thiz;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class EpochCounterPrototype extends AbstractConstructionPrototype {
public EpochCounterPrototype(Language language) {
super(
DemoConstructionPrototypeId.EPOCH_COUNTER,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
language
);
switch (language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public class MainMushroomPrototype extends AbstractConstructionPrototype {
public MainMushroomPrototype(Language language) {
super(
DemoConstructionPrototypeId.MAIN_MUSHROOM,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
language
);
switch (language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class TreePrototype extends AbstractConstructionPrototype {
public TreePrototype(String prototypeId, Language language) {
super(
prototypeId,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
language
);
switch (language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,9 @@ private void updateAsConstructionPrototypeDetail(BaseConstruction construction)
{
this.clearChildren();

AbstractConstructionPrototype constructionPrototype = screen.getGame().getIdleGameplayExport()
.getGameplayContext()
.getConstructionManager()
.getEmptyConstructionPrototype();


WorldConstructionPrototypeCellDetailNode innerBoardVM = new WorldConstructionPrototypeCellDetailNode(screen);
innerBoardVM.updateAsConstructionPrototype(construction, constructionPrototype, construction.getSaveData().getPosition());
innerBoardVM.updateAsConstructionPrototype(construction, construction.getSaveData().getPosition());
this.add(innerBoardVM)
.width(screen.getLayoutConst().WorldConstructionCellDetailNodeWidth)
.height(screen.getLayoutConst().WorldConstructionCellDetailNodeHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void changed(ChangeEvent event, Actor actor) {
@Override
public void changed(ChangeEvent event, Actor actor) {
parent.getGame().getFrontend().log(this.getClass().getSimpleName(), "transformButton clicked");
model.getUpgradeComponent().doTransfer();
model.getUpgradeComponent().doTransform();
}
});

Expand Down
Loading

0 comments on commit e368eeb

Please sign in to comment.