Skip to content

Commit 5307cf3

Browse files
committed
Finish importing Learning Trail articles
1 parent 9993d35 commit 5307cf3

File tree

23 files changed

+1261
-163
lines changed

23 files changed

+1261
-163
lines changed
Lines changed: 89 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
package com.laytonsmith.annotations;
42

53
import com.laytonsmith.core.PlatformResolver;
@@ -15,94 +13,104 @@
1513

1614
/**
1715
* Marks a function as an API function, which includes it in the list of functions.
18-
*
16+
*
1917
*/
2018
@Retention(RetentionPolicy.RUNTIME)
2119
@Target(ElementType.TYPE)
2220
public @interface api {
23-
24-
public enum Platforms{
25-
INTERPRETER_JAVA(null, "Java Interpreter"),
26-
COMPILER_BASH(new BashPlatformResolver(), "Bash Compiler");
27-
private PlatformResolver resolver;
28-
private String platformName;
29-
/**
30-
* Returns the platform specific resolver, which is able to override base functionality,
31-
* which will be adjusted as needed. If the resolver is null, one does not exist, implying
32-
* that the default is fine.
33-
* @return
34-
*/
35-
public PlatformResolver getResolver(){
36-
return this.resolver;
37-
}
38-
public String platformName(){
39-
return this.platformName;
40-
}
41-
private Platforms(PlatformResolver resolver, String platformName){
42-
this.resolver = resolver;
43-
this.platformName = platformName;
44-
}
45-
}
46-
21+
22+
public enum Platforms {
23+
INTERPRETER_JAVA(null, "Java Interpreter"),
24+
COMPILER_BASH(new BashPlatformResolver(), "Bash Compiler");
25+
private PlatformResolver resolver;
26+
private String platformName;
27+
4728
/**
48-
* Returns the platform this is implemented for. The default is {@see api.Platforms#INTERPRETER_JAVA}.
49-
* @return
29+
* Returns the platform specific resolver, which is able to override base functionality, which will be adjusted
30+
* as needed. If the resolver is null, one does not exist, implying that the default is fine.
31+
*
32+
* @return
5033
*/
51-
Platforms [] platform() default {api.Platforms.INTERPRETER_JAVA};
34+
public PlatformResolver getResolver() {
35+
return this.resolver;
36+
}
37+
38+
public String platformName() {
39+
return this.platformName;
40+
}
41+
42+
private Platforms(PlatformResolver resolver, String platformName) {
43+
this.resolver = resolver;
44+
this.platformName = platformName;
45+
}
46+
}
47+
48+
/**
49+
* Returns the platform this is implemented for. The default is {
50+
*
51+
* @see api.Platforms#INTERPRETER_JAVA}.
52+
* @return
53+
*/
54+
Platforms[] platform() default {api.Platforms.INTERPRETER_JAVA};
55+
56+
/**
57+
* Returns the environments this api element uses. The default is an empty array, but note that GlobalEnv.class is
58+
* implied for all elements, and it is not required to add that to this list.
59+
*
60+
* @return
61+
*/
62+
Class<? extends Environment.EnvironmentImpl>[] environments() default {};
63+
64+
/**
65+
* If this api element is enabled. The default is {@code true}, but you can temporarily disable an element by
66+
* setting this to false.
67+
*
68+
* @return
69+
*/
70+
boolean enabled() default true;
71+
72+
/**
73+
* This is a list of valid classes that are valid to be tagged with this annotation.
74+
*/
75+
public static enum ValidClasses {
76+
FUNCTION(com.laytonsmith.core.functions.FunctionBase.class),
77+
EVENT(com.laytonsmith.core.events.Event.class);
78+
private static List<Class> classes = null;
79+
Class classType;
80+
81+
private ValidClasses(Class c) {
82+
classType = c;
83+
}
84+
5285
/**
53-
* Returns the environments this api element uses. The default is an empty array, but note
54-
* that GlobalEnv.class is implied for all elements, and it is not required to add that to this
55-
* list.
56-
* @return
86+
* Returns a copy of the list of valid classes that may be tagged with the api annotation.
87+
*
88+
* @return
5789
*/
58-
Class<? extends Environment.EnvironmentImpl> [] environments() default {};
90+
public static List<Class> Classes() {
91+
if (classes == null) {
92+
Class[] cc = new Class[ValidClasses.values().length];
93+
for (int i = 0; i < ValidClasses.values().length; i++) {
94+
cc[i] = ValidClasses.values()[i].classType;
95+
}
96+
classes = Arrays.asList(cc);
97+
}
98+
return new ArrayList<Class>(classes);
99+
}
100+
59101
/**
60-
* If this api element is enabled. The default is {@code true}, but you can temporarily
61-
* disable an element by setting this to false.
62-
* @return
102+
* Returns true if the specified class extends a valid class.
103+
*
104+
* @param c
105+
* @return
63106
*/
64-
boolean enabled() default true;
65-
66-
/**
67-
* This is a list of valid classes that are valid to be tagged with this annotation.
68-
*/
69-
public static enum ValidClasses{
70-
FUNCTION(com.laytonsmith.core.functions.FunctionBase.class),
71-
EVENT(com.laytonsmith.core.events.Event.class);
72-
private static List<Class> classes = null;
73-
Class classType;
74-
private ValidClasses(Class c){
75-
classType = c;
76-
}
77-
78-
/**
79-
* Returns a copy of the list of valid classes that may be tagged with
80-
* the api annotation.
81-
* @return
82-
*/
83-
public static List<Class> Classes(){
84-
if(classes == null){
85-
Class[] cc = new Class[ValidClasses.values().length];
86-
for(int i = 0; i < ValidClasses.values().length; i++){
87-
cc[i] = ValidClasses.values()[i].classType;
88-
}
89-
classes = Arrays.asList(cc);
90-
}
91-
return new ArrayList<Class>(classes);
92-
}
93-
94-
/**
95-
* Returns true if the specified class extends a valid class.
96-
* @param c
97-
* @return
98-
*/
99-
public static boolean IsValid(Class c){
100-
for(Class cc : Classes()){
101-
if(cc.isAssignableFrom(c)){
102-
return true;
103-
}
104-
}
105-
return false;
106-
}
107+
public static boolean IsValid(Class c) {
108+
for (Class cc : Classes()) {
109+
if (cc.isAssignableFrom(c)) {
110+
return true;
111+
}
112+
}
113+
return false;
114+
}
107115
}
108116
}

src/main/java/com/laytonsmith/core/Main.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,13 +674,14 @@ public static void main(String[] args) throws Exception {
674674
f.createNewFile();
675675
f.setExecutable(true);
676676
FileUtil.write("#!/usr/bin/env /usr/local/bin/mscript"
677-
+ li + li
678-
+ "/**" + li
679-
+ " * Name: " + f.getName() + li
680-
+ " * Author: " + StaticLayer.GetConvertor().GetUser(null) + li
681-
+ " * Creation Date: " + new Scheduling.simple_date().exec(Target.UNKNOWN, null, new CString("yyyy-MM-dd", Target.UNKNOWN)).val() + li
682-
+ " * Description: " + li
683-
+ " */" + li + li, f, true);
677+
+ li
678+
+ "<!" + li
679+
+ "\tstrict;" + li
680+
+ "\tname: " + f.getName() + ";" + li
681+
+ "\tauthor: " + StaticLayer.GetConvertor().GetUser(null) + ";" + li
682+
+ "\tcreated: " + new Scheduling.simple_date().exec(Target.UNKNOWN, null, new CString("yyyy-MM-dd", Target.UNKNOWN)).val() + ";" + li
683+
+ "\tdescription: " + ";" + li
684+
+ ">" + li + li, f, true);
684685
}
685686
} else {
686687
throw new Error("Should not have gotten here");

src/main/java/com/laytonsmith/core/compiler/FileOptions.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,42 @@
66

77
/**
88
*
9-
*
9+
*
1010
*/
1111
public class FileOptions {
1212

1313
private boolean strict;
1414
private List<String> supressWarnings;
15+
private String name;
16+
private String author;
17+
private String created;
1518
private String description;
1619
//TODO: Make this non-public once this is all finished.
1720
public FileOptions(Map<String, String> parsedOptions) {
1821
strict = parseBoolean(getDefault(parsedOptions, "strict", "false"));
1922
supressWarnings = parseList(getDefault(parsedOptions, "supresswarnings", ""));
23+
name = getDefault(parsedOptions, "name", "");
24+
author = getDefault(parsedOptions, "author", "");
25+
created = getDefault(parsedOptions, "created", "");
2026
description = getDefault(parsedOptions, "description", null);
2127
}
22-
28+
2329
private String getDefault(Map<String, String> map, String key, String defaultIfNone){
2430
if(map.containsKey(key)){
2531
return map.get(key);
2632
} else {
2733
return defaultIfNone;
2834
}
2935
}
30-
36+
3137
private boolean parseBoolean(String bool){
3238
if(bool.equalsIgnoreCase("false") || bool.equalsIgnoreCase("off")){
3339
return false;
3440
} else {
3541
return true;
3642
}
3743
}
38-
44+
3945
private List<String> parseList(String list){
4046
List<String> l = new ArrayList<String>();
4147
for(String part : list.split(",")){
@@ -45,15 +51,27 @@ private List<String> parseList(String list){
4551
}
4652
return l;
4753
}
48-
54+
4955
public boolean isStrict(){
5056
return strict;
5157
}
52-
58+
5359
public boolean isWarningSupressed(String warning){
5460
return warning.trim().contains(warning.toLowerCase());
5561
}
56-
62+
63+
public String getName() {
64+
return name;
65+
}
66+
67+
public String getAuthor() {
68+
return author;
69+
}
70+
71+
public String getCreated() {
72+
return created;
73+
}
74+
5775
public String getDescription(){
5876
return description;
5977
}
@@ -62,8 +80,11 @@ public String getDescription(){
6280
public String toString() {
6381
return (strict ? "Strict Mode on" : "") + "\n" +
6482
(supressWarnings.isEmpty() ? "" : "Suppressed Warnings: " + supressWarnings.toString() + "\n") +
83+
(name.isEmpty() ? "" : "File name: " + name + "\n") +
84+
(author.isEmpty() ? "" : "Author: " + author + "\n") +
85+
(created.isEmpty() ? "" : "Creation Date: " + created + "\n") +
6586
(description == null ? "" : "File description: " + description + "\n");
66-
67-
}
68-
87+
88+
}
89+
6990
}

src/main/java/com/laytonsmith/core/functions/EntityManagement.java

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -601,66 +601,6 @@ public CHVersion since() {
601601
}
602602
}
603603

604-
@api
605-
public static class get_entity_breedable extends EntityGetterFunction {
606-
607-
@Override
608-
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
609-
MCEntity ent = Static.getEntity(args[0], t);
610-
if(ent instanceof MCAgeable) {
611-
return CBoolean.get(((MCAgeable) ent).getCanBreed());
612-
} else {
613-
throw new CREBadEntityException("Entity ID must be from an ageable entity!", t);
614-
}
615-
}
616-
617-
@Override
618-
public String getName() {
619-
return "get_entity_breedable";
620-
}
621-
622-
@Override
623-
public String docs() {
624-
return "boolean {entityID} Returns if an entity is set to be breedable.";
625-
}
626-
627-
@Override
628-
public CHVersion since() {
629-
return CHVersion.V3_3_1;
630-
}
631-
}
632-
633-
@api
634-
public static class set_entity_breedable extends EntitySetterFunction {
635-
636-
@Override
637-
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
638-
boolean breed = Static.getBoolean(args[1]);
639-
MCEntity ent = Static.getEntity(args[0], t);
640-
if(ent instanceof MCAgeable) {
641-
((MCAgeable) ent).setCanBreed(breed);
642-
} else {
643-
throw new CREBadEntityException("Entity ID must be from an ageable entity!", t);
644-
}
645-
return CVoid.VOID;
646-
}
647-
648-
@Override
649-
public String getName() {
650-
return "set_entity_breedable";
651-
}
652-
653-
@Override
654-
public String docs() {
655-
return "void {entityID, boolean} Set an entity to be breedable.";
656-
}
657-
658-
@Override
659-
public CHVersion since() {
660-
return CHVersion.V3_3_1;
661-
}
662-
}
663-
664604
@api
665605
public static class get_entity_age extends EntityGetterFunction {
666606

0 commit comments

Comments
 (0)