mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-13 12:16:53 +07:00
Content loading improvements
This commit is contained in:
parent
07598e3f2f
commit
d3747f0d4c
@ -3,7 +3,7 @@ const log = function(context, obj){
|
||||
}
|
||||
|
||||
const extendContent = function(classType, name, params){
|
||||
return new JavaAdapter(classType, params, modName + "-" + name)
|
||||
return new JavaAdapter(classType, params, name)
|
||||
}
|
||||
|
||||
const extend = function(classType, params){
|
||||
|
@ -5,7 +5,7 @@ const log = function(context, obj){
|
||||
}
|
||||
|
||||
const extendContent = function(classType, name, params){
|
||||
return new JavaAdapter(classType, params, modName + "-" + name)
|
||||
return new JavaAdapter(classType, params, name)
|
||||
}
|
||||
|
||||
const extend = function(classType, params){
|
||||
|
@ -3,6 +3,7 @@ package io.anuke.mindustry.core;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.func.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.util.ArcAnnotate.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.ctype.*;
|
||||
@ -23,6 +24,7 @@ public class ContentLoader{
|
||||
private ObjectMap<String, MappableContent>[] contentNameMap = new ObjectMap[ContentType.values().length];
|
||||
private Array<Content>[] contentMap = new Array[ContentType.values().length];
|
||||
private MappableContent[][] temporaryMapper;
|
||||
private @Nullable LoadedMod currentMod;
|
||||
private ObjectSet<Cons<Content>> initialization = new ObjectSet<>();
|
||||
private ContentList[] content = {
|
||||
new Fx(),
|
||||
@ -144,13 +146,23 @@ public class ContentLoader{
|
||||
|
||||
public void handleContent(Content content){
|
||||
contentMap[content.getContentType().ordinal()].add(content);
|
||||
}
|
||||
|
||||
public void setCurrentMod(LoadedMod mod){
|
||||
this.currentMod = mod;
|
||||
}
|
||||
|
||||
public String transformName(String name){
|
||||
return currentMod == null ? name : currentMod.name + "-" + name;
|
||||
}
|
||||
|
||||
public void handleMappableContent(MappableContent content){
|
||||
if(contentNameMap[content.getContentType().ordinal()].containsKey(content.name)){
|
||||
throw new IllegalArgumentException("Two content objects cannot have the same name! (issue: '" + content.name + "')");
|
||||
}
|
||||
if(currentMod != null){
|
||||
content.mod = currentMod;
|
||||
}
|
||||
contentNameMap[content.getContentType().ordinal()].put(content.name, content);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ public abstract class MappableContent extends Content{
|
||||
public final String name;
|
||||
|
||||
public MappableContent(String name){
|
||||
this.name = name;
|
||||
this.name = Vars.content.transformName(name);
|
||||
Vars.content.handleMappableContent(this);
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@ public abstract class UnlockableContent extends MappableContent{
|
||||
public UnlockableContent(String name){
|
||||
super(name);
|
||||
|
||||
this.localizedName = Core.bundle.get(getContentType() + "." + name + ".name", name);
|
||||
this.description = Core.bundle.getOrNull(getContentType() + "." + name + ".description");
|
||||
this.localizedName = Core.bundle.get(getContentType() + "." + this.name + ".name", this.name);
|
||||
this.description = Core.bundle.getOrNull(getContentType() + "." + this.name + ".description");
|
||||
}
|
||||
|
||||
/** Generate any special icons for this content. Called asynchronously.*/
|
||||
|
@ -382,8 +382,10 @@ public class Mods implements Loadable{
|
||||
public void loadScripts(){
|
||||
Time.mark();
|
||||
|
||||
try{
|
||||
for(LoadedMod mod : loaded){
|
||||
if(mod.root.child("scripts").exists()){
|
||||
content.setCurrentMod(mod.name);
|
||||
mod.scripts = mod.root.child("scripts").findAll(f -> f.extension().equals("js"));
|
||||
Log.info("[{0}] Found {1} scripts.", mod.meta.name, mod.scripts.size);
|
||||
|
||||
@ -404,6 +406,9 @@ public class Mods implements Loadable{
|
||||
}
|
||||
}
|
||||
}
|
||||
}finally{
|
||||
content.setCurrentMod(null);
|
||||
}
|
||||
|
||||
Log.info("Time to initialize modded scripts: {0}", Time.elapsed());
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ public class Item extends UnlockableContent{
|
||||
public Item(String name, Color color){
|
||||
super(name);
|
||||
this.color = color;
|
||||
this.description = Core.bundle.getOrNull("item." + this.name + ".description");
|
||||
}
|
||||
|
||||
public Item(String name){
|
||||
|
@ -31,7 +31,6 @@ public class Liquid extends UnlockableContent{
|
||||
public Liquid(String name, Color color){
|
||||
super(name);
|
||||
this.color = new Color(color);
|
||||
this.description = Core.bundle.getOrNull("liquid." + name + ".description");
|
||||
}
|
||||
|
||||
/** For modding only.*/
|
||||
|
@ -39,7 +39,6 @@ public class Mech extends UnlockableContent{
|
||||
public Mech(String name, boolean flying){
|
||||
super(name);
|
||||
this.flying = flying;
|
||||
this.description = Core.bundle.get("mech." + name + ".description");
|
||||
}
|
||||
|
||||
public Mech(String name){
|
||||
|
@ -51,7 +51,6 @@ public class UnitType extends UnlockableContent{
|
||||
|
||||
public <T extends BaseUnit> UnitType(String name){
|
||||
super(name);
|
||||
this.description = Core.bundle.getOrNull("unit." + name + ".description");
|
||||
}
|
||||
|
||||
public <T extends BaseUnit> void create(Prov<T> mainConstructor){
|
||||
|
@ -156,7 +156,6 @@ public class Block extends BlockStorage{
|
||||
|
||||
public Block(String name){
|
||||
super(name);
|
||||
this.description = Core.bundle.getOrNull("block." + name + ".description");
|
||||
this.solid = false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user