Skip to content

Commit

Permalink
Enhance single player mode (#101)
Browse files Browse the repository at this point in the history
* [add] Enable initializing BwTileMap without a map file name.

* [update] Update proto.

* [update] Update BwField.

* [add] Enable creating simulation wars.

* [add] Enable creating simulation wars for custom maps.

* [add] Enable creating simulation wars for replays.

Also fixes #100.
  • Loading branch information
Babygogogo committed Mar 15, 2020
1 parent b6f1fbb commit db77910
Show file tree
Hide file tree
Showing 87 changed files with 1,764 additions and 425 deletions.
23 changes: 12 additions & 11 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@
"bin-debug/utility/Notify.js",
"bin-debug/utility/Logger.js",
"bin-debug/utility/Lang.js",
"bin-debug/utility/ProtoTypes.js",
"bin-debug/utility/Helpers.js",
"bin-debug/utility/ProtoTypes.js",
"bin-debug/utility/FloatText.js",
"bin-debug/network/NetManager.js",
"bin-debug/utility/ConfigManager.js",
"bin-debug/utility/LocalStorage.js",
"bin-debug/utility/GridIndexHelpers.js",
"bin-debug/modules/warMap/model/WarMapModel.js",
"bin-debug/modules/baseWar/model/BwUnitMap.js",
"bin-debug/modules/baseWar/model/BwWar.js",
"bin-debug/modules/baseWar/model/BwTile.js",
"bin-debug/gameui/UiPanel.js",
"bin-debug/modules/baseWar/model/BwUnit.js",
"bin-debug/modules/baseWar/model/BwUnitMap.js",
"bin-debug/utility/WarActionCodes.js",
"bin-debug/utility/DestructionHelpers.js",
"bin-debug/utility/VisibilityHelpers.js",
"bin-debug/modules/baseWar/model/BwHelpers.js",
"bin-debug/utility/VisibilityHelpers.js",
"bin-debug/utility/LocalStorage.js",
"bin-debug/utility/DestructionHelpers.js",
"bin-debug/modules/common/view/AlertPanel.js",
"bin-debug/modules/mapEditor/model/MeManager.js",
"bin-debug/modules/multiCustomWar/model/McwModel.js",
Expand All @@ -45,17 +44,18 @@
"bin-debug/modules/singleCustomWar/model/ScwModel.js",
"bin-debug/modules/time/model/TimeModel.js",
"bin-debug/modules/user/model/UserModel.js",
"bin-debug/modules/warMap/model/WarMapModel.js",
"bin-debug/modules/baseWar/view/BwFieldView.js",
"bin-debug/modules/baseWar/view/BwTileView.js",
"bin-debug/modules/common/view/BlockPanel.js",
"bin-debug/modules/common/view/ConfirmPanel.js",
"bin-debug/gameui/UiImage.js",
"bin-debug/modules/baseWar/view/BwUnitView.js",
"bin-debug/modules/baseWar/view/BwUnitMapView.js",
"bin-debug/modules/baseWar/view/BwTileView.js",
"bin-debug/modules/baseWar/view/BwWarView.js",
"bin-debug/modules/warMap/model/WarMapProxy.js",
"bin-debug/modules/baseWar/view/BwTileMapView.js",
"bin-debug/modules/baseWar/view/BwGridVisionEffectView.js",
"bin-debug/modules/baseWar/view/BwWarView.js",
"bin-debug/modules/baseWar/view/BwUnitView.js",
"bin-debug/modules/baseWar/view/BwCursorView.js",
"bin-debug/utility/DamageCalculator.js",
"bin-debug/modules/baseWar/view/BwActionPlannerView.js",
Expand Down Expand Up @@ -152,8 +152,8 @@
"bin-debug/modules/multiCustomWar/model/McwTurnManager.js",
"bin-debug/modules/multiCustomWar/model/McwUnit.js",
"bin-debug/modules/multiCustomWar/model/McwUnitMap.js",
"bin-debug/modules/multiCustomWar/model/McwWar.js",
"bin-debug/Platform.js",
"bin-debug/modules/multiCustomWar/view/McwActionPlannerView.js",
"bin-debug/modules/multiCustomWar/view/McwBackgroundPanel.js",
"bin-debug/modules/multiCustomWar/view/McwCoListPanel.js",
"bin-debug/modules/multiCustomWar/view/McwCursorView.js",
Expand Down Expand Up @@ -213,6 +213,7 @@
"bin-debug/modules/singleCustomRoom/view/ScrCreateAdvancedSettingsPage.js",
"bin-debug/modules/singleCustomRoom/view/ScrCreateBasicSettingsPage.js",
"bin-debug/modules/singleCustomRoom/view/ScrCreateCoListPanel.js",
"bin-debug/modules/singleCustomRoom/view/ScrCreateCustomSaveSlotsPanel.js",
"bin-debug/modules/singleCustomRoom/view/ScrCreateMapListPanel.js",
"bin-debug/modules/singleCustomRoom/view/ScrCreateSaveSlotsPanel.js",
"bin-debug/modules/singleCustomRoom/view/ScrCreateSearchMapPanel.js",
Expand Down Expand Up @@ -291,6 +292,6 @@
"bin-debug/modules/mapEditor/model/MeUnit.js",
"bin-debug/modules/mapEditor/model/MeUnitMap.js",
"bin-debug/modules/mapEditor/model/MeUtility.js",
"bin-debug/modules/multiCustomWar/model/McwWar.js"
"bin-debug/modules/multiCustomWar/view/McwActionPlannerView.js"
]
}
2 changes: 1 addition & 1 deletion resource/config/NetMessageProto.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions resource/default.thm.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"resource/skins/singleCustomRoom/ScrCreateAdvancedSettingsPage.exml",
"resource/skins/singleCustomRoom/ScrCreateBasicSettingsPage.exml",
"resource/skins/singleCustomRoom/ScrCreateCoListPanel.exml",
"resource/skins/singleCustomRoom/ScrCreateCustomSaveSlotsPanel.exml",
"resource/skins/singleCustomRoom/ScrCreateMapListPanel.exml",
"resource/skins/singleCustomRoom/ScrCreateSaveSlotsPanel.exml",
"resource/skins/singleCustomRoom/ScrCreateSearchMapPanel.exml",
Expand Down
6 changes: 4 additions & 2 deletions resource/skins/lobby/LobbyPanel.exml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
</e:List>
</GameUi:UiScrollList>
</e:Group>
<GameUi:UiLabel text="Thank you for playing Tiny Wars!\nTo start, touch the scroll list to the right." textColor="0xffffff" horizontalCenter="-110"
verticalCenter="0" verticalAlign="middle" textAlign="center" size="25" />
<GameUi:UiLabel id="_labelTips"
text="Thank you for playing Tiny Wars!\nTo start, touch the scroll list to the right."
textColor="0xffffff" horizontalCenter="-110" verticalCenter="0" verticalAlign="middle"
textAlign="center" size="25" />
</e:Skin>
2 changes: 2 additions & 0 deletions resource/skins/singleCustomRoom/ScrContinueWarListPanel.exml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<GameUi:UiLabel id="_labelMapName" text="地图名: 未知" y="0" stroke="2" size="20" scaleX="1" scaleY="1" />
<GameUi:UiLabel id="_labelDesigner" text="作者: 未知" y="25" stroke="2" size="20" scaleX="1" scaleY="1" />
</e:Group>
<GameUi:UiLabel id="_labelNoPreview" text="暂无预览" stroke="2" size="40" scaleX="1" scaleY="1" horizontalCenter="0"
verticalCenter="0" />
</e:Group>
<e:Group top="40" bottom="0" width="200" right="0">
<GameUi:UiImage source="c04_t01_s02_f01" scale9Grid="9,9,2,2" anchorOffsetX="0" anchorOffsetY="0" alpha="0.8"
Expand Down
50 changes: 50 additions & 0 deletions resource/skins/singleCustomRoom/ScrCreateCustomSaveSlotsPanel.exml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<e:Skin width="960" height="540" xmlns:e="http://ns.egret.com/eui" xmlns:GameUi="TinyWars.GameUi.*"
xmlns:w="http://ns.egret.com/wing">
<GameUi:UiImage left="0" right="0" top="0" bottom="0" source="semi_transparent" />
<e:Group id="_group" top="60" bottom="60" width="640" horizontalCenter="0">
<GameUi:UiImage source="c04_t01_s02_f01" scale9Grid="9,9,2,2" anchorOffsetX="0" anchorOffsetY="0" alpha="0.8"
left="0" right="0" top="0" bottom="0" />
<GameUi:UiButton id="_btnHelp" label="帮助" top="10" left="10">
<GameUi:skinName>
<e:Skin states="up,down,disabled">
<e:Image width="100%" height="100%" />
<e:Label id="labelDisplay" size="20" bold="true" left="0" right="0" top="0" bottom="0"
textColor="0x00ff00" />
</e:Skin>
</GameUi:skinName>
</GameUi:UiButton>
<GameUi:UiLabel id="_labelPanelTitle" text="选择存档位置" y="10" size="20" horizontalCenter="0" />
<GameUi:UiButton id="_btnCancel" label="取消" right="10" top="10">
<GameUi:skinName>
<e:Skin states="up,down,disabled">
<e:Image width="100%" height="100%" />
<e:Label id="labelDisplay" size="20" bold="true" left="0" right="0" top="0" bottom="0"
textColor="0xff0000" />
</e:Skin>
</GameUi:skinName>
</GameUi:UiButton>
<GameUi:UiScrollList id="_srlSaveSlot" left="15" right="15" bottom="10" top="40">
<e:List id="_listSaveSlot" requireSelection="true">
<e:itemRendererSkinName>
<e:Skin width="298" height="60" currentState="up" states="down,up">
<e:Group id="_group" left="0" right="0" top="0" bottom="0">
<GameUi:UiImage id="_imgBg" source="c04_t01_s02_f01" scale9Grid="9,9,2,2" anchorOffsetX="0"
anchorOffsetY="0" alpha="0.8" left="0" right="0" top="0" bottom="0"
visible.up="false" />
<GameUi:UiLabel id="_labelSlotIndex" text="1" size="12" textColor="0xffffff" y="8" x="10" />
<GameUi:UiLabel id="_labelType" text="自由战斗" size="12" textColor="0xFFFFFF" y="8" x="30" />
<GameUi:UiLabel id="_labelMapName" text="地图名" size="22" bold="true" textColor="0xffffff"
x="10" bottom="12" />
<GameUi:UiLabel id="_labelChoose" text="选择" visible.up="false" size="22" bold="true"
textColor="0x00ff00" right="10" bottom="12" />
</e:Group>
</e:Skin>
</e:itemRendererSkinName>
<e:layout>
<e:TileLayout orientation="rows" requestedColumnCount="2" columnAlign="justifyUsingGap" />
</e:layout>
</e:List>
</GameUi:UiScrollList>
</e:Group>
</e:Skin>
5 changes: 2 additions & 3 deletions resource/skins/singleCustomRoom/ScrCreateSaveSlotsPanel.exml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
anchorOffsetY="0" alpha="0.8" left="0" right="0" top="0" bottom="0"
visible.up="false" />
<GameUi:UiLabel id="_labelSlotIndex" text="1" size="12" textColor="0xffffff" y="8" x="10" />
<GameUi:UiLabel id="_labelType" text="自由战斗" size="12" textColor="0xFFFFFF" y="8"
horizontalCenter="0" />
<GameUi:UiLabel id="_labelType" text="自由战斗" size="12" textColor="0xFFFFFF" y="8" x="30" />
<GameUi:UiLabel id="_labelMapName" text="地图名" size="22" bold="true" textColor="0xffffff"
x="10" bottom="12" />
<GameUi:UiLabel id="_labelChoose" text="选择" visible.up="false" size="22" bold="true"
Expand All @@ -34,7 +33,7 @@
</e:Skin>
</e:itemRendererSkinName>
<e:layout>
<e:TileLayout orientation="rows" verticalGap="10" rowAlign="justifyUsingGap" />
<e:TileLayout orientation="rows" requestedColumnCount="2" columnAlign="justifyUsingGap" />
</e:layout>
</e:List>
</GameUi:UiScrollList>
Expand Down
5 changes: 2 additions & 3 deletions src/modules/baseWar/model/BwActionPlanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ namespace TinyWars.BaseWar {
{ type: Notify.Type.BwCursorDragged, callback: this._onNotifyBwCursorDragged },
];

