新增mvvm示例
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -22,3 +22,6 @@
|
||||
[submodule "thirdparty/mvvm-ui-framework"]
|
||||
path = thirdparty/mvvm-ui-framework
|
||||
url = https://github.com/esengine/mvvm-ui-framework.git
|
||||
[submodule "thirdparty/cocos-nexus"]
|
||||
path = thirdparty/cocos-nexus
|
||||
url = https://github.com/esengine/cocos-nexus.git
|
||||
|
||||
9
extensions/cocos/cocos-ecs/assets/resources/prefabs.meta
Normal file
9
extensions/cocos/cocos-ecs/assets/resources/prefabs.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "2bf3ded8-4054-4d8f-a367-c76b21eaf538",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.50",
|
||||
"importer": "prefab",
|
||||
"imported": true,
|
||||
"uuid": "51a6e245-2983-4258-be9f-9e21378f7f9f",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"syncNodeName": "Panel_Node"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
9
extensions/cocos/cocos-ecs/assets/scripts/mvvm/game.meta
Normal file
9
extensions/cocos/cocos-ecs/assets/scripts/mvvm/game.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "21b8d75a-82be-4b5a-8ecf-765558907857",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { ViewModel, observable, computed, command } from '@esengine/mvvm-ui-framework';
|
||||
|
||||
/**
|
||||
* 游戏状态视图模型
|
||||
*/
|
||||
export class GameStateViewModel extends ViewModel {
|
||||
|
||||
public get name(): string {
|
||||
return 'GameStateViewModel';
|
||||
}
|
||||
|
||||
@observable
|
||||
currentLevel: number = 1;
|
||||
|
||||
@observable
|
||||
health: number = 100;
|
||||
|
||||
@observable
|
||||
mana: number = 50;
|
||||
|
||||
@observable
|
||||
experience: number = 0;
|
||||
|
||||
@computed(['health'])
|
||||
get healthPercent(): number {
|
||||
return (this.health / 100) * 100;
|
||||
}
|
||||
|
||||
@computed(['experience', 'currentLevel'])
|
||||
get experienceToNextLevel(): number {
|
||||
return (this.currentLevel * 100) - this.experience;
|
||||
}
|
||||
|
||||
@command()
|
||||
public levelUp(): void {
|
||||
this.currentLevel += 1;
|
||||
this.health = 100;
|
||||
this.mana += 10;
|
||||
}
|
||||
|
||||
@command()
|
||||
public takeDamage(damage: number): void {
|
||||
this.health = Math.max(0, this.health - damage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8fa14e6f-46cd-4cb4-9ac1-0a1919e260a5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
extensions/cocos/cocos-ecs/assets/scripts/mvvm/shop.meta
Normal file
9
extensions/cocos/cocos-ecs/assets/scripts/mvvm/shop.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "2c09b280-bf73-4d95-9b1f-d4d915442980",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { ViewModel, observable, computed, command } from '@esengine/mvvm-ui-framework';
|
||||
|
||||
/**
|
||||
* 商店视图模型
|
||||
*/
|
||||
export class ShopViewModel extends ViewModel {
|
||||
|
||||
public get name(): string {
|
||||
return 'ShopViewModel';
|
||||
}
|
||||
|
||||
@observable
|
||||
selectedCategory: string = 'weapons';
|
||||
|
||||
@observable
|
||||
playerGold: number = 1000;
|
||||
|
||||
@observable
|
||||
cartItems: any[] = [];
|
||||
|
||||
@computed(['cartItems'])
|
||||
get totalPrice(): number {
|
||||
return this.cartItems.reduce((total, item) => total + item.price, 0);
|
||||
}
|
||||
|
||||
@computed(['playerGold', 'totalPrice'])
|
||||
get canPurchase(): boolean {
|
||||
return this.playerGold >= this.totalPrice;
|
||||
}
|
||||
|
||||
@command()
|
||||
public addToCart(item: any): void {
|
||||
this.cartItems.push(item);
|
||||
}
|
||||
|
||||
@command('canPurchase')
|
||||
public purchase(): void {
|
||||
this.playerGold -= this.totalPrice;
|
||||
this.cartItems = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "148fe394-03cd-45a1-9bc0-5cb24440d8db",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
extensions/cocos/cocos-ecs/assets/scripts/mvvm/user.meta
Normal file
9
extensions/cocos/cocos-ecs/assets/scripts/mvvm/user.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "62abfd02-b9f5-41d2-9822-2c777af21e27",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { ViewModel, observable, computed, command } from '@esengine/mvvm-ui-framework';
|
||||
|
||||
/**
|
||||
* 用户配置文件视图模型
|
||||
*/
|
||||
export class UserProfileViewModel extends ViewModel {
|
||||
|
||||
public get name(): string {
|
||||
return 'UserProfileViewModel';
|
||||
}
|
||||
|
||||
@observable
|
||||
avatar: string = '';
|
||||
|
||||
@observable
|
||||
nickname: string = '';
|
||||
|
||||
@observable
|
||||
email: string = '';
|
||||
|
||||
@observable
|
||||
phone: string = '';
|
||||
|
||||
@computed(['nickname', 'email'])
|
||||
get displayInfo(): string {
|
||||
return `${this.nickname} (${this.email})`;
|
||||
}
|
||||
|
||||
@command()
|
||||
public updateProfile(): void {
|
||||
console.log('更新用户配置文件');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "05648650-5963-4847-8789-7bdc6ea7f43c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Submodule extensions/cocos/cocos-ecs/extensions/behaviour-tree updated: 06eb76889b...141a36f92d
Submodule extensions/cocos/cocos-ecs/extensions/mvvm-designer updated: f030e47991...3a63efa72c
8
extensions/cocos/cocos-ecs/package-lock.json
generated
8
extensions/cocos/cocos-ecs/package-lock.json
generated
@@ -6,7 +6,7 @@
|
||||
"": {
|
||||
"name": "cocos-ecs",
|
||||
"dependencies": {
|
||||
"@esengine/ai": "^2.0.17",
|
||||
"@esengine/ai": "^2.0.19",
|
||||
"@esengine/cocos-nexus": "^1.0.1",
|
||||
"@esengine/ecs-framework": "^2.1.23",
|
||||
"@esengine/mvvm-ui-framework": "^1.0.3"
|
||||
@@ -38,9 +38,9 @@
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/@esengine/ai": {
|
||||
"version": "2.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@esengine/ai/-/ai-2.0.17.tgz",
|
||||
"integrity": "sha512-ek19BGzW4VmkZsCr6N0SDJthzU6q+FTjb5wMwc3dEU1PdDRxPeSaD5wwhPfnTkgMXuGkncnM3NGuboz915LWyg==",
|
||||
"version": "2.0.19",
|
||||
"resolved": "https://registry.npmjs.org/@esengine/ai/-/ai-2.0.19.tgz",
|
||||
"integrity": "sha512-vK+5jtOYv4LeLX9IbhfC04qzaXfZOYdGyXsZ52Bxiv3KCgzMnP2cKQfMXLvkhgkMKQ8m16PaiHyaDFoo8BKk4w==",
|
||||
"dependencies": {
|
||||
"@esengine/ecs-framework": "^2.1.20"
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"version": "3.8.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@esengine/ai": "^2.0.17",
|
||||
"@esengine/ai": "^2.0.19",
|
||||
"@esengine/cocos-nexus": "^1.0.1",
|
||||
"@esengine/ecs-framework": "^2.1.23",
|
||||
"@esengine/mvvm-ui-framework": "^1.0.3"
|
||||
|
||||
1
thirdparty/cocos-nexus
vendored
Submodule
1
thirdparty/cocos-nexus
vendored
Submodule
Submodule thirdparty/cocos-nexus added at d361885133
Reference in New Issue
Block a user