-
-
Save agladysh/6f99595fc289fc28e251 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local create_dialog_state = function( | |
characters, | |
state_id, | |
block, | |
initial_state_id, | |
skip_emotions | |
) | |
arguments( | |
"table", characters, | |
"string", state_id, | |
"table", block, | |
"string", initial_state_id, | |
"table", skip_emotions | |
) | |
local dialog = assert(block.dialog); | |
local character_name_ru = nil | |
if dialog.character then | |
local character = characters[dialog.character] | |
character_name_ru = character.visible_name -- Hack. | |
or character.name | |
end | |
local on_start = create_on_start( | |
characters, | |
block.emotions, | |
false -- Dialog is not a cutscene | |
) | |
if block.sounds then | |
on_start[#on_start + 1] = | |
{ | |
effect = "play_sounds"; | |
channels = block.sounds; | |
} | |
end | |
return | |
{ | |
scene = assert(block.location); | |
on_start = on_start; | |
remark = | |
{ | |
character = character_name_ru or nil; | |
text = trim(assert(dialog[1])); | |
replies = timap( | |
function(reply) | |
return | |
{ | |
text = trim(assert(reply[1])); | |
visible = reply.if_seen | |
and ( | |
{ | |
effect = "play_or"; | |
values = timap( | |
function(seen_state_id) | |
return | |
{ | |
effect = "play_state_get"; | |
name = create_seen_var_name(seen_state_id); | |
default = false; | |
} | |
end, | |
reply.if_seen | |
); | |
} | |
) | |
or nil | |
; | |
transition = (reply.transition == false) | |
and | |
{ | |
state = false; | |
} | |
or | |
{ | |
state = skip_emotions[reply.transition.id] | |
and reply.transition.id | |
or create_emotion_state_id(reply.transition.id) | |
; | |
ops = (reply.transition.need_is_seen) | |
and | |
{ | |
{ | |
effect = "play_state_setter"; | |
values = | |
{ | |
[ | |
create_seen_var_name( | |
reply.transition.need_is_seen | |
) | |
] = true; | |
}; | |
}; | |
} | |
or nil | |
; | |
} | |
; | |
} | |
end, | |
assert(dialog.replies) | |
); | |
}; | |
} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T.dialog_reply = T:item { | |
text = _G.trim(T[1]); | |
visible = T.if_seen and { | |
effect = "play_or"; | |
values = T.if_seen:map { | |
T:item { | |
effect = "play_state_get"; | |
name = _G.seen_var_name(T); | |
default = false; | |
}; | |
}; | |
}; | |
transition = (T.transition == false) and { | |
state = false; | |
} or { | |
state = T.skip_emotions[T.transition.id] and | |
T.transition.id or | |
_G.emotion_state_id(T.transition.id); | |
ops = (T.transition.need_is_seen) and { | |
{ | |
effect = "play_state_setter"; | |
values = { | |
[_G.seen_var_name(T.transition.need_is_seen)] = true; | |
}; | |
}; | |
}; | |
}; | |
}; | |
T.dialog_state = | |
{ | |
scene = T.block.location; | |
on_start = T.on_start; | |
remark = { | |
character = T.character_name_ru or nil; | |
text = _G.trim(T.dialog[1]); | |
replies = T.dialog.replies:map { T.dialog_reply }; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local dialog_reply_visible = _ | |
{ | |
effect = "play_or"; | |
values = _:map(_.if_seen) | |
{ | |
_:item | |
{ | |
effect = "play_state_get"; | |
name = seen_var_name(_); | |
default = false; | |
}; | |
}; | |
} | |
local dialog_reply_transition = _ | |
{ | |
state = skip_emotions[_.transition.id] | |
and _.transition.id | |
or emotion_state_id(_.transition.id) | |
; | |
ops = (_.transition.need_is_seen) and | |
{ | |
{ | |
effect = "play_state_setter"; | |
values = | |
{ | |
[seen_var_name(_.transition.need_is_seen)] = true; | |
}; | |
}; | |
}; | |
} | |
local dialog_reply = _:item | |
{ | |
text = trim(_[1]); | |
visible = _(dialog_reply_visible); | |
transition = (_.transition) and _(dialog_reply_transition) or | |
{ | |
state = false; | |
}; | |
}; | |
dialog_state = _ | |
{ | |
scene = block.location; | |
on_start = _(on_start); -- Defined elsewhere | |
remark = | |
{ | |
character = character_name_ru or nil; | |
text = trim(dialog[1]); | |
replies = _:map(dialog.replies) { _(dialog_reply) }; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment