Skip to content

Commit

Permalink
添加法术名
Browse files Browse the repository at this point in the history
  • Loading branch information
EternalRider committed Mar 2, 2024
1 parent 459b2d7 commit 5eb6c4b
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 27 deletions.
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "spellbook",
"title": "法术书",
"description": "提供一个独立于系统的法术书界面。",
"version": "1.1.0",
"version": "1.2.0",
"author": "EternalRider",
"dependencies": [
{
Expand All @@ -21,6 +21,6 @@
"url": "https://github.com/EternalRider/spellbook",
"minimumCoreVersion": "11",
"compatibleCoreVersion": "11",
"manifest": "https://github.com/EternalRider/spellbook/releases/download/1.1.0/module.json",
"download": "https://github.com/EternalRider/spellbook/releases/download/1.1.0/spellbook.zip"
"manifest": "https://github.com/EternalRider/spellbook/releases/download/1.2.0/module.json",
"download": "https://github.com/EternalRider/spellbook/releases/download/1.2.0/spellbook.zip"
}
47 changes: 35 additions & 12 deletions scripts/function/prepar-slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class PreparSlot extends Application {
}

mapSlots(k) {
// const slotName = game.settings.get(MODULE_ID, 'showSpellName') ? "prepar-slot-name" : "";
return Object.entries(this.config.SLOTS[k]).map(([key, slots]) => {
const slotData = [];
for (let i = 0; i < slots.length; i++) {
Expand Down Expand Up @@ -109,12 +110,13 @@ export class PreparSlot extends Application {
y: y,
empty: item ? "" : "prepar-slot-empty",
slotLocked: (slotLocked && this.limit.type == "施展锁定") ? "prepar-slot-locked" : "",
slotUseNum: slotUseNum,
slotUseMax: slotUseMax,
slotUseCur: slotUseCur,
slotMark: slotMark,
showUsed: (this.limit.type == "可用次数" || this.limit.type == "总点数池") ? "true" : "",
showPool: this.limit.type == "总点数池" ? "true" : "",
slotUseNum,
slotUseMax,
slotUseCur,
slotMark,
// slotName,
// showUsed: (this.limit.type == "可用次数" || this.limit.type == "总点数池") ? "true" : "",
// showPool: this.limit.type == "总点数池" ? "true" : "",
});
}
return slotData;
Expand Down Expand Up @@ -149,6 +151,9 @@ export class PreparSlot extends Application {
limitLock: this.limit.type === "施展锁定" ? "true" : "",
limitCount: this.limit.type === "可用次数" ? "true" : "",
limitPool: this.limit.type === "总点数池" ? "true" : "",
showName: game.settings.get(MODULE_ID, 'showSpellName'),
showUsed: this.limit.type == "可用次数" || this.limit.type == "总点数池",
// showPool: this.limit.type == "总点数池",
pool: { value: this.limit.poolValue, max: this.limit.poolMax }
};
Utilities.debug("getData", data);
Expand Down Expand Up @@ -484,11 +489,29 @@ export class PreparSlot extends Application {
const fromPanel = data.fromPanel;
const fromItemUuid = data.fromUuid;
const panelType = data.panelType;
const item = await fromUuid(data.uuid);
let item = await fromUuid(data.uuid);

// if (item.type != "power") {
// return;
// }
Utilities.debug("_onDrop", event, data, item, this.actor, item.type, (item.type != "power" && item.type != "spell" && item.type != game.settings.get(MODULE_ID, 'spellItemType')));
if (item.type != "power" && item.type != "spell" && item.type != game.settings.get(MODULE_ID, 'spellItemType')) {
return;
}

Utilities.debug("_onDrop", (game.settings.get(MODULE_ID, 'autoAddSpell') && item.parent != this.actor), item.clone);
if (game.settings.get(MODULE_ID, 'autoAddSpell') && item.parent != this.actor) {
if (game.settings.get(MODULE_ID, 'detectSameName')) {
let sameName = this.actor.items.find((i) => i.name === item.name);
if (sameName) {
item = sameName;
} else {
item = await this.actor.createEmbeddedDocuments("Item", [item.toObject()]);
item = item[0];
}
} else {
item = await this.actor.createEmbeddedDocuments("Item", [item.toObject()]);
item = item[0];
}
}
Utilities.debug("_onDrop", item, item.type, item.parent, this.actor);

const swapItems = draggedId !== undefined && draggedIndex !== undefined;
const currentFlag = this.getSlots();
Expand Down Expand Up @@ -559,7 +582,7 @@ export class PreparSlot extends Application {

_getHeaderButtons() {
let buttons = super._getHeaderButtons();
if (game.user.isGM || game.settings.get(MODULE_ID, 'allowPlayerConfig')) {
if (game.user.isGM || game.settings.get(MODULE_ID, 'allowUserConfig')) {
buttons.unshift({
class: "prepar-slot-actor-config",
icon: "fas fa-cog",
Expand Down Expand Up @@ -604,7 +627,7 @@ export class PreparSlot extends Application {

async configure() {
//如果非GM且不允许非GM用户配置,则返回
if (!game.user.isGM && !game.settings.get(MODULE_ID, 'allowPlayerConfig')) return;
if (!game.user.isGM && !game.settings.get(MODULE_ID, 'allowUserConfig')) return;

//配置准备槽位的环数和每个环的槽位数量
//配置背景图像和槽位图标
Expand Down
3 changes: 3 additions & 0 deletions scripts/function/spell-book.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class SpellBook extends Application {
}

mapSlots(k) {
// const slotName = game.settings.get(MODULE_ID, 'showSpellName') ? "spell-book-name" : "";
return Object.entries(this.config.SLOTS[k]).map(([key, slots]) => {
const slotData = [];
for (let i = 0; i < slots.length; i++) {
Expand All @@ -79,6 +80,7 @@ export class SpellBook extends Application {
image: slots[i].img,
item,
itemColor,
// slotName,
empty: item ? "" : "spell-book-empty",
current: ((k == "LEFT" && page == this.pageNum.current - 1) || (k == "RIGHT" && page == this.pageNum.current)) ? "spell-book-current-page" : "",
});
Expand Down Expand Up @@ -109,6 +111,7 @@ export class SpellBook extends Application {
item: this.item,
background: img.background,
currentPage: this.pageNum.current,
showName: game.settings.get(MODULE_ID, 'showSpellName'),
};
Utilities.debug("getData", data);
return data;
Expand Down
32 changes: 32 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export function register_settings() {
scope: 'world',
config: true,
});
game.settings.register(MODULE_ID, 'spellItemType', {
name: "系统法术类型",
hint: "系统法术类型,当系统的法术类型不为power或spell时使用此值",
type: String,
default: "",
scope: 'world',
config: true,
});
game.settings.register(MODULE_ID, 'defaultSlotNum', {
name: "默认准备槽数量",
hint: "默认准备槽数量,当角色没有配置准备槽数量时初次打开准备槽时使用此值,以逗号分隔,第一个数只能是0或1",
Expand All @@ -48,6 +56,30 @@ export function register_settings() {
scope: 'world',
config: true,
});
game.settings.register(MODULE_ID, 'showSpellName', {
name: "显示法术名称",
hint: "在准备槽和法术书中显示法术名称",
type: Boolean,
default: false,
scope: 'world',
config: true,
});
game.settings.register(MODULE_ID, 'autoAddSpell', {
name: "自动添加法术",
hint: "当添加到准备槽的法术不在角色上时自动添加到角色上",
type: Boolean,
default: true,
scope: 'world',
config: true,
});
game.settings.register(MODULE_ID, 'detectSameName', {
name: "自动添加检测重名",
hint: "启用自动添加法术时检测重名法术,如果有重名法术则不添加",
type: Boolean,
default: true,
scope: 'world',
config: true,
});

game.settings.register(MODULE_ID, 'debug', {
name: "是否开启debug模式",
Expand Down
Binary file modified spellbook.zip
Binary file not shown.
45 changes: 39 additions & 6 deletions styles/module.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
background-position: center;
border: 3px ridge var(--prepar-slot-main-color);
box-shadow: inset 0 0 10px var(--prepar-slot-main-color);
display: flex;
justify-content: center;
}

.prepar-slot .prepar-slot-content .prepar-slot-foreground .prepar-slot-slot {
Expand Down Expand Up @@ -97,8 +99,9 @@
}
.prepar-slot .prepar-slot-content .prepar-slot-foreground .prepar-slot-pool,
.prepar-slot .prepar-slot-content .prepar-slot-foreground .prepar-slot-slot-mark,
.prepar-slot .prepar-slot-content .prepar-slot-foreground .prepar-slot-slot-use {
position: absolute;
.prepar-slot .prepar-slot-content .prepar-slot-foreground .prepar-slot-slot-use,
.prepar-slot .prepar-slot-content .prepar-slot-foreground .prepar-slot-slot-name {
position: relative;
background-color: darkslategray;
opacity: 0.8;
border: none;
Expand All @@ -115,27 +118,41 @@
top: 0;
left: 0;
height: 30px;
width: fit-content;
line-height: 30px;
border-radius: 0% 0% 50% 0%;
padding: 0px 10px;
font-size: large;
pointer-events: all;
}
.prepar-slot .prepar-slot-content .prepar-slot-foreground .prepar-slot-slot-mark {
top: 0;
left: 0;
width: 30%;
height: 30%;
width: fit-content;
height: fit-content;
line-height: 18px;
border-radius: 50%;
}
.prepar-slot .prepar-slot-content .prepar-slot-foreground .prepar-slot-slot-name {
width: -webkit-fill-available;
line-height: 18px;
border-radius: 10px;
word-break: keep-all;
}
.prepar-slot .prepar-slot-content .prepar-slot-foreground .prepar-slot-slot-use {
width: 100%;
height: 30%;
bottom: 0;
line-height: 18px;
border-radius: 10px;
font-size: large;
position: absolute;
}
.prepar-slot .prepar-slot-content .prepar-slot-foreground .prepar-slot-slot-head {
width: 100%;
height: 30%;
position: absolute;
top: 0;
display: flex;
justify-content: flex-start;
}

.spell-book .spell-book-content .spell-book-foreground {
Expand All @@ -146,4 +163,20 @@
padding: 30px;
grid-template-columns: repeat(2, 60px);
grid-gap: 15px;
}
.spell-book .spell-book-content .spell-book-foreground .spell-book-slot-name {
width: -webkit-fill-available;
height: 30%;
line-height: 18px;
border-radius: 10px;
background-color: #483b2a;
opacity: 0.8;
border: none;
box-shadow: none;
pointer-events: none;
text-align: center;
vertical-align: middle;
font-weight: bold;
color: white;
word-break: keep-all;
}
14 changes: 10 additions & 4 deletions templates/prepar-slot.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
<img class="prepar-slot-backimg" src="{{background}}" alt="">
</div>
<div class="prepar-slot-foreground">
<div class="prepar-slot-panel">
<div class="prepar-slot-panel" style="width: 100%; height: 100%;">
<div class="prepar-slot-pool" {{#unless limitPool}}hidden="true" {{/unless}} draggable="false">{{pool.value}}/{{pool.max}}</div>
{{#each prepared as |slots|}}
{{#each slots as |slot|}}
<div {{#unless slot.empty}}draggable="true" {{/unless}} data-tooltip="{{slot.item.name}}"
<div {{#unless slot.empty}}draggable="true" {{/unless}} data-tooltip-class="item-tooltip" data-tooltip="{{#if slot.item.uuid}}<section class=&quot;loading&quot; data-uuid=&quot;{{slot.item.uuid}}&quot;>{{slot.item.name}}</section>{{/if}}"
class="prepar-slot-slot {{slot.empty}}" data-index="{{slot.slotIndex}}" data-id="{{slot.slotId}}"
style="{{#if slot.itemColor}}box-shadow: inset 0 0 10px {{slot.itemColor}}, 0 0 5px {{slot.itemColor}}, 0 0 15px #00ffe7; border-color: {{slot.itemColor}};{{/if}} background-image: url('{{#if slot.item.img}}{{slot.item.img}}{{else}}{{slot.image}}{{/if}}'); position: absolute; top: {{slot.y}}px; left: {{slot.x}}px">
<i draggable="false" class="fa-solid fa-lock prepar-slot-lock {{slot.slotLocked}}" {{#unless slot.slotLocked}}style="display:none;" {{/unless}}></i>
{{!-- <img {{#unless slot.slotLocked}}hidden="true" {{/unless}} draggable="false" class="prepar-slot-lock {{slot.slotLocked}}" src="icons/svg/door-locked-outline.svg" /> --}}
<div class="prepar-slot-slot-mark" {{#unless slot.slotMark}}hidden="true" {{/unless}} draggable="false">{{slot.slotMark}}</div>
<div class="prepar-slot-slot-use" {{#unless slot.showUsed}}hidden="true" {{/unless}}{{#if slot.empty}}hidden="true" {{/if}} draggable="false">{{#if slot.showPool}}{{slot.slotUseNum}}{{else}}{{slot.slotUseCur}}/{{slot.slotUseMax}}{{/if}}</div>
<div class="prepar-slot-slot-head">
<div class="prepar-slot-slot-mark" {{#unless slot.slotMark}}hidden="true" {{/unless}} draggable="false">{{slot.slotMark}}</div>
<div class="prepar-slot-slot-name" {{#unless @root.showName}}hidden="true" {{/unless}}{{#unless slot.item.name}}hidden="true" {{/unless}} draggable="false">{{slot.item.name}}</div>
</div>
{{!-- <div class="prepar-slot-slot-text">
<div class="prepar-slot-slot-use" {{#unless slot.slotName}}{{#unless slot.item.name}}hidden="true" {{/unless}}{{/unless}} draggable="false">{{slot.item.name}}</div> --}}
<div class="prepar-slot-slot-use" {{#unless @root.showUsed}}hidden="true" {{/unless}}{{#if slot.empty}}hidden="true" {{/if}} draggable="false">{{#if @root.limitPool}}{{slot.slotUseNum}}{{else}}{{slot.slotUseCur}}/{{slot.slotUseMax}}{{/if}}</div>
{{!-- </div> --}}
</div>
{{/each}}
{{/each}}
Expand Down
8 changes: 6 additions & 2 deletions templates/spell-book.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
{{#each left as |slots|}}
{{#each slots as |slot|}}
<div {{#unless slot.empty}}draggable="true" {{/unless}} {{#unless slot.current}}hidden="true" {{/unless}}
data-tooltip="{{slot.item.name}}" class="spell-book-slot {{slot.empty}}" data-index="{{slot.slotIndex}}"
data-tooltip-class="item-tooltip" data-tooltip="{{#if slot.item.uuid}}<section class=&quot;loading&quot; data-uuid=&quot;{{slot.item.uuid}}&quot;>{{slot.item.name}}</section>{{/if}}"
class="spell-book-slot {{slot.empty}}" data-index="{{slot.slotIndex}}"
data-id="{{slot.slotId}}"
style="{{#if slot.itemColor}}box-shadow: inset 0 0 10px {{slot.itemColor}}; border-color: {{slot.itemColor}};{{/if}} background-image: url('{{#if slot.item.img}}{{slot.item.img}}{{else}}{{slot.image}}{{/if}}'); ">
<div class="spell-book-slot-name" {{#unless @root.showName}}hidden="true" {{/unless}}{{#unless slot.item.name}}hidden="true" {{/unless}} draggable="false">{{slot.item.name}}</div>
</div>
{{/each}}
{{/each}}
Expand All @@ -18,9 +20,11 @@
{{#each right as |slots|}}
{{#each slots as |slot|}}
<div {{#unless slot.empty}}draggable="true" {{/unless}} {{#unless slot.current}}hidden="true" {{/unless}}
data-tooltip="{{slot.item.name}}" class="spell-book-slot {{slot.empty}}" data-index="{{slot.slotIndex}}"
data-tooltip-class="item-tooltip" data-tooltip="{{#if slot.item.uuid}}<section class=&quot;loading&quot; data-uuid=&quot;{{slot.item.uuid}}&quot;><i class=&quot;fas fa-spinner fa-spin-pulse&quot;></i></section>{{/if}}"
class="spell-book-slot {{slot.empty}}" data-index="{{slot.slotIndex}}"
data-id="{{slot.slotId}}"
style="{{#if slot.itemColor}}box-shadow: inset 0 0 10px {{slot.itemColor}}; border-color: {{slot.itemColor}};{{/if}} background-image: url('{{#if slot.item.img}}{{slot.item.img}}{{else}}{{slot.image}}{{/if}}'); ">
<div class="spell-book-slot-name" {{#unless @root.showName}}hidden="true" {{/unless}}{{#unless slot.item.name}}hidden="true" {{/unless}} draggable="false">{{slot.item.name}}</div>
</div>
{{/each}}
{{/each}}
Expand Down

0 comments on commit 5eb6c4b

Please sign in to comment.