parte do cliente completa, falta so a parte do obs e do mestre.
This commit is contained in:
Binary file not shown.
@@ -102,6 +102,9 @@ func main() {
|
||||
e.POST("player/inv", inv_add)
|
||||
e.GET("player/inv/del/:id", inv_del)
|
||||
e.GET("player/inv/use/:id", inv_use)
|
||||
e.GET("player/inv/ph", inv_ph)
|
||||
e.GET("player/inv/ph/del/:id", inv_phDel)
|
||||
e.POST("player/inv/ph", inv_phAdd)
|
||||
e.POST("player/update", player_updateInputs)
|
||||
e.PATCH("player/:atb/:updown", player_update)
|
||||
|
||||
|
||||
@@ -417,7 +417,7 @@ func inv_del(c echo.Context) error {
|
||||
return jsonError(c, http.StatusInternalServerError, "erro ao deletar item.")
|
||||
}
|
||||
|
||||
return jsonSuccess(c, "você item deletado")
|
||||
return jsonSuccess(c, "você deletou um item")
|
||||
}
|
||||
|
||||
func inv_use(c echo.Context) error {
|
||||
@@ -512,3 +512,82 @@ func inv_add(c echo.Context) error {
|
||||
|
||||
return jsonSuccess(c, fmt.Sprintf("%s %ss foram colocados no seu inventário.", quantidade, nome))
|
||||
}
|
||||
func inv_ph(c echo.Context) error {
|
||||
session, err := requireSession(c)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if session["playerName"] == "" {
|
||||
return jsonError(c, http.StatusUnauthorized, "Você precisa estar logado para adicionar itens ao inventário.")
|
||||
}
|
||||
|
||||
row, err := db.Query(fmt.Sprintf("SELECT * FROM invPower_%s ORDER BY id DESC;", session["playerName"]))
|
||||
if err != nil {
|
||||
log.Println("Erro ao consultar sua lista de habilidade.")
|
||||
return jsonError(c, http.StatusInternalServerError, "Erro ao consultar sua lista de habilidade.")
|
||||
}
|
||||
defer row.Close()
|
||||
|
||||
var lista []plyPwr
|
||||
for row.Next() {
|
||||
var id int
|
||||
var nome, desc string
|
||||
if err := row.Scan(&id, &nome, &desc); err != nil {
|
||||
return jsonError(c, http.StatusInternalServerError, "algo deu errado ao montar lista de rolagem")
|
||||
}
|
||||
lista = append(lista, plyPwr{ID: id, Name: nome, Desc: desc})
|
||||
}
|
||||
|
||||
sort.Slice(lista, func(i, j int) bool {
|
||||
return lista[i].ID < lista[j].ID
|
||||
})
|
||||
|
||||
if len(lista) == 0 {
|
||||
return jsonError(c, http.StatusNotFound, "você ainda não tem habilidades")
|
||||
}
|
||||
return c.JSON(http.StatusOK, resp_json{
|
||||
Status: "Success",
|
||||
InvPws: lista,
|
||||
})
|
||||
}
|
||||
|
||||
func inv_phAdd(c echo.Context) error {
|
||||
session, err := requireSession(c)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if session["playerName"] == "" {
|
||||
return jsonError(c, http.StatusUnauthorized, "Você precisa estar logado para adicionar itens ao inventário.")
|
||||
}
|
||||
|
||||
nome := c.FormValue("nameph")
|
||||
desc := c.FormValue("descph")
|
||||
|
||||
if anyEmpty(nome, desc) {
|
||||
return jsonError(c, http.StatusBadRequest, "Algum parâmetro está faltando ou está vazio. Tente novamente.")
|
||||
}
|
||||
|
||||
_, err = db.Exec(fmt.Sprintf("INSERT INTO invPower_%s (name_power, desc_power) VALUES (?, ?)", session["playerName"]), nome, desc)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return jsonError(c, http.StatusInternalServerError, fmt.Sprintf("erro ao adicionar %s a sua lista", nome))
|
||||
}
|
||||
return jsonSuccess(c, fmt.Sprintf("%s foi adicionado a sua lista", nome))
|
||||
}
|
||||
|
||||
func inv_phDel(c echo.Context) error {
|
||||
session, err := requireSession(c)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if session["playerName"] == "" {
|
||||
return jsonError(c, http.StatusUnauthorized, "você precisa estar logado para apagar uma habilidade")
|
||||
}
|
||||
itemID := c.Param("id")
|
||||
err = updateField(fmt.Sprintf("DELETE FROM invPower_%s WHERE id=?;", session["playerName"]), itemID)
|
||||
if err != nil {
|
||||
return jsonError(c, http.StatusInternalServerError, "erro ao deletar habilidade.")
|
||||
}
|
||||
|
||||
return jsonSuccess(c, "você deletou uma habilidade")
|
||||
}
|
||||
|
||||
@@ -78,6 +78,29 @@
|
||||
background-color: var(--subbgcolor);
|
||||
}
|
||||
|
||||
#powers {
|
||||
ul {
|
||||
li {
|
||||
position: relative;
|
||||
#DelBTN {
|
||||
top: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: red;
|
||||
position: absolute;
|
||||
width: 4dvh;
|
||||
height: 100%;
|
||||
transition: 0.3s;
|
||||
&:hover {
|
||||
background-color: darkred;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#status {
|
||||
width: 25%;
|
||||
border-right: solid 1px var(--lines);
|
||||
@@ -352,7 +375,7 @@
|
||||
font-size: 1.2em;
|
||||
margin-top: 0.5dvh;
|
||||
}
|
||||
a {
|
||||
input[type="submit"] {
|
||||
margin-top: 0.5dvh;
|
||||
background-color: var(--btncolor);
|
||||
width: 90%;
|
||||
|
||||
@@ -50,6 +50,9 @@
|
||||
<a id="btn" class="share">
|
||||
<span class="material-symbols-outlined">share</span>
|
||||
</a>
|
||||
<a id="btn" class="obs">
|
||||
<span class="material-symbols-outlined">duo</span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<label>level:</label>
|
||||
@@ -378,9 +381,7 @@
|
||||
</div>
|
||||
<div id="powers">
|
||||
<h1>Habilidades</h1>
|
||||
<ul>
|
||||
<li><a>bla bla bla bla</a></li>
|
||||
</ul>
|
||||
<ul></ul>
|
||||
<hgroup>
|
||||
<input
|
||||
type="text"
|
||||
@@ -390,9 +391,15 @@
|
||||
/>
|
||||
<textarea
|
||||
id="desc"
|
||||
name="desc"
|
||||
placeholder="escrava como sua habilidade ou poder funciona"
|
||||
></textarea>
|
||||
<a id="btn">add</a>
|
||||
<input
|
||||
type="submit"
|
||||
id="btn"
|
||||
class="powerAdd"
|
||||
value="add"
|
||||
/>
|
||||
</hgroup>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
let img;
|
||||
let update;
|
||||
let playerID;
|
||||
let lastPowerID = 0;
|
||||
|
||||
async function useInv(id, type) {
|
||||
try {
|
||||
@@ -18,6 +19,46 @@ async function useInv(id, type) {
|
||||
}
|
||||
}
|
||||
|
||||
function invpower() {
|
||||
$.ajax({
|
||||
url: `${window.api}player/inv/ph`,
|
||||
type: "GET",
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
const $invpower = $("#powers ul");
|
||||
|
||||
let latestId = lastPowerID;
|
||||
|
||||
resp.InvPws.forEach((item) => {
|
||||
if (item.id > lastPowerID) {
|
||||
const $li = $("<li>");
|
||||
$li.append($("<a>").text(item.name));
|
||||
|
||||
const $del = $("<a>")
|
||||
.attr("id", "DelBTN")
|
||||
.append(
|
||||
$("<span>").addClass("material-symbols-outlined").text("close"),
|
||||
);
|
||||
|
||||
$li.on("click", () => alert(item.desc));
|
||||
$del.on("click", (e) => {
|
||||
e.stopPropagation();
|
||||
useInv(item.id, "ph/del");
|
||||
$del.closest("li").remove();
|
||||
});
|
||||
|
||||
$li.append($del);
|
||||
$invpower.append($li);
|
||||
|
||||
if (item.id > latestId) latestId = item.id;
|
||||
}
|
||||
});
|
||||
|
||||
lastPowerID = latestId;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function invPlayer() {
|
||||
$.ajax({
|
||||
url: `${window.api}player/inv`,
|
||||
@@ -57,6 +98,28 @@ function invPlayer() {
|
||||
});
|
||||
}
|
||||
|
||||
function invPowerAdd() {
|
||||
const habilidade = $("input[name='habilidade']").val();
|
||||
const desc = $("textarea[name='desc']").val();
|
||||
|
||||
$.ajax({
|
||||
url: `${window.api}player/inv/ph`,
|
||||
type: "POST",
|
||||
data: { nameph: habilidade, descph: desc },
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
msg(resp.Status, resp.Message);
|
||||
$("input[name='habilidade'], textarea[name='desc']").val("");
|
||||
},
|
||||
error(resp) {
|
||||
msg(
|
||||
resp.responseJSON?.Status || "Erro",
|
||||
resp.responseJSON?.Message || "Algo deu errado.",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function invAdd() {
|
||||
const nome = $("input[name='item_name']").val();
|
||||
const durabilidade = $("select[name='durabilite']").val();
|
||||
@@ -196,10 +259,15 @@ $(document).ready(function () {
|
||||
invAdd();
|
||||
});
|
||||
|
||||
$(".powerAdd").on("click", function () {
|
||||
invPowerAdd();
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
loadFicha();
|
||||
rollLoad();
|
||||
invPlayer();
|
||||
invpower();
|
||||
}, 1000);
|
||||
|
||||
loadFicha();
|
||||
|
||||
Reference in New Issue
Block a user