public async init(mapFileName: string): Promise<BwActionPlanner> {
const mapData = await WarMapModel.getExtraData(mapFileName);
this._setMapSize({ width: mapData.mapWidth, height: mapData.mapHeight });
public async init(mapSizeAndMaxPlayerIndex: Types.MapSizeAndMaxPlayerIndex): Promise<BwActionPlanner> {
this._setMapSize({ width: mapSizeAndMaxPlayerIndex.mapWidth, height: mapSizeAndMaxPlayerIndex.mapHeight });

this._view = this._view || new (this._getViewClass())();
this._view.init(this);
Expand Down
5 changes: 2 additions & 3 deletions src/modules/baseWar/model/BwCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ namespace TinyWars.BaseWar {

protected abstract _getViewClass(): new () => BwCursorView;

public async init(mapFileName: string): Promise<BwCursor> {
const mapData = await WarMapModel.getExtraData(mapFileName);
this._setMapSize({ width: mapData.mapWidth, height: mapData.mapHeight });
public async init(mapSizeAndMaxPlayerIndex: Types.MapSizeAndMaxPlayerIndex): Promise<BwCursor> {
this._setMapSize({ width: mapSizeAndMaxPlayerIndex.mapWidth, height: mapSizeAndMaxPlayerIndex.mapHeight });
this.setGridIndex({ x: 0, y: 0 });

this._view = this._view || new (this._getViewClass())();
Expand Down
63 changes: 54 additions & 9 deletions src/modules/baseWar/model/BwField.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

namespace TinyWars.BaseWar {
import Types = Utility.Types;
import SerializedBwField = Types.SerializedField;
import Types = Utility.Types;
import MapSizeAndMaxPlayerIndex = Types.MapSizeAndMaxPlayerIndex;

export abstract class BwField {
private _unitMap : BwUnitMap;
Expand All @@ -12,13 +12,18 @@ namespace TinyWars.BaseWar {
private _gridVisionEffect : BwGridVisionEffect;
private _view : BwFieldView;

public async init(data: SerializedBwField, configVersion: string, mapFileName: string): Promise<BwField> {
this._setFogMap(await (this.getFogMap() || new (this._getFogMapClass())).init(data.fogMap, mapFileName));
this._setTileMap(await (this.getTileMap() || new (this._getTileMapClass())).init(configVersion, mapFileName, data.tileMap));
this._setUnitMap(await (this.getUnitMap() || new (this._getUnitMapClass())).init(configVersion, mapFileName, data.unitMap));
this._setCursor(await (this.getCursor() || new (this._getCursorClass())).init(mapFileName));
this._setActionPlanner(await (this.getActionPlanner() || new (this._getActionPlannerClass())).init(mapFileName));
this._setGridVisionEffect(await (this.getGridVisionEffect() || new (this._getGridVisionEffectClass())).init());
public async init(
data : Types.SerializedField,
configVersion : string,
mapFileName : string | null | undefined,
mapSizeAndMaxPlayerIndex: MapSizeAndMaxPlayerIndex
): Promise<BwField> {
await this._initFogMap(data.fogMap, mapSizeAndMaxPlayerIndex);
await this._initTileMap(data.tileMap, configVersion, mapFileName, mapSizeAndMaxPlayerIndex);
await this._initUnitMap(data.unitMap, configVersion, mapFileName, mapSizeAndMaxPlayerIndex);
await this._initCursor(mapSizeAndMaxPlayerIndex);
await this._initActionPlanner(mapSizeAndMaxPlayerIndex);
await this._initGridVisionEffect();

this._view = this._view || new (this._getViewClass())();
this._view.init(this);
Expand Down Expand Up @@ -65,41 +70,81 @@ namespace TinyWars.BaseWar {
return this._view;
}

private async _initFogMap(data: Types.SerializedFogMap, mapSizeAndMaxPlayerIndex: MapSizeAndMaxPlayerIndex): Promise<void> {
const fogMap = this.getFogMap() || new (this._getFogMapClass())();
await fogMap.init(data, mapSizeAndMaxPlayerIndex);
this._setFogMap(fogMap);
}
private _setFogMap(map: BwFogMap): void {
this._fogMap = map;
}
public getFogMap(): BwFogMap {
return this._fogMap;
}

private async _initTileMap(
data : Types.SerializedTileMap | null | undefined,
configVersion : string,
mapFileName : string | null | undefined,
mapSizeAndMaxPlayerIndex: MapSizeAndMaxPlayerIndex
): Promise<void> {
const tileMap = this.getTileMap() || new (this._getTileMapClass())();
await tileMap.init(data, configVersion, mapFileName, mapSizeAndMaxPlayerIndex);
this._setTileMap(tileMap);
}
private _setTileMap(map: BwTileMap): void {
this._tileMap = map;
}
public getTileMap(): BwTileMap {
return this._tileMap;
}

private async _initUnitMap(
data : Types.SerializedUnitMap | null | undefined,
configVersion : string,
mapFileName : string | null | undefined,
mapSizeAndMaxPlayerIndex: MapSizeAndMaxPlayerIndex
): Promise<void> {
const unitMap = this.getUnitMap() || new (this._getUnitMapClass())();
await unitMap.init(data, configVersion, mapFileName, mapSizeAndMaxPlayerIndex);
this._setUnitMap(unitMap);
}
private _setUnitMap(map: BwUnitMap): void {
this._unitMap = map;
}
public getUnitMap(): BwUnitMap {
return this._unitMap;
}

private async _initCursor(mapSizeAndMaxPlayerIndex: MapSizeAndMaxPlayerIndex): Promise<void> {
const cursor = this.getCursor() || new (this._getCursorClass())();
await cursor.init(mapSizeAndMaxPlayerIndex);
this._setCursor(cursor);
}
private _setCursor(cursor: BwCursor): void {
this._cursor = cursor;
}
public getCursor(): BwCursor {
return this._cursor;
}

private async _initActionPlanner(mapSizeAndMaxPlayerIndex: MapSizeAndMaxPlayerIndex): Promise<void> {
const actionPlanner = this.getActionPlanner() || new (this._getActionPlannerClass())();
await actionPlanner.init(mapSizeAndMaxPlayerIndex);
this._setActionPlanner(actionPlanner);
}
private _setActionPlanner(actionPlanner: BwActionPlanner): void {
this._actionPlanner = actionPlanner;
}
public getActionPlanner(): BwActionPlanner {
return this._actionPlanner;
}

private async _initGridVisionEffect(): Promise<void> {
const effect = this.getGridVisionEffect() || new (this._getGridVisionEffectClass())();
await effect.init();
this._setGridVisionEffect(effect);
}
private _setGridVisionEffect(gridVisionEffect: BwGridVisionEffect): void {
this._gridVisionEffect = gridVisionEffect;
}
Expand Down
17 changes: 8 additions & 9 deletions src/modules/baseWar/model/BwFogMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ namespace TinyWars.BaseWar {
private _mapsFromPaths : Map<number, Visibility[][]>;
private _war : BwWar;

public async init(data: SerializedBwFogMap, mapFileName: string): Promise<BwFogMap> {
const mapInfo = await MapManager.getExtraData(mapFileName);
const mapSize: MapSize = { width: mapInfo.mapWidth, height: mapInfo.mapHeight };
this._mapsFromPaths = createEmptyMaps<Visibility>(mapSize, mapInfo.playersCount);
this._setMapSize(mapInfo.mapWidth, mapInfo.mapHeight);
public async init(data: SerializedBwFogMap, mapSizeAndMaxPlayerIndex: Types.MapSizeAndMaxPlayerIndex): Promise<BwFogMap> {
const mapSize : MapSize = { width: mapSizeAndMaxPlayerIndex.mapWidth, height: mapSizeAndMaxPlayerIndex.mapHeight };
this._mapsFromPaths = createEmptyMaps<Visibility>(mapSize, mapSizeAndMaxPlayerIndex.maxPlayerIndex);
this._setMapSize(mapSize);
this.setForceFogCode(data.forceFogCode || ForceFogCode.None);
this.setForceExpirePlayerIndex(data.forceExpirePlayerIndex);
this.setForceExpireTurnIndex(data.forceExpireTurnIndex);
Expand All @@ -48,8 +47,8 @@ namespace TinyWars.BaseWar {
////////////////////////////////////////////////////////////////////////////////////////////////////
// Other public functions.
////////////////////////////////////////////////////////////////////////////////////////////////////
private _setMapSize(width: number, height: number): void {
this._mapSize = { width: width, height: height };
private _setMapSize(mapSize: MapSize): void {
this._mapSize = mapSize;
}
public getMapSize(): MapSize {
return this._mapSize;
Expand Down Expand Up @@ -195,9 +194,9 @@ namespace TinyWars.BaseWar {
}
}

function createEmptyMaps<T extends (number | Visibility)>(mapSize: MapSize, playersCount: number): Map<number, T[][]> {
function createEmptyMaps<T extends (number | Visibility)>(mapSize: MapSize, maxPlayerIndex: number): Map<number, T[][]> {
const map = new Map<number, T[][]>();
for (let i = 0; i < playersCount + 1; ++i) {
for (let i = 0; i <= maxPlayerIndex; ++i) {
map.set(i, Helpers.createEmptyMap<T>(mapSize.width, mapSize.height, 0 as T));
}
return map;
Expand Down
Loading

0 comments on commit db77910

Please sign in to comment.