refactor: enhance action handling and introduce ActionResourceButton component
This commit is contained in:
@@ -4,11 +4,31 @@ export function isGatheringAction(action: PetGatherAction): boolean {
|
||||
return action.startsWith('GATHERING_');
|
||||
}
|
||||
|
||||
export function getResourceFromAction(action: PetGatherAction): string | null {
|
||||
if (!isGatheringAction(action)) return null;
|
||||
return action.replace('GATHERING_', '').toLowerCase();
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
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] || '');
|
||||
}
|
||||
Reference in New Issue
Block a user