Skip to content

Commit

Permalink
Merge pull request #70 from anatawa12/add-modelpack-name-to-name-of-t…
Browse files Browse the repository at this point in the history
…he-source-code

Add modelpack name to name of the source code
  • Loading branch information
anatawa12 authored May 22, 2020
2 parents 53ab89b + dbc6f7c commit b9a89a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fun ModelPackManager.getScriptAndDoScript(fileName: String): ScriptEngine {
usingContext { cx ->
val scope = makeNewScope()

val script = ScriptImporter.makeScript(filePath, scriptStr)
val script = ScriptImporter.makeScript(filePath, scriptStr, resource.pack)

script.exec(cx, scope)

Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/anatawa12/fixRtm/scripting/ScriptImporter.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.anatawa12.fixRtm.scripting

import com.anatawa12.fixRtm.io.FIXFileLoader
import com.anatawa12.fixRtm.io.FIXModelPack
import com.anatawa12.fixRtm.io.FIXResource
import net.minecraft.client.resources.IResource
import net.minecraft.util.ResourceLocation
import org.mozilla.javascript.*
import java.util.concurrent.ConcurrentHashMap
Expand All @@ -18,13 +21,15 @@ object ScriptImporter {

fun getScript(name: String): Script {
val resourceLocation = ResourceLocation(name)
val script = FIXFileLoader.getInputStream(resourceLocation).reader().use { it.readText() }
return makeScript(resourceLocation, script)
val resource = FIXFileLoader.getResource(resourceLocation)
val script = resource.inputStream.reader().use { it.readText() }
return makeScript(resourceLocation, script, resource.pack)
}

fun makeScript(name: ResourceLocation, script: String): Script {
fun makeScript(location: ResourceLocation, script: String, pack: FIXModelPack? = null): Script {
val script = preprocessScript(script)
return ScriptCompiledClassCache.compile(script, name.toString())
val name = if (pack != null) "$location(${pack.file.name})" else "$location"
return ScriptCompiledClassCache.compile(script, name)
}

private val allDependenceScripts = ConcurrentHashMap<ResourceLocation, Map<ResourceLocation, String>>()
Expand Down

0 comments on commit b9a89a3

Please sign in to comment.