-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
208 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/app/components/bag-item-view/bag-item-view.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<nz-card class="h-full overflow-auto" [nzBodyStyle]="{ height: '100%', padding: '1rem', overflow: 'auto' }"> | ||
@for (bagItem of bagItems; track bagItem.id) { | ||
<div | ||
nz-card-grid | ||
nz-popover | ||
[nzPopoverContent]="contentTemplate" | ||
class="flex flex-col justify-center items-center w-1/4 lg:w-1/6 2xl:w-1/12 h-16 p-2 relative" | ||
> | ||
{{ bagItem.item.name }} | ||
<div class="absolute bottom-1 right-1 text-xs text-gray-500"> | ||
{{ bagItem.count }} | ||
</div> | ||
</div> | ||
<ng-template #contentTemplate> | ||
<div class="flex flex-col gap-2 justify-center items-center"> | ||
<span class="text-md font-bold">{{ bagItem.item.name }}</span> | ||
<p class="text-gray-500">{{ bagItem.item.description }}</p> | ||
<div class="flex gap-2"> | ||
@if (bagType === 'character') { | ||
@if (bagItem.item.uesable) { | ||
<button nz-button nzType="primary" nzSize="small" (click)="onItemUseClick(bagItem)">使用</button> | ||
} | ||
<button nz-button nzSize="small" (click)="onItemDropClick(bagItem, 1)">丢弃</button> | ||
<button nz-button nzSize="small" (click)="onItemDropClick(bagItem, bagItem.count)">丢弃全部</button> | ||
} @else if (bagType === 'shop') { | ||
<button nz-button nzType="primary" nzSize="small" (click)="onItemBuyClick(bagItem, 1)">购买</button> | ||
<button nz-button nzType="primary" nzSize="small" (click)="onItemBuyClick(bagItem, bagItem.count)">购买全部</button> | ||
} | ||
</div> | ||
</div> | ||
</ng-template> | ||
} | ||
</nz-card> |
4 changes: 4 additions & 0 deletions
4
src/app/components/bag-item-view/bag-item-view.component.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
:host{ | ||
flex: 1; | ||
height: 0; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/app/components/bag-item-view/bag-item-view.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { BagItemViewComponent } from './bag-item-view.component'; | ||
|
||
describe('ItemViewComponent', () => { | ||
let component: BagItemViewComponent; | ||
let fixture: ComponentFixture<BagItemViewComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [BagItemViewComponent] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(BagItemViewComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
src/app/components/bag-item-view/bag-item-view.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Component, inject, Input } from '@angular/core'; | ||
import { NzCardModule } from 'ng-zorro-antd/card'; | ||
import { BagItem, ItemMap } from '../../models/item.model'; | ||
import { NzPopoverModule } from 'ng-zorro-antd/popover'; | ||
import { LogType, LogLevel } from '../../models'; | ||
import { BackpackService } from '../../services/backpack.service'; | ||
import { LogService } from '../../services/log.service'; | ||
import { NzButtonModule } from 'ng-zorro-antd/button'; | ||
import { NzMessageModule, NzMessageService } from 'ng-zorro-antd/message'; | ||
|
||
@Component({ | ||
selector: 'app-item-view', | ||
standalone: true, | ||
imports: [NzCardModule, NzPopoverModule, NzButtonModule, NzMessageModule], | ||
templateUrl: './bag-item-view.component.html', | ||
styleUrl: './bag-item-view.component.less' | ||
}) | ||
export class BagItemViewComponent { | ||
private backpackSrv = inject(BackpackService); | ||
private logSrv = inject(LogService); | ||
private msg = inject(NzMessageService); | ||
|
||
@Input() bagItems: BagItem[] = []; | ||
@Input() bagType: 'character' | 'shop' = 'character'; | ||
|
||
onItemUseClick(bagItem: BagItem) { | ||
this.backpackSrv.useItem(bagItem.item).then(res => { | ||
if (!res) { | ||
this.backpackSrv.removeItem(bagItem.item, 1); | ||
} else { | ||
console.log(res); | ||
} | ||
}); | ||
} | ||
|
||
onItemDropClick(bagItem: BagItem, count: number) { | ||
this.backpackSrv.removeItem(bagItem.item, count); | ||
this.logSrv.log({ | ||
msg: `丢弃${count}个${bagItem.item.name}`, | ||
type: LogType.Item, | ||
level: LogLevel.Info | ||
}); | ||
} | ||
|
||
onItemBuyClick(bagItem: BagItem, count: number) { | ||
const cost = bagItem.item.price * count; | ||
const money = this.backpackSrv.getItemCountById('1'); | ||
if (money > cost) { | ||
this.backpackSrv.addItem(bagItem.item, count); | ||
this.backpackSrv.removeItem(ItemMap['1'], cost); | ||
bagItem.count -= count; | ||
this.logSrv.log({ | ||
msg: `花费${cost}个灵石,购买了${count}个${bagItem.item.name}`, | ||
type: LogType.Item, | ||
level: LogLevel.Info | ||
}); | ||
} else { | ||
this.msg.warning('你买不起!'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 2 additions & 26 deletions
28
src/app/pages/home/components/backpack/backpack.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,24 @@ | ||
import { Component, inject } from '@angular/core'; | ||
import { NzCardModule } from 'ng-zorro-antd/card'; | ||
import { NzPopoverModule } from 'ng-zorro-antd/popover'; | ||
import { NzTabsModule } from 'ng-zorro-antd/tabs'; | ||
import { NzTypographyModule } from 'ng-zorro-antd/typography'; | ||
|
||
import { BagItem, ItemTypeMap, ItemTypeValueMap } from '../../../../models/item.model'; | ||
import { BackpackService } from '../../../../services/backpack.service'; | ||
import { NzButtonModule } from 'ng-zorro-antd/button'; | ||
import { LogService } from '../../../../services/log.service'; | ||
import { LogLevel, LogType } from '../../../../models'; | ||
import { BagItemViewComponent } from '../../../../components/bag-item-view/bag-item-view.component'; | ||
|
||
@Component({ | ||
selector: 'app-backpack', | ||
standalone: true, | ||
imports: [NzTabsModule, NzCardModule, NzTypographyModule, NzPopoverModule, NzButtonModule], | ||
imports: [NzTabsModule, NzTypographyModule, BagItemViewComponent], | ||
templateUrl: './backpack.component.html', | ||
styleUrl: './backpack.component.less' | ||
}) | ||
export class BackpackComponent { | ||
private backpackSrv = inject(BackpackService); | ||
private logSrv = inject(LogService); | ||
bagTabs: string[] = ['全部', ...Object.values(ItemTypeMap)]; | ||
tabIdx = 0; | ||
|
||
get bagItems(): BagItem[] { | ||
return this.backpackSrv.getItems(this.tabIdx ? ItemTypeValueMap[this.tabIdx] : undefined); | ||
} | ||
|
||
onItemUseClick(bagItem: BagItem) { | ||
this.backpackSrv.useItem(bagItem.item).then(res => { | ||
if (!res) { | ||
this.backpackSrv.removeItem(bagItem.item, 1); | ||
} else { | ||
console.log(res); | ||
} | ||
}); | ||
} | ||
|
||
onItemDropClick(bagItem: BagItem, count: number) { | ||
this.backpackSrv.removeItem(bagItem.item, count); | ||
this.logSrv.log({ | ||
msg: `丢弃${count}个${bagItem.item.name}`, | ||
type: LogType.Item, | ||
level: LogLevel.Info | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@if (isShopShow) { | ||
<h5 nz-typography class="underline decoration-sky-500">商城</h5> | ||
<app-item-view [bagItems]="bagItems" bagType="shop" /> | ||
} @else { | ||
<nz-empty class="h-full flex flex-col justify-center items-center" nzNotFoundContent="行商已经离开,将在每年1月准时回来"></nz-empty> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
:host{ | ||
flex: 1; | ||
height: 0; | ||
display: flex; | ||
flex-direction: column; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ShopComponent } from './shop.component'; | ||
|
||
describe('ShopComponent', () => { | ||
let component: ShopComponent; | ||
let fixture: ComponentFixture<ShopComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ShopComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ShopComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Component, inject } from '@angular/core'; | ||
import { RuntimeService } from '../../services/runtime.service'; | ||
import { NzTypographyModule } from 'ng-zorro-antd/typography'; | ||
import { NzEmptyModule } from 'ng-zorro-antd/empty'; | ||
import { BagItemViewComponent } from '../../components/bag-item-view/bag-item-view.component'; | ||
import { BagItem, ItemMap } from '../../models/item.model'; | ||
|
||
@Component({ | ||
selector: 'app-shop', | ||
standalone: true, | ||
imports: [NzTypographyModule, NzEmptyModule, BagItemViewComponent], | ||
templateUrl: './shop.component.html', | ||
styleUrl: './shop.component.less' | ||
}) | ||
export class ShopComponent { | ||
private rtSrv = inject(RuntimeService); | ||
|
||
bagItems: BagItem[] = []; | ||
|
||
get isShopShow() { | ||
return this.rtSrv.timeTick.value % 36 < 3; | ||
} | ||
|
||
ngOnInit() { | ||
this.bagItems = [ | ||
{ | ||
id: '40000', | ||
item: ItemMap['40000'], | ||
count: 100 | ||
} | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9c3245a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
wanjie – ./
wanjie.vercel.app
wanjie-git-main-encaiks-projects.vercel.app
wanjie-encaiks-projects.vercel.app