Date: 2023/09/10 07:14:19 UTC-07:00
Type: Denizen Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# speaker:
# title (string)
# text (string)
# options:
# - text (string)
# click (task)
tickquests_dialogue_update_text_task:
type: task
definitions: dialogue|dialogue_entity|selected[The selected option index.]
script:
- define title <[dialogue.speaker.title]>
- define text <[dialogue.speaker.text]>
- define lines <list>
# TITLE
- define lines:->:<[title]>
# TEXT
- define lines:->:<empty>
- define lines:->:<&[base]><[text]>
- define text <[lines].separated_by[<n>]>
- define line_width <[dialogue_entity].line_width>
- define height <[text].split_lines_by_width[<[line_width]>].split[<n>].size>
# OPTIONS
- define lines:->:<empty>
- define line_height_accumulated 0
- define line_heights <list>
- foreach <[dialogue.options]> as:opt:
- if <[selected].if_null[0]> == <[loop_index]>:
- define lines:->:<[opt.text].custom_color[emphasis].bold>
- else:
- define lines:->:<[opt.text].color[white]>
- define option_split_line <[opt.text].split_lines_by_width[<[line_width]>].split[<n>].size>
- define line_height_accumulated:+:<[option_split_line]>
- define line_height <[dialogue.options].size.add[1].sub[<[line_height_accumulated]>]>
- define line_heights:->:<[line_height]>
- announce "line height of '<[opt.text]>' is <[line_height]>"
- define text <[lines].separated_by[<n>]>
- adjust <[dialogue_entity]> text:<[text]>
- flag <[dialogue_entity]> tickquests.dialogue:<[dialogue]>
- flag <[dialogue_entity]> tickquests.line_heights:<[line_heights]>
- flag <[dialogue_entity]> tickquests.selected:<[selected]>
tickquests_dialogue_create_task:
type: task
definitions: dialogue|loc|dialogue_entity|players
description: Creates a dialogue entity at the given location and shows it to the given players. Creates interaction entities for each option.
script:
- if !<[dialogue_entity].exists>:
- fakespawn tickquests_dialogue_text_display <[loc]> save:text players:<[players]>
- define dialogue_entity <entry[text].faked_entity>
- define loc <[dialogue_entity].location>
- run tickquests_dialogue_update_text_task def.dialogue:<[dialogue]> def.dialogue_entity:<[dialogue_entity]>
- define base_height <[dialogue_entity].scale.y.mul[0.25]>
- foreach <[dialogue_entity].flag[tickquests.line_heights]> as:lh:
- spawn tickquests_dialogue_hover_entity <[loc].above[<[base_height].mul[<[lh].sub[1]>]>]> save:opt_entity
- define opt_entity <entry[opt_entity].spawned_entity>
- adjust <[opt_entity]> height:<[base_height]>
- adjust <[opt_entity]> width:2
tickquests_dialogue_hover_option:
type: task
definitions: dialogue_entity|opt_index
script:
- define dialogue <[dialogue_entity].flag[tickquests.dialogue]>
- run tickquests_dialogue_update_text_task def.dialogue:<[dialogue]> def.dialogue_entity:<[dialogue_entity]> def.selected:<[opt_index]>
tickquests_dialogue_text_display:
type: entity
entity_type: text_display
mechanisms:
background_color: black
pivot: center
display: left
scale: 0.7,0.7,0.7
line_width: 200
see_through: true
tickquests_dialogue_hover_entity:
type: entity
entity_type: interaction
tickquests_sample_dialogue:
type: data
d:
speaker:
title: James
text: Hello, I'm <element[James].custom_color[emphasis]>. This is a sample dialogue.
options: <list[<map[text=Opt 1]>].include_single[<map[text=Opt 2]>]>