📜 ⬆️ ⬇️

PlayScript

Translator's note: a week ago, Zynga opened the source of a project that simplifies transferring games from Flash to mobile platforms. Since there are a lot of people in Habré who write games on flash or for mobile platforms, I present you the translation of the text from the page of this project. It is likely that you will want to use it in your designs.

What is PlayScript?


PlayScript is an open source project, which is an ActionScript-compatible compiler and a Flash-compatible runtime environment that runs on Mono .NET and is designed to create mobile applications using MonoTouch and Mono for Android. The combination of Adobe FlashBuilder for creating web applications and Xamarin Studio for mobile will allow you to develop multiplatform applications using all the advantages of IDE data, as well as the ability to access native APIs on mobile platforms.


The PlayScript compiler can also translate its code in C ++ and JavaScript (similar to Haxe), which allows you to create web applications that do not require Flash, as well as native applications for PC and mobile (with some restrictions). Note: Currently, JS and C ++ are in an experimental stage.
')
In addition to supporting ActionScript, the PlayScript compiler also supports the new language, PlayScript, which is a mixture of C # and ActionScript. This new language supports all the features of C #, including:
• Generics
• Properties
• Developments
• Value types
• Operator Overloading
• Asynchronous programming
• LINQ

Despite this, the language is backward compatible with ActionScript. PlayScript can be used to create web and mobile applications (via JavaScript and Mono). Existing Flash applications can be easily converted to PlayScript by simply renaming files from .as to .play and fixing some of the problems associated with the stricter syntax and semantics of the new language.

In addition, the PlayScript runtime provides full support for Stage3D, which allows you to port games to phones with very minor changes. Part of the display library was also implemented to support third-party Stage3D frameworks such as Starling, Away3D, and Feathers.

PlayScript provides a complete set of tools for creating and running ActionScript games on mobile phones using Mono and the web using Adobe Flash or JavaScript / HTML5.

How is PlayScript implemented?


