Peter
This commit is contained in:
Binary file not shown.
+47
-3
@@ -362,6 +362,44 @@ app.put('/games/:gameId/:userId/character', (req, res) => {
|
|||||||
stmt.finalize();
|
stmt.finalize();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Update Player Character
|
||||||
|
app.put('/games/character/:charId', async (req, res) => {
|
||||||
|
const charId = req.params.charId;
|
||||||
|
const {
|
||||||
|
charName, race, sex, age, job, description,
|
||||||
|
maxHealth, currentHealth, maxMana, currentMana,
|
||||||
|
strength, dexterity, agility, endurance,
|
||||||
|
level, gold
|
||||||
|
} = req.body;
|
||||||
|
|
||||||
|
const stmt = db.prepare(`
|
||||||
|
UPDATE PlayerCharacter
|
||||||
|
SET CharName = ?, Race = ?, Sex = ?, Age = ?, Job = ?,
|
||||||
|
Description = ?, MaxHealth = ?, CurrentHealth = ?,
|
||||||
|
MaxMana = ?, CurrentMana = ?, Strength = ?,
|
||||||
|
Dexterity = ?, Agility = ?, Endurance = ?,
|
||||||
|
Level = ?, Gold = ?
|
||||||
|
WHERE CharID = ?
|
||||||
|
`);
|
||||||
|
|
||||||
|
stmt.run([
|
||||||
|
charName, race, sex, age, job, description,
|
||||||
|
maxHealth, currentHealth, maxMana, currentMana,
|
||||||
|
strength, dexterity, agility, endurance,
|
||||||
|
level, gold, charId
|
||||||
|
], function(err) {
|
||||||
|
if (err) {
|
||||||
|
console.error('Database error:', err);
|
||||||
|
return res.status(500).json({ error: 'Internal server error' });
|
||||||
|
}
|
||||||
|
if (this.changes === 0) {
|
||||||
|
return res.status(404).json({ error: 'Character not found' });
|
||||||
|
}
|
||||||
|
res.json({ message: 'Character updated successfully!' });
|
||||||
|
});
|
||||||
|
stmt.finalize();
|
||||||
|
});
|
||||||
|
|
||||||
// Fetch Player Items
|
// Fetch Player Items
|
||||||
app.get('/games/:gameId/:charId/items', (req, res) => {
|
app.get('/games/:gameId/:charId/items', (req, res) => {
|
||||||
const gameId = req.params.gameId;
|
const gameId = req.params.gameId;
|
||||||
@@ -424,13 +462,18 @@ app.post('/games/:charId/:itemId/owner', (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Update Item details including owner
|
// Update Item details including owner
|
||||||
app.put('/games/item/:itemId', async (req, res) => {
|
app.put('/games/item/:itemId', (req, res) => {
|
||||||
const itemId = req.params.itemId;
|
const itemId = req.params.itemId;
|
||||||
const {
|
const {
|
||||||
ItemName, Type, Art, Rarity, MaxDurability, CurrentDurability,
|
ItemName, Type, Art, Rarity, MaxDurability, CurrentDurability,
|
||||||
GoldValue, Abilities, OwnerID, AP
|
GoldValue, Abilities, OwnerID, AP
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
|
// Validate required fields
|
||||||
|
if (!ItemName) {
|
||||||
|
return res.status(400).json({ error: 'Item name is required' });
|
||||||
|
}
|
||||||
|
|
||||||
const stmt = db.prepare(`
|
const stmt = db.prepare(`
|
||||||
UPDATE Item
|
UPDATE Item
|
||||||
SET ItemName = ?, Type = ?, Art = ?, Rarity = ?,
|
SET ItemName = ?, Type = ?, Art = ?, Rarity = ?,
|
||||||
@@ -440,8 +483,9 @@ app.put('/games/item/:itemId', async (req, res) => {
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
stmt.run([
|
stmt.run([
|
||||||
ItemName, Type, Art, Rarity, MaxDurability, CurrentDurability,
|
ItemName, Type, Art, Rarity,
|
||||||
GoldValue, Abilities, OwnerID, AP, itemId
|
MaxDurability, CurrentDurability, GoldValue,
|
||||||
|
Abilities, OwnerID, AP, itemId
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Database error:', err);
|
console.error('Database error:', err);
|
||||||
|
|||||||
@@ -105,37 +105,95 @@ const GameMasterPage = () => {
|
|||||||
setIsEditing(true);
|
setIsEditing(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update handleUpdate to fetch once after saving
|
// Update the handleUpdate function
|
||||||
const handleUpdate = async () => {
|
const handleUpdate = async () => {
|
||||||
try {
|
try {
|
||||||
let response;
|
let response;
|
||||||
if (editType === 'item') {
|
if (editType === 'item') {
|
||||||
response = await axios.put(`http://localhost:5000/games/item/${selectedItem.ItemID}`, formData);
|
const itemData = {
|
||||||
|
ItemName: formData.ItemName,
|
||||||
|
Type: formData.Type,
|
||||||
|
Art: formData.Art,
|
||||||
|
Rarity: formData.Rarity,
|
||||||
|
MaxDurability: formData.MaxDurability,
|
||||||
|
CurrentDurability: formData.CurrentDurability,
|
||||||
|
GoldValue: formData.GoldValue,
|
||||||
|
Abilities: formData.Abilities,
|
||||||
|
OwnerID: formData.OwnerID,
|
||||||
|
AP: formData.AP
|
||||||
|
};
|
||||||
|
response = await axios.put(`http://localhost:5000/games/item/${selectedItem.ItemID}`, itemData);
|
||||||
} else if (editType === 'npc') {
|
} else if (editType === 'npc') {
|
||||||
response = await axios.put(`http://localhost:5000/games/npc/${selectedItem.NPCID}`, formData);
|
// Update NPC data
|
||||||
|
const npcData = {
|
||||||
|
Name: formData.Name,
|
||||||
|
Race: formData.Race,
|
||||||
|
Sex: formData.Sex,
|
||||||
|
Age: formData.Age,
|
||||||
|
Job: formData.Job,
|
||||||
|
Description: formData.Description,
|
||||||
|
MaxHealth: formData.MaxHealth,
|
||||||
|
CurrentHealth: formData.CurrentHealth,
|
||||||
|
MaxMana: formData.MaxMana,
|
||||||
|
CurrentMana: formData.CurrentMana,
|
||||||
|
Strength: formData.Strength,
|
||||||
|
Dexterity: formData.Dexterity,
|
||||||
|
Agility: formData.Agility,
|
||||||
|
Endurance: formData.Endurance,
|
||||||
|
Level: formData.Level,
|
||||||
|
Allied: formData.Allied
|
||||||
|
};
|
||||||
|
response = await axios.put(`http://localhost:5000/games/npc/${selectedItem.NpcID}`, npcData);
|
||||||
} else if (editType === 'character') {
|
} else if (editType === 'character') {
|
||||||
response = await axios.put(`http://localhost:5000/games/character/${selectedItem.CharID}`, formData);
|
// Update Player Character data
|
||||||
|
const charData = {
|
||||||
|
charName: formData.CharName,
|
||||||
|
race: formData.Race,
|
||||||
|
sex: formData.Sex,
|
||||||
|
age: formData.Age,
|
||||||
|
job: formData.Job,
|
||||||
|
description: formData.Description,
|
||||||
|
maxHealth: formData.MaxHealth,
|
||||||
|
currentHealth: formData.CurrentHealth,
|
||||||
|
maxMana: formData.MaxMana,
|
||||||
|
currentMana: formData.CurrentMana,
|
||||||
|
strength: formData.Strength,
|
||||||
|
dexterity: formData.Dexterity,
|
||||||
|
agility: formData.Agility,
|
||||||
|
endurance: formData.Endurance,
|
||||||
|
level: formData.Level,
|
||||||
|
gold: formData.Gold
|
||||||
|
};
|
||||||
|
response = await axios.put(`http://localhost:5000/games/character/${selectedItem.CharID}`, charData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
|
// Fetch updated data after successful update
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
|
// Fetch player characters
|
||||||
const pcsResponse = await axios.get(`http://localhost:5000/games/${gameId}/playerchars`);
|
const pcsResponse = await axios.get(`http://localhost:5000/games/${gameId}/playerchars`);
|
||||||
const processedPCs = Array.isArray(pcsResponse.data) ? pcsResponse.data : [pcsResponse.data];
|
setPlayerCharacters(
|
||||||
setPlayerCharacters(processedPCs.filter(pc => pc !== null));
|
Array.isArray(pcsResponse.data) ? pcsResponse.data : [pcsResponse.data]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Fetch NPCs
|
||||||
const npcsResponse = await axios.get(`http://localhost:5000/games/${gameId}/npcs`);
|
const npcsResponse = await axios.get(`http://localhost:5000/games/${gameId}/npcs`);
|
||||||
const processedNPCs = Array.isArray(npcsResponse.data) ? npcsResponse.data : [npcsResponse.data];
|
setNpcs(
|
||||||
setNpcs(processedNPCs.filter(npc => npc !== null));
|
Array.isArray(npcsResponse.data) ? npcsResponse.data : [npcsResponse.data]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Fetch items
|
||||||
const itemsResponse = await axios.get(`http://localhost:5000/games/${gameId}/items`);
|
const itemsResponse = await axios.get(`http://localhost:5000/games/${gameId}/items`);
|
||||||
const processedItems = Array.isArray(itemsResponse.data) ? itemsResponse.data : [itemsResponse.data];
|
setItems(
|
||||||
setItems(processedItems.filter(item => item !== null));
|
Array.isArray(itemsResponse.data) ? itemsResponse.data : [itemsResponse.data]
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching data:', error);
|
console.error('Error fetching updated data:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await fetchData(); // Fetch once after successful update
|
|
||||||
|
await fetchData();
|
||||||
setEditModalOpen(false);
|
setEditModalOpen(false);
|
||||||
setFormData(null);
|
setFormData(null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user