refactor: reorganize pet action types and update related components for improved resource management
This commit is contained in:
@@ -1,34 +1,29 @@
|
||||
import { PetGatherAction } from '../types/PetUpdateActionRequest';
|
||||
import { PetGatherAction } from '../types/PetAction';
|
||||
|
||||
export function isGatheringAction(action: PetGatherAction): boolean {
|
||||
return action.startsWith('GATHERING_');
|
||||
}
|
||||
|
||||
export function getResourceFromAction(action: string): string | null {
|
||||
if (!action) return null;
|
||||
|
||||
const patterns = ['GATHERING_', 'EXPLORING_', 'BATTLE_'];
|
||||
for (const pattern of patterns) {
|
||||
if (action.startsWith(pattern)) {
|
||||
return action.replace(pattern, '').toLowerCase();
|
||||
}
|
||||
export function isActionActive(currentAction: PetGatherAction, actionType: 'gather' | 'explore' | 'battle'): boolean {
|
||||
if (actionType === 'gather') {
|
||||
return currentAction.startsWith('GATHERING_');
|
||||
}
|
||||
if (actionType === 'explore') {
|
||||
return currentAction === 'EXPLORE';
|
||||
}
|
||||
if (actionType === 'battle') {
|
||||
return currentAction === 'BATTLE';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getResourceFromAction(action: PetGatherAction): string | null {
|
||||
if (action.startsWith('GATHERING_')) {
|
||||
return action.replace('GATHERING_', '').toLowerCase();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function formatResourceName(resource: string): string {
|
||||
return resource.charAt(0).toUpperCase() + resource.slice(1);
|
||||
}
|
||||
|
||||
export function isActionActive(action: string, actionType: string): boolean {
|
||||
if (!action) return false;
|
||||
|
||||
const actionMap = {
|
||||
'gather': 'GATHERING_',
|
||||
'explore': 'EXPLORING_',
|
||||
'battle': 'BATTLE_'
|
||||
};
|
||||
|
||||
return action.startsWith(actionMap[actionType] || '');
|
||||
return resource.charAt(0).toUpperCase() + resource.slice(1).toLowerCase();
|
||||
}
|
||||
Reference in New Issue
Block a user