Skip to content

Commit

Permalink
Limit maximum character name
Browse files Browse the repository at this point in the history
  • Loading branch information
lorgan3 committed Sep 8, 2024
1 parent de71b8b commit 326ecb8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/organisms/TeamDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const handleDelete = (event: Event) => {
flex-grow: 0;
background: var(--background);
overflow: hidden;
white-space: nowrap;
&.interactive {
cursor: pointer;
Expand Down
16 changes: 12 additions & 4 deletions src/data/entity/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const PAGE_READ_DURATION = 60;

const MELEE_POWER = 20;

const MAX_NAME_LENGTH = 30;

enum AnimationState {
Idle = "elf_idle",
Walk = "elf_walk",
Expand Down Expand Up @@ -183,6 +185,7 @@ export class Character extends Container implements HurtableEntity, Syncable {
private spellSource: any | null = null;
private lookDirection = 1;
private wings?: Wings;
private namePlateName: string;

private animator: Animator<AnimationState>;

Expand All @@ -194,6 +197,11 @@ export class Character extends Container implements HurtableEntity, Syncable {
) {
super();

this.namePlateName =
characterName.length > MAX_NAME_LENGTH
? characterName.slice(0, MAX_NAME_LENGTH - 3) + "..."
: characterName;

this.body = new Body(Level.instance.terrain.characterMask, {
mask: rectangle6x16,
onCollide: this.onCollide,
Expand Down Expand Up @@ -303,7 +311,7 @@ export class Character extends Container implements HurtableEntity, Syncable {
sprite2.alpha = 0.5;

this.namePlate = new BitmapText({
text: `${characterName} ${this._hp}`,
text: `${this.namePlateName} ${this._hp}`,
style: {
fontFamily: "Eternal",
fontSize: 32,
Expand Down Expand Up @@ -347,7 +355,7 @@ export class Character extends Container implements HurtableEntity, Syncable {
this.lastReportedHp - this._hp,
...this.getCenter()
);
this.namePlate.text = `${this.characterName} ${Math.max(
this.namePlate.text = `${this.namePlateName} ${Math.max(
0,
Math.ceil(this._hp)
)}`;
Expand Down Expand Up @@ -564,7 +572,7 @@ export class Character extends Container implements HurtableEntity, Syncable {
this.lastReportedHp - this._hp,
...this.getCenter()
);
this.namePlate.text = `${this.characterName} ${Math.max(
this.namePlate.text = `${this.namePlateName} ${Math.max(
0,
Math.ceil(this._hp)
)}`;
Expand Down Expand Up @@ -642,7 +650,7 @@ export class Character extends Container implements HurtableEntity, Syncable {
if (diff > 0) {
Level.instance.numberContainer.heal(diff, ...this.getCenter());
this.lastReportedHp += diff;
this.namePlate.text = `${this.characterName} ${Math.max(
this.namePlate.text = `${this.namePlateName} ${Math.max(
0,
Math.ceil(this.lastReportedHp)
)}`;
Expand Down
2 changes: 1 addition & 1 deletion src/util/assets/assetsContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class AssetsContainer {
fontSize: 32,
fill: "#fff",
dropShadow: {
distance: 4,
distance: 2,
angle: 45,
},
},
Expand Down

0 comments on commit 326ecb8

Please sign in to comment.