Enhanced JavaScript environment for J2ME Devices
Table of Contents
Athena2ME is a project that seeks to facilitate and at the same time brings a complete kit for users to create homebrew software for Java ME mobile divices using the JavaScript language. It has dozens of built-in functions, both for creating games and apps. The main advantage over using Athena2ME project instead of Sun Wireless Toolkit or Nokia S40 SDK is above all the practicality, you will use one of the simplest possible languages to create what you have in mind, besides not having to compile, just script and test, fast and simple.
- os: OS dependant functions in general.
- Image: Image drawing.
- Draw: Shape drawing, rectangles, triangles etc.
- Screen: The entire screen of your project, enable or disable parameters.
- Font: Functions that control the texts that appear on the screen, loading texts, drawing and unloading from memory.
- Pad: Above being able to draw and everything else, A human interface is important.
- Keyboard: Basic keypad support.
- Timer: Control the time precisely in your code, it contains several timing functions.
New types are always being added and this list can grow a lot over time, so stay tuned.
- Image basic functions
- Screen basic functions
- OS Font functions
- Physical pad functions
- Keypad functions
- Timer functions
- OS external file functions
- OS platform functions
- std functions
- Thread functions
- 3D Render functions
- Network (requests, sockets, websockets)
- Archive (zip, 7zip, tar, rar) system
- Add float support
- Add ArrayBuffer support
- Add let, const
- Add array functions
- Add more JS standard functions
In this section you will have some information about how to code using Athena2ME, from prerequisites to useful functions and information about the language.
Using Athena2ME you only need one way to code and one way to test your code, that is, if you want, you can even create your code on yout J2ME device, but I'll leave some recommendations below.
-
PC: Visual Studio Code(with JavaScript extension) and some J2ME emulator or a real device.
-
Android: QuickEdit and some J2ME emulator or a real device.
Oh, and I also have to mention that an essential prerequisite for using Athena2ME is knowing how to code in JavaScript.
Hello World:
var font = new Font("default");
var running = true;
System.setExitHandler(function () {
running = false;
});
while (running) {
Screen.clear(); // Clear screen for the next frame.
font.print("Hello from Athena2ME!", 15, 15);
Screen.update(); // Updates the screen.
}
Athena2ME uses a heavily modified version of the RockScript interpreter for JavaScript language, which means that it brings some basic ES5 JavaScript features so far.
-
Object
• toString
• hasOwnProperty -
Function
• call
• apply -
Number
• MAX_VALUE
• MIN_VALUE
• NaN
• valueOf -
String
• fromCharCode
• valueOf
• charAt
• charCodeAt
• indexOf
• lastIndexOf
• substring
• split -
Array
• concat
• join
• push
• pop
• shift
• unshift
• slice
• sort
• reverse -
Date
• now
• getTime
• setTime -
Error
• name
• message
• toString -
Math
• random
• min
• max -
Misc
• console.log
• isNaN
• parseInt
• eval
• es - evalString
How to run it
Athena is basically a JavaScript loader, so it loads .js files inside .jar file (which is a zip file). It runs "main.js" by default.
Below is the list of usable functions of Athena2ME project currently, this list is constantly being updated.
P.S.: Italic parameters refer to optional parameters
- os.setExitHandler(func) - Set func to be called when the device run any action to exit Athena2ME.
- os.platform - Return a string representing the platform: "j2me".
- var col = Color.new(r, g, b, a) - Returns a color object from the specified RGB(A) parameters.
Construction:
- var image = new Image(path);
path - Path to the file, E.g.: "/test.png".
var test = new Image("/owl.png");
Properties:
- width, height - Image drawing size, default value is the original image size.
- startx, starty - Beginning of the area that will be drawn from the image, the default value is 0.0.
- endx, endy - End of the area that will be drawn from the image, the default value is the original image size.
Methods:
- draw(x, y) - Draw loaded image onscreen(call it every frame). Example: image.draw(15.0, 100.0);
- free() - Free content immediately.
- Draw.rect(x, y, width, height, color) - Draws a rectangle on the specified color, position and size on the screen.
- Draw.line(x, y, x2, y2, color) - Draws a line on the specified colors and position on the screen.
- Draw.triangle(x, y, x2, y2, x3, y3, color) - Draws a triangle on the specified points positions and colors on the screen.
- Screen.clear(color) - Clears screen with the specified color. If you don't specify any argument, it will use black as default.
- Screen.update() - Run the render queue and jump to the next frame, i.e.: Updates your screen.
Constants:
Faces:
- Font.FACE_MONOSPACE
- Font.FACE_PROPORTIONAL
- Font.FACE_SYSTEM
Styles (P.S.: Styles can be combined, excepting STYLE_PLAIN):
- Font.STYLE_PLAIN
- Font.STYLE_BOLD
- Font.STYLE_ITALIC
- Font.STYLE_UNDERLINED
Sizes:
- Font.SIZE_SMALL
- Font.SIZE_MEDIUM
- Font.SIZE_LARGE
Construction:
var osdfnt = new Font("default"); //Load default font
var font = new Font(Font.FACE_MONOSPACE, Font.STYLE_ITALIC, Font.SIZE_MEDIUM); //Load a custom variant font. Arguments: face, style, size (style and size are optional)
Properties:
- color - Define font tinting, default value is Color.new(255, 255, 255).
- align - Font alignment, default value is FontAlign.NONE. Avaliable options below:
• FontAlign.NONE
• FontAlign.TOP
• FontAlign.BOTTOM
• FontAlign.LEFT
• FontAlign.RIGHT
• FontAlign.VCENTER
• FontAlign.HCENTER
• FontAlign.CENTER
Methods:
- print(x, y, text) - Draw text on screen(call it every frame). Example: font.print(10.0, 10.0, "Hello world!);
- getTextSize(text) - Returns text absolute size in pixels (width, height). Example: const size = font.getTextSize("Hello world!");
- free() - Free asset content immediately.
-
Buttons list:
• Pad.UP
• Pad.DOWN
• Pad.LEFT
• Pad.RIGHT
• Pad.FIRE
• Pad.GAME_A
• Pad.GAME_B
• Pad.GAME_C
• Pad.GAME_D -
Pad.update() - Updates all pads pressed.
-
var fire_pressed = Pad.pressed(button) - Check if a button is being pressed (continuously).
-
var fire_pressed = Pad.justPressed(button) - Checks if a button was pressed only once.
- var c = Keyboard.get() - Get keyboard current char.
- var timer = new Timer()
• get()
• set(value)
• free()
• pause()
• resume()
• reset()
• playing()
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AwesomeFeature
) - Commit your Changes (
git commit -m 'Add some AwesomeFeature'
) - Push to the Branch (
git push origin feature/AwesomeFeature
) - Open a Pull Request
Distributed under MIT. See LICENSE for more information.
Daniel Santos - @danadsees - [email protected]
Project Link: https://github.com/DanielSant0s/Athena2ME