mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[libgdx] Use "placeholder name" instead of "name" for skin keys.
Better matches Spine editor terminology.
This commit is contained in:
parent
4259e86e19
commit
52c20335e1
@ -3346,7 +3346,8 @@ public class SkeletonSerializer {
|
|||||||
json.writeValue(visitedObjects.get(obj));
|
json.writeValue(visitedObjects.get(obj));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String refString = obj.getName() != null ? "<SkinEntry-" + obj.getName() + ">" : "<SkinEntry-" + (nextId++) + ">";
|
String refString = obj.getPlaceholderName() != null ? "<SkinEntry-" + obj.getPlaceholderName() + ">"
|
||||||
|
: "<SkinEntry-" + (nextId++) + ">";
|
||||||
visitedObjects.put(obj, refString);
|
visitedObjects.put(obj, refString);
|
||||||
|
|
||||||
json.writeObjectStart();
|
json.writeObjectStart();
|
||||||
@ -3359,7 +3360,7 @@ public class SkeletonSerializer {
|
|||||||
json.writeValue(obj.getSlotIndex());
|
json.writeValue(obj.getSlotIndex());
|
||||||
|
|
||||||
json.writeName("name");
|
json.writeName("name");
|
||||||
json.writeValue(obj.getName());
|
json.writeValue(obj.getPlaceholderName());
|
||||||
|
|
||||||
json.writeName("attachment");
|
json.writeName("attachment");
|
||||||
writeAttachment(obj.getAttachment());
|
writeAttachment(obj.getAttachment());
|
||||||
|
|||||||
@ -37,7 +37,7 @@ import com.badlogic.gdx.utils.OrderedSet;
|
|||||||
import com.esotericsoftware.spine.attachments.Attachment;
|
import com.esotericsoftware.spine.attachments.Attachment;
|
||||||
import com.esotericsoftware.spine.attachments.MeshAttachment;
|
import com.esotericsoftware.spine.attachments.MeshAttachment;
|
||||||
|
|
||||||
/** Stores attachments by slot index and attachment name.
|
/** Stores attachments by slot index and placeholder name.
|
||||||
* <p>
|
* <p>
|
||||||
* See SkeletonData {@link SkeletonData#defaultSkin}, Skeleton {@link Skeleton#skin}, and
|
* See SkeletonData {@link SkeletonData#defaultSkin}, Skeleton {@link Skeleton#skin}, and
|
||||||
* <a href="https://esotericsoftware.com/spine-runtime-skins">Runtime skins</a> in the Spine Runtimes Guide. */
|
* <a href="https://esotericsoftware.com/spine-runtime-skins">Runtime skins</a> in the Spine Runtimes Guide. */
|
||||||
@ -57,10 +57,10 @@ public class Skin {
|
|||||||
attachments.orderedItems().ordered = false;
|
attachments.orderedItems().ordered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds an attachment to the skin for the specified slot index and name. */
|
/** Adds an attachment to the skin for the specified slot index and placeholder name. */
|
||||||
public void setAttachment (int slotIndex, String name, Attachment attachment) {
|
public void setAttachment (int slotIndex, String placeholderName, Attachment attachment) {
|
||||||
if (attachment == null) throw new IllegalArgumentException("attachment cannot be null.");
|
if (attachment == null) throw new IllegalArgumentException("attachment cannot be null.");
|
||||||
var entry = new SkinEntry(slotIndex, name, attachment);
|
var entry = new SkinEntry(slotIndex, placeholderName, attachment);
|
||||||
if (!attachments.add(entry)) attachments.get(entry).attachment = attachment;
|
if (!attachments.add(entry)) attachments.get(entry).attachment = attachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ public class Skin {
|
|||||||
if (!constraints.contains(data, true)) constraints.add(data);
|
if (!constraints.contains(data, true)) constraints.add(data);
|
||||||
|
|
||||||
for (SkinEntry entry : skin.attachments.orderedItems())
|
for (SkinEntry entry : skin.attachments.orderedItems())
|
||||||
setAttachment(entry.slotIndex, entry.name, entry.attachment);
|
setAttachment(entry.slotIndex, entry.placeholderName, entry.attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds all bones and constraints and copies of all attachments from the specified skin to this skin. Mesh attachments are not
|
/** Adds all bones and constraints and copies of all attachments from the specified skin to this skin. Mesh attachments are not
|
||||||
@ -91,22 +91,22 @@ public class Skin {
|
|||||||
|
|
||||||
for (SkinEntry entry : skin.attachments.orderedItems()) {
|
for (SkinEntry entry : skin.attachments.orderedItems()) {
|
||||||
if (entry.attachment instanceof MeshAttachment mesh)
|
if (entry.attachment instanceof MeshAttachment mesh)
|
||||||
setAttachment(entry.slotIndex, entry.name, mesh.newLinkedMesh());
|
setAttachment(entry.slotIndex, entry.placeholderName, mesh.newLinkedMesh());
|
||||||
else
|
else
|
||||||
setAttachment(entry.slotIndex, entry.name, entry.attachment != null ? entry.attachment.copy() : null);
|
setAttachment(entry.slotIndex, entry.placeholderName, entry.attachment != null ? entry.attachment.copy() : null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the attachment for the specified slot index and name, or null. */
|
/** Returns the attachment for the specified slot index and placeholder name, or null. */
|
||||||
public @Null Attachment getAttachment (int slotIndex, String name) {
|
public @Null Attachment getAttachment (int slotIndex, String placeholderName) {
|
||||||
lookup.set(slotIndex, name);
|
lookup.set(slotIndex, placeholderName);
|
||||||
SkinEntry entry = attachments.get(lookup);
|
SkinEntry entry = attachments.get(lookup);
|
||||||
return entry != null ? entry.attachment : null;
|
return entry != null ? entry.attachment : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Removes the attachment in the skin for the specified slot index and name, if any. */
|
/** Removes the attachment in the skin for the specified slot index and placeholder name, if any. */
|
||||||
public void removeAttachment (int slotIndex, String name) {
|
public void removeAttachment (int slotIndex, String placeholderName) {
|
||||||
lookup.set(slotIndex, name);
|
lookup.set(slotIndex, placeholderName);
|
||||||
attachments.remove(lookup);
|
attachments.remove(lookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,39 +158,39 @@ public class Skin {
|
|||||||
for (SkinEntry entry : oldSkin.attachments.orderedItems()) {
|
for (SkinEntry entry : oldSkin.attachments.orderedItems()) {
|
||||||
SlotPose slot = slots[entry.slotIndex].pose;
|
SlotPose slot = slots[entry.slotIndex].pose;
|
||||||
if (slot.attachment == entry.attachment) {
|
if (slot.attachment == entry.attachment) {
|
||||||
Attachment attachment = getAttachment(entry.slotIndex, entry.name);
|
Attachment attachment = getAttachment(entry.slotIndex, entry.placeholderName);
|
||||||
if (attachment != null) slot.setAttachment(attachment);
|
if (attachment != null) slot.setAttachment(attachment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Stores an entry in the skin consisting of the slot index and the attachment name. */
|
/** Stores an entry in the skin consisting of the slot index and placeholder name. */
|
||||||
static public class SkinEntry {
|
static public class SkinEntry {
|
||||||
int slotIndex;
|
int slotIndex;
|
||||||
String name;
|
String placeholderName;
|
||||||
@Null Attachment attachment;
|
@Null Attachment attachment;
|
||||||
private int hashCode;
|
private int hashCode;
|
||||||
|
|
||||||
SkinEntry (int slotIndex, String name, @Null Attachment attachment) {
|
SkinEntry (int slotIndex, String placeholderName, @Null Attachment attachment) {
|
||||||
set(slotIndex, name);
|
set(slotIndex, placeholderName);
|
||||||
this.attachment = attachment;
|
this.attachment = attachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set (int slotIndex, String name) {
|
void set (int slotIndex, String placeholderName) {
|
||||||
if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0.");
|
if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0.");
|
||||||
if (name == null) throw new IllegalArgumentException("name cannot be null.");
|
if (placeholderName == null) throw new IllegalArgumentException("placeholderName cannot be null.");
|
||||||
this.slotIndex = slotIndex;
|
this.slotIndex = slotIndex;
|
||||||
this.name = name;
|
this.placeholderName = placeholderName;
|
||||||
hashCode = name.hashCode() + slotIndex * 37;
|
hashCode = placeholderName.hashCode() + slotIndex * 37;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSlotIndex () {
|
public int getSlotIndex () {
|
||||||
return slotIndex;
|
return slotIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The name the attachment is associated with, equivalent to the skin placeholder name in the Spine editor. */
|
/** The placeholder name that the attachment is associated with. */
|
||||||
public String getName () {
|
public String getPlaceholderName () {
|
||||||
return name;
|
return placeholderName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Attachment getAttachment () {
|
public Attachment getAttachment () {
|
||||||
@ -205,11 +205,11 @@ public class Skin {
|
|||||||
if (object == null) return false;
|
if (object == null) return false;
|
||||||
var other = (SkinEntry)object;
|
var other = (SkinEntry)object;
|
||||||
if (slotIndex != other.slotIndex) return false;
|
if (slotIndex != other.slotIndex) return false;
|
||||||
return name.equals(other.name);
|
return placeholderName.equals(other.placeholderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString () {
|
public String toString () {
|
||||||
return slotIndex + ":" + name;
|
return slotIndex + ":" + placeholderName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user