The PlayScript compiler is implemented as an additional preprocessor to the Mono MCS compiler. Installing the PlayScript version of Mono will allow you to compile all three languages ​​(C #, ActionScript and PlayScript) by simply adding files with the .cs, .as and .play extensions to the MCS command line.

Similarly, in Xamarin Studio IDE, on the framework version selection page, you can select PlayScript Mono, which allows you to add .as and .play files to any C # project and compile them using MonoTouch or Mono for Android. ActionScript code can directly call C # code, and vice versa.

How is Stage3D implemented?


PlayScript includes two libraries: PlayScript.Dynamic_aot.dll, and pscorlib.dll, which implement the runtime and Stage3D via OpenGL. Links to these libraries in your project will allow you to run existing code using Stage3D without modification.

Current status


The PlayScript and ActionScript compiler is fairly stable at the moment (considering that it is built on the basis of a mature Mono), but there is still some ActionScript functionality that has not been implemented. Work is underway to eliminate these remaining issues and provide full compatibility with ActionScript.

ActionScript support

• Dynamic classes are compiled, but not yet implemented.
• The [Embed] tag is not yet implemented.
• The Singleton pattern using the guard class is not supported (using a private parameter in a public constructor)
• Static and non-static members with the same name are not supported.
• Class and package level instructions are not supported.
• A variety of minor bugs.

PlayScript support

• Insecure code is not supported (conflict with the use of the * symbol in ActionScript).
• Some problems with multi-dimensional arrays.
• Translation in JavaScript and C ++ is experimental.

Runtime support

• Much work has been done to support Stage3D and implement AGAL through HLSL.
• Starling and Away3D frameworks are fully functional.
• Very little work has been done on the net library and other kernel libraries.

How to install PlayScript?


You can download the current binary files here:

Mac OSX 0.1.2 (Mono 3.0.8)

Windows: (Coming)

Package includes Mono SDK, toolkit and libraries. To use the framework, install Xamarin Studio, and follow the instructions (see below) to make the PlayScript mono framework the default framework.

Build from source

Since PlayScript is part of Mono and MCS, you can use the appropriate Xamarin instructions for assembly.

Mac:

www.mono-project.com/Compiling_Mono_on_OSX

Windows:

www.mono-project.com/Compiling_Mono_on_Windows

In addition, the base libraries pscorlib.dll and PlayScript.Dynamic.dll (excluding Stage3D) will be compiled and added to the GAC in the final installer Mono. To use "monotouch", "monomac" or "monoandroid" versions of these libraries, use the .csproj files in the "mcs / class" folder in the repository.

How to use PlayScript in Xamarin Studio?


• Build Mono according to the instructions. Use --prefix = / Users / myname / playscript-mono-inst to install the framework in a convenient place on your hard disk.
• Open Xamarin Studio, and select “Preferences”.
• Select the “.NET runtimes” tab.
• Click on the “Add” button and select the folder where the PlayScript mono framework is located.
• Click the Set as Default button.
• Restart Xamarin Studio.

Now you should be able to add .as and .play files to your project and compile them.

Features:


Performance

• The use of "unsafe" code.
• Direct interaction with machine code (cocos2d-X, Page44, etc.).
• Optimized compiler for generating javascript.
• The ability to broadcast in C ++ with a minimum size of the application and with minimal overhead to start.

Extended Support Tools

• Full support for tools, including syntax highlighting and Intellisense in MonoDevelop IDE.
• Debugging source code on all platforms (FlashBuilder for Flash).
• Quick compilation in Release.

Full API support

• Full support for iOS and Android APIs via MonoTouch and Mono for Android.
• Full support for Windows / MacOSX API.
• Full integration with UI Builder (iOS) and Android GUI Builder through Xamarin Studio.

Differences between PlayScript and ActionScript

• PlayScript supports most of the features of C # 5.
• PlayScript requires a semicolon after the end of the instructions.
• PlayScript uses visibility blocks for variables.
• PlayScript requires the use of a break in the switch statement.
• PlayScript supports generics using AS3 syntax (. <>) Using C # functionality.
• PlayScript supports properties using the "property" keyword.
• PlayScript supports indexers and operator overloading with the keywords "indexer" and "operator".
• PlayScript implements namespaces in AS3 by converting them into .NET namespaces.

Differences between PlayScript and C #

• PlayScript requires the use of the “overload” keyword to overload methods.
• PlayScript does not support using statements.
• PlayScript browser does not support the checked and unchecked statements.
• PlayScript does not support unsafe code (although support will be added in the future).
• In PlayScript, you cannot directly access the properties of the underlying Object object (ToString (), GetType (), GetHashCode ()) until you convert it to System.Object. However, using this approach will make it impossible to translate your code in C ++ or JavaScript.

License


This Zynga project is released under the Apache license.

PlayScript sample code


// Basic types var b:byte; var sb:sbyte; var s:short; var us:ushort; var i:int; var u:uint; var l:long; var ul:ulong; var f:float; var d:double; // Conditional compilation #if DEBUG #else #endif // Fixed arrays var a:int[] = new int[100]; // Properties public property MyProperty:int { get { return _myInt; } set { _myInt = value; } } // Events public event MyEvent; // Delegates public delegate MyDelegate(i:int):void; // Operators public static operator - (i:int, j:int):int { } // Indexers public indexer this (index:int) { get { return _a[index]; } set { _a[index] = value; } } // Generics public class Foo.<T> { public var _f:T; public function foo<T>(v:T):void { } } // Async async function AccessTheWebAsync():Task.<int> { var client:HttpClient= new HttpClient(); var getStringTask:Task.<String> = client.GetStringAsync("http://msdn.microsoft.com"); var urlContents:String = await getStringTask; return urlContents.Length; } 

Source: https://habr.com/ru/post/176323/


All Articles