Skip to content

Commit

Permalink
Comment change, fix grammars.
Browse files Browse the repository at this point in the history
  • Loading branch information
cao-awa committed Jan 5, 2025
1 parent f5fe604 commit c2a3900
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 51 deletions.
16 changes: 2 additions & 14 deletions src/main/java/com/github/cao/awa/conium/ConiumServerInitializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,8 @@ class ConiumServerInitializer : DedicatedServerModInitializer {
ConiumClient.willNeverInitialized()
ConiumDedicatedServer.onInitialized()

// Conium.reloadCallbacks.add {
// ConiumEventContextBuilder.request(
// ConiumEventType.USED_BLOCK,
// ConiumEventArgTypes.BLOCK_POS,
// ConiumEventArgTypes.SERVER_PLAYER
// ) { block, pos, player ->
// player.networkHandler.sendPacket(
// SynchronizeRegistryPayload("Player ${player.name.literalString} used block '$block' at '$pos'").packet
// )
// true
// }
// }

ServerConfigurationConnectionEvents.CONFIGURE.register { handler: ServerConfigurationNetworkHandler, server: MinecraftServer ->
// Register the configuring packet to synchronize registries.
ServerConfigurationConnectionEvents.CONFIGURE.register { handler: ServerConfigurationNetworkHandler, _: MinecraftServer ->
handler.sendPacket(
SynchronizeRegistryPayload().packet
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost
import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate

/**
* A dedicated script manager for conium that translate and compile scripts then evaluates.
* A dedicated script manager for conium that translates and compiles scripts then evaluates.
*
* ConiumScriptManager is script dynamic loadable.
*
Expand All @@ -52,23 +52,23 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
private val LOGGER: Logger = LogManager.getLogger("ConiumScriptManager")
private val DATA_TYPE: String = RegistryKeys.getPath(ConiumRegistryKeys.SCRIPT)

// Commons script here, all script uses theses script.
// Commons script here, all scripts use these scripts.
private val defaultCommons: String = IOUtil.read(ResourceLoader.get("assets/conium/scripts/conium.commons.kts"))
private val defaultBedrockScriptInit: String = IOUtil.read(ResourceLoader.get("assets/conium/scripts/conium.bedrock.script.init.kts"))
private val defaultBedrockCommons: String = IOUtil.read(ResourceLoader.get("assets/conium/scripts/conium.bedrock.commons.kts"))

/**
* The 'host' is kotlin scripting host that used to compile and evaluate the kotlin scripts.
*
* Don't use JSR223 API to evaluates scripts, it will cause unexpected produce env problems!
* Don't use JSR223 API to evaluate scripts, it will cause unexpected produce env problems!
*/
private val host: BasicJvmScriptingHost = BasicJvmScriptingHost()
}

/**
* The 'exportedScript' is shared script context when script return a '[ScriptExport]'
* The 'exportedScript' is shared script context when the script return a '[ScriptExport]'
*
* Other scripts can use comment to import these contexts where they marked as:
* Other scripts can use comment to import these contexts where they are marked as:
*
* '// IMPORT: ExportName' or '// IMPORT: ExportName, OtherExportName'
*/
Expand All @@ -84,9 +84,9 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
/**
* Prepares the intermediate object.
*
* This method is called in the prepare executor in a reload.
* This method is called in the prepared executor in a reload.
*
* @param profiler the prepare profiler
* @param profiler the prepared profiler
* @param manager the resource manager
*
* @return the prepared object
Expand Down Expand Up @@ -129,12 +129,12 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
manager: ResourceManager,
results: MutableMap<Identifier, Resource>
) {
// There are 3 types finder need to load.
// There is 3 types finder need to load.
val kotlinFinder = ResourceFinder(DATA_TYPE, ".kts")
val javascriptFinder = ResourceFinder(DATA_TYPE, ".js")
val typescriptFinder = ResourceFinder(DATA_TYPE, ".ts")

// Load kotlin script.
// Load kotlin scripts.
kotlinFinder.findResources(manager).entries.iterator().forEach {
results[it.key] = it.value
}
Expand All @@ -153,10 +153,10 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
/**
* Handles the prepared intermediate object.
*
* This method is called in the apply executor, or the game engine, in a reload.
* This method is called in the applied executor, or the game engine, in a reload.
*
* @param manager the resource manager
* @param profiler the apply profiler
* @param profiler the profiler
* @param prepared the prepared object
*
* @author aco_awa
Expand All @@ -173,12 +173,12 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
// Clear old exported script, scripts will export to here again in next step loading
this.exportedScript.clear()

// Add script for next step ordered loading.
// Add the script for next step ordered loading.
CollectionFactor.linkedList<ScriptEval>().let { scripts ->
// Load commons.
scripts.add(ScriptEval(defaultCommons, "ConiumCommons"))

// Bedrock common is only load when conium allow bedrock.
// Bedrock common is only load when conium allows bedrock.
if (Conium.allowBedrock) {
scripts.add(ScriptEval(defaultBedrockCommons, "ConiumBedrockCommons", "ConiumCommons"))
scripts.add(ScriptEval(defaultBedrockScriptInit, "ConiumBedrockScriptInit", "ConiumCommons", "ConiumBedrockCommons"))
Expand All @@ -193,7 +193,7 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
// Load script data after.
scripts.add(ScriptEval(content, path, "ConiumCommons"))
} else if (!Conium.allowBedrock) {
// When disabled bedrock script allows, then script won't be load.
// When bedrock scripting allows is disabled, then the script won't be load.
LOGGER.warn("Conium are disabled bedrock script, ignored '$identifier'")
} else if (path.endsWith(".ts")) {
// Load script data after translate typescript to kotlin.
Expand All @@ -210,13 +210,13 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
LOGGER.warn("Failed to translate the script: {}", content, it)
}
} else if (path.endsWith(".js")) {
// Javascript supports are not done.
// JavaScript supporting is not done.
TODO("Javascript translator are not implemented yet.")
}
}
}

// Scripts will compiles and executions in order.
// Scripts will compile and executions in order.
evalKotlin(scripts)
}
}
Expand Down Expand Up @@ -244,7 +244,7 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
}
})

// Use visitor to builds typescript AST after context parsed.
// Use the visitor to build typescript AST after context parsed.
return LanguageTypescriptVisitor().visitProgram(parser.program())
}

Expand All @@ -253,28 +253,29 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
// Prepares the typescript AST for next step translating.
typescriptFile.prepares()

// Translate typescript to conium script (kotlin script with conium API).
// Translate typescript to the conium script (kotlin script with conium API).
val translated: String = StructuringTranslator.translate(
// Use conium provider to processes something additional features.
// See the package 'com.github.cao.awa.conium.script.translate'
"conium",
// Translate to kotlin script.
LanguageTranslateTarget.KOTLIN_SCRIPT,
// Whole file to translates.
// Whole file to translate.
TypescriptTranslateElement.FILE,
typescriptFile
)

// Bedrock script need post script instance to 'BedrockEventContext',
// Bedrock script needs post the script instance to 'BedrockEventContext',
// because the 'world' or 'system' or others variables may uniques in different context.
// The bedrock commons use 'get() = access(this)' to access current context,
// when context created, it will push to the 'contexts' in 'BedrockEventContext', so 'access' can got current context for this script.
// when context created, it will push to the 'contexts' in 'BedrockEventContext',
// so 'access' can get current context for this script.
return@let translated
}
}

/**
* Post the kotlin scripts to ordered eval function.
* Post the kotlin scripts to ordering eval function.
*
* @param scripts scripts data
*
Expand All @@ -287,7 +288,7 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
/**
* Compile and evaluate the kotlin scripts in order, post once when callback was called.
*
* The callback will be calls after a script runs done.
* The callback will be called after a script runs done.
*
* @param scripts scripts data
*
Expand All @@ -297,9 +298,9 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
* @since 1.0.0
*/
private fun evalKotlin(scripts: Iterator<ScriptEval>) {
// Do not continues load when scripts already not has next.
// Do not continue to load when scripts already not has next.
if (scripts.hasNext()) {
// Get next script and process it.
// Get the next script and process it.
evalKotlin(scripts.next()) {
// Continues to processes until scripts has no next present.
evalKotlin(scripts)
Expand Down Expand Up @@ -343,29 +344,29 @@ class ConiumScriptManager : SinglePreparationResourceReloader<MutableMap<Identif
val result: ResultWithDiagnostics<EvaluationResult> = host.eval(
StringScriptSource(content),
// Create compilation configuration that dependencies whole java classpath.
// Dependencies whole classpath is necessary, otherwise kotlin script may not be executes anything,
// Dependencies whole classpath is necessary, otherwise the kotlin script may not be executing anything,
// like unable to load class 'java.lang.Object' or ETC.
createJvmCompilationConfigurationFromTemplate<ConiumScript> {
jvm {
dependenciesFromCurrentContext(wholeClasspath = true)
}
},
// No evaluation configuration, script contexts has maintained by conium.
// No evaluation configuration, script contexts have maintained by conium.
null
)

// Processes export and calls callback to load next script.
// Processes export and calls callback to load the next script.
when (result) {
is ResultWithDiagnostics.Success -> {
// When result is 'Success', then 'returnValue' must not be null.
// When the result is 'Success', then 'returnValue' must not be null.
result.value
.returnValue
.let { returnValue: ResultValue ->
// When the 'returnValue' is value, then it may be 'ScriptExport'.
(returnValue as? ResultValue.Value)
?.let(ResultValue.Value::value)
?.let { value ->
// When value type is 'ScriptExport', then export it to conium contexts.
// When the value type is 'ScriptExport', then export it to conium contexts.
(value as? ScriptExport)?.let {
// The 'ofCode' only allow types import can be import to scripts.
this.exportedScript[it.name] = it.ofCode(content)
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/com/github/cao/awa/conium/parameter/DynamicArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DynamicArgs<P : ParameterSelective?, R>(
* @see DynamicArgsBuilder
* @see DynamicArgType
*
* @return the new context arguments that trying to fills required arguments instance
* @return the new context arguments that trying to fill required arguments instance
*
* @author cao_awa
* @author 草二号机
Expand All @@ -67,7 +67,7 @@ class DynamicArgs<P : ParameterSelective?, R>(
for ((key: DynamicArgType<*>, value: Any?) in sources) {
// Only varying argument type to real argument instance.
if (value is DynamicArgType<*>) {
// Dynamic args has multiple varying methods, find until found or no more method can trys.
// Dynamic args has multiple varying methods, find until found or no more method can try.
for (dynamicVarying: DynamicArgs<*, *>? in value.dynamicArgs) {
// Do not process null dynamic args or transform the dynamic args that doesn't have correct lifecycles.
if (dynamicVarying == null || dynamicVarying.lifecycle != DynamicArgsLifecycle.TRANSFORM) {
Expand All @@ -76,19 +76,19 @@ class DynamicArgs<P : ParameterSelective?, R>(

// Run the dynamic vary.
val result: Any? = dynamicVarying.runCatching {
// Arise the dynamic args, it will continues to vary args or got a value.
// Arise the dynamic args, it will continue to vary args or got a value.
arising(identity, sources, null)
}.getOrNull()

// When result found, stop dynamic args varying.
// When a result found, stop dynamic args varying.
if (result != null) {
// And put to arguments map.
args[key] = result
break
}
}
} else {
// The real instance should directly put to arguments map.
// The real instance should directly put to the argument map.
args[key] = value
}
}
Expand All @@ -114,14 +114,15 @@ class DynamicArgs<P : ParameterSelective?, R>(
* @since 1.0.0
*/
fun arising(identity: Any, args: MutableMap<DynamicArgType<*>, Any?>, p: P?): R {
// When 'ParameterSelective' instance is null, means this dynamic args won't got more args, it should got a value.
// When 'ParameterSelective' instance is null, means this dynamic args won't get more dynamic args.
// Then this dynamic args instance should get a value later.
if (p == null) {
// Do trigger directly, no vary args.
return this.trigger.apply(identity, args, null)
}

// Vary args to got more completed arguments.
// Put 'queryArg'(DynamicArgType<*>) to source arguments map, it will vary to other value in next step varying.
// Put 'queryArg' to source arguments map, it will vary to other value in the next step varying.
for (queryArg: DynamicArgType<*> in this.queryArgs) {
// Do not add query arg to varying when args contains the real value.
if (args.containsKey(queryArg)) {
Expand Down

0 comments on commit c2a3900

Please sign in to comment.