import ktxt2 conversion types

This commit is contained in:
2023-05-31 20:07:30 -06:00
parent c0d99f7bd3
commit 04cde116bc
7 changed files with 136 additions and 3 deletions

View File

@@ -0,0 +1,7 @@
# @install: lix --silent download "gh://github.com/kiss-lang/bad-nlp#f04043cd2231f707f263bf91e1fb7b8b5eeb504f" into bad-nlp/0.0.0/github/f04043cd2231f707f263bf91e1fb7b8b5eeb504f
# @run: haxelib run-dir bad-nlp "${HAXE_LIBCACHE}/bad-nlp/0.0.0/github/f04043cd2231f707f263bf91e1fb7b8b5eeb504f"
-lib haxe-strings
-lib kiss
-lib yaml
-cp ${HAXE_LIBCACHE}/bad-nlp/0.0.0/github/f04043cd2231f707f263bf91e1fb7b8b5eeb504f/src/
-D bad-nlp=0.0.0

View File

@@ -1,12 +1,12 @@
# @install: lix --silent download "gh://github.com/kiss-lang/kiss#3aa41cbcc0e9e5f87004f56f8b29b6d793c9cdf3" into kiss/0.0.1/github/3aa41cbcc0e9e5f87004f56f8b29b6d793c9cdf3
# @run: haxelib run-dir kiss "${HAXE_LIBCACHE}/kiss/0.0.1/github/3aa41cbcc0e9e5f87004f56f8b29b6d793c9cdf3"
# @install: lix --silent download "gh://github.com/kiss-lang/kiss#d46e386972dd893a690fd20427613bd9dca5a60d" into kiss/0.0.1/github/d46e386972dd893a690fd20427613bd9dca5a60d
# @run: haxelib run-dir kiss "${HAXE_LIBCACHE}/kiss/0.0.1/github/d46e386972dd893a690fd20427613bd9dca5a60d"
-lib haxe-strings
-lib hscript
-lib tink_json
-lib tink_macro
-lib tink_syntaxhub
-lib uuid
-cp ${HAXE_LIBCACHE}/kiss/0.0.1/github/3aa41cbcc0e9e5f87004f56f8b29b6d793c9cdf3/src
-cp ${HAXE_LIBCACHE}/kiss/0.0.1/github/d46e386972dd893a690fd20427613bd9dca5a60d/src
-D kiss=0.0.1
-w -WUnusedPattern
--macro kiss.KissFrontend.use()

View File

@@ -0,0 +1,8 @@
package tct;
import kiss.Prelude;
import kiss.List;
import bad_nlp.Names;
@:build(kiss.Kiss.build())
class NamesConversion {}

View File

@@ -0,0 +1,15 @@
(defNew [&prop &mut :String name
&prop &mut :String sourceType
&prop &mut :String outputType
:(String,Array<String>)->Bool canConvertNames
:Array<String>->String convertNames]
[
&mut :String->Bool canConvert ->block {
(Main.updateNameExceptions)
?(whenLet [names (Names.findNames block)] (canConvertNames block names))
}
&mut :String->String convert ->block {
(Main.updateNameExceptions)
(let [names (Names.findNames block)] (convertNames names))
}
])

View File

@@ -0,0 +1,8 @@
package tct;
import kiss.Prelude;
import kiss.List;
import kiss.Stream;
@:build(kiss.Kiss.build())
class StreamConversion {}

View File

@@ -0,0 +1,9 @@
(defNew [&prop &mut :String name
&prop &mut :String sourceType
&prop &mut :String outputType
:Stream->Bool canConvertStream
:Stream->String convertStream]
[
&mut :String->Bool canConvert ->block (canConvertStream (Stream.fromString block))
&mut :String->String convert ->block (convertStream (Stream.fromString block))
])

View File

@@ -0,0 +1,86 @@
// TCT Conversions for Fountain files
(function isUpperCase [s]
(= s (s.toUpperCase)))
(var :Array<String> specialSpeechTags [])
(function specialSpeech [name parenTag hmethod]
(specialSpeechTags.push parenTag)
(FileConversionProject.registerConversion
(new tct.StreamConversion name "fountain" "hollywoo"
->stream
?(whenLet [(Some name) (stream.takeUntilAndDrop " (${parenTag}")]
(and (isUpperCase name) {(stream.dropWhitespace) !(stream.isEmpty)}))
->stream
(let [name (whenLet [(Some name) (stream.takeUntilAndDrop " (${parenTag}")] name)
&mut output ""]
(stream.takeLine)
(loop
(let [wryly (ifLet [(Some w) (stream.takeBetween "(" ")\n")] w "")
line (ifLet [(Some l) (stream.takeLine)] (l.trim) (break))]
(when line
(+= output "$hmethod \"${name}\" \"${wryly}\" ##\"${line}\"##\n"))))
output))))
(specialSpeech "On Phone Speech" "O.P." "ONPHONESPEECH")
(specialSpeech "VoiceOver Speech" "V.O." "VOICEOVER")
(specialSpeech "Off-Screen Speech" "O.S." "OFFSCREENSPEECH")
(FileConversionProject.registerConversion
(new tct.StreamConversion "Normal Speech" "fountain" "hollywoo"
->stream ?(whenLet [(Some name) (stream.takeLine)]
(doFor tag specialSpeechTags
(whenLet [(Some _) (indexOf name "(${tag}")] (return false)))
(and (isUpperCase name) {(stream.dropWhitespace) !(stream.isEmpty)}))
->stream
(let [name (whenLet [(Some name) (stream.takeLine)] (.trim (name.replace "(CONT'D)" "")))
&mut output []]
(loop
(let [wryly (ifLet [(Some w) (stream.takeBetween "(" ")\n")] w "")
line (ifLet [(Some l) (stream.takeLine)] (l.trim) (break))]
(when line
(output.push "NORMALSPEECH \"${name}\" \"${wryly}\" ##\"${line}\"##"))))
(output.push "")
(output.join "\n"))))
(FileConversionProject.registerConversion
(new tct.StreamConversion "Label" "fountain" "hollywoo"
->stream ?{(stream.dropWhitespace) (stream.startsWith "/*")}
->stream
"LABEL $(.trim
(.replace
(.replace
(.replace stream.content "/*" "")
"*/" "")
"*" ""))\n"))
(function isScreenLine [:String block]
(when (block.startsWith "SUPER:") (return false))
(= 1 .length (filter (block.split "\n"))))
(function doWithCharacters [:String thing :String args]
(FileConversionProject.registerConversion
(new tct.NamesConversion "${thing} characters" "fountain" "hollywoo"
->[block names] (isScreenLine block)
->names (+
(.join (for name names "$(thing.toUpperCase)CHARACTER \"${name}\" $args") "\n")
"\n"))))
(doWithCharacters "Add" "<position key> <facing>")
(doWithCharacters "Remove" "")
(FileConversionProject.registerConversion
(new tct.StreamConversion "Timed super text" "fountain" "hollywoo"
->stream (stream.startsWith "SUPER:")
->stream {
(stream.dropString "SUPER:")
(stream.dropWhitespace)
(let [text (stream.expect "super text" ->(stream.takeLine))]
"TIMEDSUPERTEXT ##\"${text}\"## ##\"${text}\"##")
}))
(FileConversionProject.registerConversion
(new tct.StreamConversion "Delay" "fountain" "hollywoo"
->stream (isScreenLine stream.content)
->stream "DELAY ##\"$(stream.content.trim)\"##"))