mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-10 18:57:39 +07:00
Many new modding improvements
This commit is contained in:
parent
b128155615
commit
ac21c620fe
@ -5,8 +5,9 @@ const log = function(context, obj){
|
||||
}
|
||||
|
||||
const readString = path => Vars.mods.getScripts().readString(path)
|
||||
|
||||
const readBytes = path => Vars.mods.getScripts().readBytes(path)
|
||||
const loadMusic = path => Vars.mods.getScripts().loadMusic(path)
|
||||
const loadSound = path => Vars.mods.getScripts().loadSound(path)
|
||||
|
||||
var scriptName = "base.js"
|
||||
var modName = "none"
|
||||
|
@ -7,8 +7,9 @@ const log = function(context, obj){
|
||||
}
|
||||
|
||||
const readString = path => Vars.mods.getScripts().readString(path)
|
||||
|
||||
const readBytes = path => Vars.mods.getScripts().readBytes(path)
|
||||
const loadMusic = path => Vars.mods.getScripts().loadMusic(path)
|
||||
const loadSound = path => Vars.mods.getScripts().loadSound(path)
|
||||
|
||||
var scriptName = "base.js"
|
||||
var modName = "none"
|
||||
@ -40,6 +41,7 @@ importPackage(Packages.arc)
|
||||
importPackage(Packages.arc.func)
|
||||
importPackage(Packages.arc.graphics)
|
||||
importPackage(Packages.arc.graphics.g2d)
|
||||
importPackage(Packages.arc.graphics.gl)
|
||||
importPackage(Packages.arc.math)
|
||||
importPackage(Packages.arc.math.geom)
|
||||
importPackage(Packages.arc.scene)
|
||||
|
@ -19,6 +19,7 @@ public class MusicControl{
|
||||
public Seq<Music> ambientMusic = Seq.with();
|
||||
/** darker music, used in times of conflict */
|
||||
public Seq<Music> darkMusic = Seq.with();
|
||||
|
||||
protected Music lastRandomPlayed;
|
||||
protected Interval timer = new Interval();
|
||||
protected @Nullable Music current;
|
||||
|
@ -484,7 +484,7 @@ public class UnitTypes implements ContentList{
|
||||
}};
|
||||
|
||||
zenith = new UnitType("zenith"){{
|
||||
health = 1000;
|
||||
health = 700;
|
||||
speed = 1.9f;
|
||||
accel = 0.04f;
|
||||
drag = 0.016f;
|
||||
@ -492,13 +492,13 @@ public class UnitTypes implements ContentList{
|
||||
range = 140f;
|
||||
hitsize = 18f;
|
||||
lowAltitude = true;
|
||||
armor = 6f;
|
||||
armor = 5f;
|
||||
|
||||
engineOffset = 12f;
|
||||
engineSize = 3f;
|
||||
|
||||
weapons.add(new Weapon("zenith-missiles"){{
|
||||
reload = 32f;
|
||||
reload = 40f;
|
||||
x = 7f;
|
||||
rotate = true;
|
||||
shake = 1f;
|
||||
|
@ -185,6 +185,8 @@ public class Renderer implements ApplicationListener{
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
Events.fire(Trigger.preDraw);
|
||||
|
||||
camera.update();
|
||||
|
||||
if(Float.isNaN(camera.position.x) || Float.isNaN(camera.position.y)){
|
||||
@ -205,6 +207,8 @@ public class Renderer implements ApplicationListener{
|
||||
|
||||
Draw.sort(true);
|
||||
|
||||
Events.fire(Trigger.draw);
|
||||
|
||||
if(pixelator.enabled()){
|
||||
pixelator.register();
|
||||
}
|
||||
@ -254,6 +258,8 @@ public class Renderer implements ApplicationListener{
|
||||
Draw.reset();
|
||||
Draw.flush();
|
||||
Draw.sort(false);
|
||||
|
||||
Events.fire(Trigger.postDraw);
|
||||
}
|
||||
|
||||
private void drawBackground(){
|
||||
|
@ -128,6 +128,8 @@ public class UI implements ApplicationListener, Loadable{
|
||||
public void update(){
|
||||
if(disableUI || Core.scene == null) return;
|
||||
|
||||
Events.fire(Trigger.uiDrawBegin);
|
||||
|
||||
Core.scene.act();
|
||||
Core.scene.draw();
|
||||
|
||||
@ -143,6 +145,8 @@ public class UI implements ApplicationListener, Loadable{
|
||||
control.tutorial.draw();
|
||||
Draw.flush();
|
||||
}
|
||||
|
||||
Events.fire(Trigger.uiDrawEnd);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,7 +30,12 @@ public class EventType{
|
||||
openWiki,
|
||||
teamCoreDamage,
|
||||
socketConfigChanged,
|
||||
update
|
||||
update,
|
||||
draw,
|
||||
preDraw,
|
||||
postDraw,
|
||||
uiDrawBegin,
|
||||
uiDrawEnd
|
||||
}
|
||||
|
||||
public static class WinEvent{}
|
||||
|
@ -5,6 +5,9 @@ public class Layer{
|
||||
|
||||
public static final float
|
||||
|
||||
//min layer
|
||||
min = -11,
|
||||
|
||||
//background, which may be planets or an image or nothing at all
|
||||
background = -10,
|
||||
|
||||
@ -81,7 +84,10 @@ public class Layer{
|
||||
end = 200,
|
||||
|
||||
//things after pixelation - used for text
|
||||
endPixeled = 210
|
||||
endPixeled = 210,
|
||||
|
||||
//max layer
|
||||
max = 220
|
||||
|
||||
;
|
||||
}
|
||||
|
@ -132,14 +132,12 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
//draw schematic requests
|
||||
for(BuildPlan request : selectRequests){
|
||||
request.animScale = 1f;
|
||||
drawRequest(request);
|
||||
}
|
||||
selectRequests.each(req -> {
|
||||
req.animScale = 1f;
|
||||
drawRequest(req);
|
||||
});
|
||||
|
||||
for(BuildPlan request : selectRequests){
|
||||
drawOverRequest(request);
|
||||
}
|
||||
selectRequests.each(this::drawOverRequest);
|
||||
|
||||
if(player.isBuilder()){
|
||||
//draw things that may be placed soon
|
||||
|
@ -538,11 +538,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
if(test.get(req)) return req;
|
||||
}
|
||||
|
||||
for(BuildPlan req : selectRequests){
|
||||
if(test.get(req)) return req;
|
||||
}
|
||||
|
||||
return null;
|
||||
return selectRequests.find(test);
|
||||
}
|
||||
|
||||
protected void drawBreakSelection(int x1, int y1, int x2, int y2){
|
||||
|
@ -177,9 +177,7 @@ public class LExecutor{
|
||||
public void run(LExecutor exec){
|
||||
int address = exec.numi(index);
|
||||
|
||||
if(address >= 0 && address < exec.links.length){
|
||||
exec.setobj(output, exec.links[address]);
|
||||
}
|
||||
exec.setobj(output, address >= 0 && address < exec.links.length ? exec.links[address] : null);
|
||||
}
|
||||
}
|
||||
|
||||
|
79
core/src/mindustry/mod/ModLoadingMusic.java
Normal file
79
core/src/mindustry/mod/ModLoadingMusic.java
Normal file
@ -0,0 +1,79 @@
|
||||
package mindustry.mod;
|
||||
|
||||
import arc.audio.*;
|
||||
import arc.mock.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
|
||||
public class ModLoadingMusic implements Music{
|
||||
public @NonNull Music music = new MockMusic();
|
||||
|
||||
@Override
|
||||
public void play(){
|
||||
music.play();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause(){
|
||||
music.pause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(){
|
||||
music.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlaying(){
|
||||
return music.isPlaying();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLooping(){
|
||||
return music.isLooping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLooping(boolean isLooping){
|
||||
music.setLooping(isLooping);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume(){
|
||||
return music.getVolume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVolume(float volume){
|
||||
music.setVolume(volume);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPan(float pan, float volume){
|
||||
music.setPan(pan, volume);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPosition(){
|
||||
return music.getPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(float position){
|
||||
music.setPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
music.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompletionListener(OnCompletionListener listener){
|
||||
music.setCompletionListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisposed(){
|
||||
return music.isDisposed();
|
||||
}
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
package mindustry.mod;
|
||||
|
||||
import arc.*;
|
||||
import arc.assets.*;
|
||||
import arc.audio.*;
|
||||
import arc.files.*;
|
||||
import arc.mock.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.Log.*;
|
||||
@ -73,7 +76,7 @@ public class Scripts implements Disposable{
|
||||
Log.log(level, "[@]: @", source, message);
|
||||
}
|
||||
|
||||
//utility mod functions
|
||||
//region utility mod functions
|
||||
|
||||
public String readString(String path){
|
||||
return Vars.tree.get(path, true).readString();
|
||||
@ -83,6 +86,38 @@ public class Scripts implements Disposable{
|
||||
return Vars.tree.get(path, true).readBytes();
|
||||
}
|
||||
|
||||
public Sound loadSound(String soundName){
|
||||
if(Vars.headless) return new MockSound();
|
||||
|
||||
String name = "sounds/" + soundName;
|
||||
String path = Vars.tree.get(name + ".ogg").exists() && !Vars.ios ? name + ".ogg" : name + ".mp3";
|
||||
|
||||
if(Core.assets.contains(path, Sound.class)) return Core.assets.get(path, Sound.class);
|
||||
ModLoadingSound sound = new ModLoadingSound();
|
||||
AssetDescriptor<?> desc = Core.assets.load(path, Sound.class);
|
||||
desc.loaded = result -> sound.sound = (Sound)result;
|
||||
desc.errored = Throwable::printStackTrace;
|
||||
|
||||
return sound;
|
||||
}
|
||||
|
||||
public Music loadMusic(String soundName){
|
||||
if(Vars.headless) return new MockMusic();
|
||||
|
||||
String name = "music/" + soundName;
|
||||
String path = Vars.tree.get(name + ".ogg").exists() && !Vars.ios ? name + ".ogg" : name + ".mp3";
|
||||
|
||||
if(Core.assets.contains(path, Music.class)) return Core.assets.get(path, Music.class);
|
||||
ModLoadingMusic sound = new ModLoadingMusic();
|
||||
AssetDescriptor<?> desc = Core.assets.load(path, Music.class);
|
||||
desc.loaded = result -> sound.music = (Music)result;
|
||||
desc.errored = Throwable::printStackTrace;
|
||||
|
||||
return sound;
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
public void run(LoadedMod mod, Fi file){
|
||||
currentMod = mod;
|
||||
run(file.readString(), file.name(), true);
|
||||
|
@ -28,11 +28,8 @@ public class CoreItemsDisplay extends Table{
|
||||
update(() -> {
|
||||
CoreBuild core = Vars.player.team().core();
|
||||
|
||||
for(Item item : content.items()){
|
||||
if(core != null && core.items.get(item) > 0 && usedItems.add(item)){
|
||||
rebuild();
|
||||
break;
|
||||
}
|
||||
if(content.items().contains(item -> core != null && core.items.get(item) > 0 && usedItems.add(item))){
|
||||
rebuild();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -178,7 +178,7 @@ public class Conveyor extends Block implements Autotiler{
|
||||
float mspeed = speed * tilesize * 55f;
|
||||
float centerSpeed = 0.1f;
|
||||
float centerDstScl = 3f;
|
||||
float tx = Geometry.d4x[rotation], ty = Geometry.d4y[rotation];
|
||||
float tx = Geometry.d4x(rotation), ty = Geometry.d4y(rotation);
|
||||
|
||||
float centerx = 0f, centery = 0f;
|
||||
|
||||
|
@ -207,7 +207,6 @@ public class LogicBlock extends Block{
|
||||
stream.readInt();
|
||||
}
|
||||
}else{
|
||||
|
||||
for(int i = 0; i < total; i++){
|
||||
String name = stream.readUTF();
|
||||
short x = stream.readShort(), y = stream.readShort();
|
||||
@ -290,6 +289,7 @@ public class LogicBlock extends Block{
|
||||
}
|
||||
|
||||
asm.putConst("@links", executor.links.length);
|
||||
asm.putConst("@ipt", instructionsPerTick);
|
||||
|
||||
//store any older variables
|
||||
for(Var var : executor.vars){
|
||||
|
@ -5,6 +5,7 @@ import arc.files.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.graphics.g2d.TextureAtlas.*;
|
||||
import arc.graphics.gl.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
@ -16,14 +17,14 @@ import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
public class ScriptStubGenerator{
|
||||
public class ScriptMainGenerator{
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
String base = "mindustry";
|
||||
Seq<String> blacklist = Seq.with("plugin", "mod", "net", "io", "tools");
|
||||
Seq<String> nameBlacklist = Seq.with("ClassAccess");
|
||||
Seq<Class<?>> whitelist = Seq.with(Draw.class, Fill.class, Lines.class, Core.class, TextureAtlas.class, TextureRegion.class, Time.class, System.class, PrintStream.class,
|
||||
AtlasRegion.class, String.class, Mathf.class, Angles.class, Color.class, Runnable.class, Object.class, Icon.class, Tex.class,
|
||||
AtlasRegion.class, String.class, Mathf.class, Angles.class, Color.class, Runnable.class, Object.class, Icon.class, Tex.class, Shader.class,
|
||||
Sounds.class, Musics.class, Call.class, Texture.class, TextureData.class, Pixmap.class, I18NBundle.class, Interval.class, DataInput.class, DataOutput.class,
|
||||
DataInputStream.class, DataOutputStream.class, Integer.class, Float.class, Double.class, Long.class, Boolean.class, Short.class, Byte.class, Character.class);
|
||||
Seq<String> nopackage = Seq.with("java.lang", "java");
|
Loading…
Reference in New Issue
Block a user