Ejemplo n.º 1
0
        public override Dictionary <string, string> GenerateReplacementDictionary(Options options, ResourceDatabase resDb)
        {
            Dictionary <string, string> replacements = this.ParentPlatform.GenerateReplacementDictionary(options, resDb);

            replacements["ORGANIZATION_NAME"] = "Organization Name";

            replacements["DEVELOPMENT_TEAM_ALL_CAPS"] = "";
            replacements["DEVELOPMENT_TEAM_NOT_CAPS"] = "";
            string developmentTeam = options.GetStringOrNull(ExportOptionKey.IOS_DEV_TEAM_ID);

            if (developmentTeam != null)
            {
                replacements["DEVELOPMENT_TEAM_NOT_CAPS"] = "DevelopmentTeam = " + developmentTeam + ";";
                replacements["DEVELOPMENT_TEAM_ALL_CAPS"] = "DEVELOPMENT_TEAM = " + developmentTeam + ";";
            }

            string bundleIdPrefix = options.GetStringOrNull(ExportOptionKey.IOS_BUNDLE_PREFIX);

            replacements["IOS_BUNDLE_ID"] = bundleIdPrefix == null
                ? options.GetString(ExportOptionKey.PROJECT_ID)
                : bundleIdPrefix + "." + options.GetString(ExportOptionKey.PROJECT_ID);

            OrientationParser orientations = new OrientationParser(options);

            replacements["IOS_SUPPORTED_ORIENTATIONS_INFO_PLIST"] = string.Join("",
                                                                                "\t<array>\n",
                                                                                orientations.SupportsPortrait ? "\t\t<string>UIInterfaceOrientationPortrait</string>\n" : "",
                                                                                orientations.SupportsUpsideDown ? "\t\t<string>UIInterfaceOrientationPortraitUpsideDown</string>\n" : "",
                                                                                orientations.SupportsLandscapeLeft ? "\t\t<string>UIInterfaceOrientationLandscapeLeft</string>\n" : "",
                                                                                orientations.SupportsLandscapeRight ? "\t\t<string>UIInterfaceOrientationLandscapeRight</string>\n" : "",
                                                                                "\t</array>");

            return(replacements);
        }
Ejemplo n.º 2
0
        public override void ExportProject(
            Dictionary <string, FileOutput> output,
            IList <LibraryForExport> libraries,
            ResourceDatabase resourceDatabase,
            Options options)
        {
            Dictionary <string, string> replacements = this.GenerateReplacementDictionary(options, resourceDatabase);

            this.OutputAndroidBoilerplate(output, replacements, options);

            options.SetOption(ExportOptionKey.JS_FILE_PREFIX, null);
            options.SetOption(ExportOptionKey.JS_FULL_PAGE, false); // TODO: figure out if logic should be implemented in the web view for this.
            options.SetOption(ExportOptionKey.JS_HEAD_EXTRAS, string.Join(
                                  "\n",
                                  "<script type=\"text/javascript\" src=\"android.js\"></script>",
                                  "<style type=\"text/css\">",
                                  "  body { margin:0px; background-color:#000; }",
                                  "  #crayon_host {",
                                  "    background-color:#000;",
                                  "    text-align:left;",
                                  "    width:100%;",
                                  "    height:100%;",
                                  "  }",
                                  "</style>"
                                  ));

            Dictionary <string, FileOutput> files        = new Dictionary <string, FileOutput>();
            Dictionary <string, FileOutput> basicProject = new Dictionary <string, FileOutput>();

            this.ParentPlatform.ExportProject(
                basicProject,
                libraries,
                resourceDatabase,
                options);

            // TODO: not good. The library inclusions should automatically be populated in LangJavaScript platforms.
            replacements["JS_LIB_INCLUSIONS"] = JavaScriptApp.PlatformImpl.GenerateJsLibInclusionHtml(basicProject.Keys);

            foreach (string filePath in basicProject.Keys)
            {
                FileOutput file = basicProject[filePath];
                if (filePath.EndsWith("index.html"))
                {
                    file.TextContent = file.TextContent.Replace(
                        "<script type=\"text/javascript\" src=\"",
                        "<script type=\"text/javascript\" src=\"file:///android_asset/");
                }
                files["app/src/main/assets/" + filePath] = file;
            }

            // TODO: use orientations
            OrientationParser orientations = new OrientationParser(options);

            foreach (string filename in files.Keys)
            {
                output[this.ApplyReplacements(filename, replacements)] = files[filename];
            }
        }
Ejemplo n.º 3
0
        public ToyRobotAssembly(ITextInputter textInputter, ITextOutputter textOutputter, ITableDimensions tableDimensions)
        {
            var initialRobotState        = new NotPlacedRobotState();
            var toyRobot                 = new ToyRobot.ToyRobot(initialRobotState);
            var robotStateFactory        = new RobotStateFactory();
            var robotStateBuilderFactory = new RobotStateBuilderFactory();
            var leftOrientationTurner    =
                new LeftOrientationTurner(robotStateBuilderFactory);
            var rightOrientationTurner =
                new RightOrientationTurner(robotStateBuilderFactory);
            var moveStateTransformer =
                new MoveStateTransformer(robotStateBuilderFactory);
            var moveAttempter           = new MoveAttempter(moveStateTransformer, tableDimensions);
            var commandPerformerFactory = new CommandPerformerFactory(
                robotStateFactory,
                leftOrientationTurner,
                rightOrientationTurner,
                moveAttempter,
                tableDimensions,
                textOutputter);
            var orientationFactory  = new OrientationParser();
            var reportCommandParser = new ReportCommandParser(commandPerformerFactory);
            var moveCommandParser   = new MoveCommandParser(commandPerformerFactory);
            var leftCommandParser   = new LeftCommandParser(commandPerformerFactory);
            var rightCommandParser  = new RightCommandParser(commandPerformerFactory);
            var placeCommandParser  = new PlaceCommandParser(
                commandPerformerFactory, orientationFactory);
            var commandParsers = new ICommandParser[]
            {
                reportCommandParser,
                moveCommandParser,
                leftCommandParser,
                rightCommandParser,
                placeCommandParser
            };
            var masterCommandParser = new MasterCommandParser(commandParsers);
            var commandHandler      = new CommandHandler(toyRobot, masterCommandParser);
            var commandReader       = new CommandReader(commandHandler);

            this.ToyRobotDriver = new ToyRobotDriver(textInputter, commandReader);
        }
Ejemplo n.º 4
0
        public override void ExportProject(
            Dictionary <string, FileOutput> output,
            IList <LibraryForExport> libraries,
            ResourceDatabase resourceDatabase,
            Options options)
        {
            options.SetOption(ExportOptionKey.JS_FILE_PREFIX, null);
            options.SetOption(ExportOptionKey.JS_FULL_PAGE, false); // iOS export has its own enforced fullscreen logic
            options.SetOption(ExportOptionKey.JS_HEAD_EXTRAS, "");
            Dictionary <string, string> replacements = this.GenerateReplacementDictionary(options, resourceDatabase);

            Dictionary <string, FileOutput> files        = new Dictionary <string, FileOutput>();
            Dictionary <string, FileOutput> basicProject = new Dictionary <string, FileOutput>();

            this.ParentPlatform.ExportProject(
                basicProject,
                libraries,
                resourceDatabase,
                options);

            // TODO: not good. The library inclusions should automatically be populated in LangJavaScript platforms.
            // This is also done identically in the ChromeApp PlatformImpl.
            replacements["JS_LIB_INCLUSIONS"] = JavaScriptApp.PlatformImpl.GenerateJsLibInclusionHtml(basicProject.Keys);

            foreach (string filePath in basicProject.Keys)
            {
                files["%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/jsres/" + filePath] = basicProject[filePath];
            }

            // TODO: use this in the pbxproj file.
            string uuidSeed = options.GetStringOrNull(ExportOptionKey.GUID_SEED);


            OrientationParser orientations         = new OrientationParser(options);
            bool       useLandscapeForLaunchscreen = orientations.SupportsLandscapeLeft || orientations.SupportsLandscapeRight;
            FileOutput launchScreen;

            if (options.GetBool(ExportOptionKey.HAS_LAUNCHSCREEN))
            {
                launchScreen = new FileOutput()
                {
                    Type   = FileOutputType.Image,
                    Bitmap = new Bitmap(options.GetString(ExportOptionKey.LAUNCHSCREEN_PATH)),
                };
            }
            else
            {
                string resourcePath = "SwiftResources/" + (useLandscapeForLaunchscreen ? "launchhorizontal.png" : "launchvertical.png");
                byte[] bytes        = new ResourceStore(typeof(JavaScriptAppIos.PlatformImpl)).ReadAssemblyFileBytes(resourcePath);

                launchScreen = new FileOutput()
                {
                    Type   = FileOutputType.Image,
                    Bitmap = new Bitmap(bytes),
                };
            }
            files["%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Assets.xcassets/Launchscreen.imageset/launchscreen.png"] = launchScreen;
            replacements["LAUNCH_SCREEN_WIDTH"]  = launchScreen.Bitmap.Width.ToString();
            replacements["LAUNCH_SCREEN_HEIGHT"] = launchScreen.Bitmap.Height.ToString();

            IconSetGenerator icons = new IconSetGenerator();

            if (options.GetBool(ExportOptionKey.HAS_ICON))
            {
                string[] iconPaths = options.GetStringArray(ExportOptionKey.ICON_PATH);
                foreach (string iconPath in iconPaths)
                {
                    Bitmap icon = new Bitmap(iconPath);
                    icons.AddInputImage(icon);
                }
            }

            Dictionary <int, Bitmap> iconImagesBySize = icons
                                                        .AddOutputSize(20 * 1)
                                                        .AddOutputSize(20 * 2)
                                                        .AddOutputSize(20 * 3)
                                                        .AddOutputSize(29 * 1)
                                                        .AddOutputSize(29 * 2)
                                                        .AddOutputSize(29 * 3)
                                                        .AddOutputSize(40 * 1)
                                                        .AddOutputSize(40 * 2)
                                                        .AddOutputSize(40 * 3)
                                                        .AddOutputSize(60 * 2)
                                                        .AddOutputSize(60 * 3)
                                                        .AddOutputSize(76 * 1)
                                                        .AddOutputSize(76 * 2)
                                                        .AddOutputSize(167) // 83.5 * 2
                                                        .AddOutputSize(1024)
                                                        .GenerateWithDefaultFallback();

            foreach (int size in iconImagesBySize.Keys)
            {
                files["%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Assets.xcassets/AppIcon.appiconset/icon" + size + ".png"] = new FileOutput()
                {
                    Type   = FileOutputType.Image,
                    Bitmap = iconImagesBySize[size],
                };
            }

            foreach (string pair in new string[] {
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%.xcodeproj/project.pbxproj|SwiftResources/PbxProj.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/AppDelegate.swift|SwiftResources/AppDelegateSwift.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Assets.xcassets/AppIcon.appiconset/Contents.json|SwiftResources/IconSetContentJson.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Assets.xcassets/Launchscreen.imageset/Contents.json|SwiftResources/ImageSetContentJson.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Base.lproj/LaunchScreen.storyboard|SwiftResources/LaunchScreenStoryboard.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Base.lproj/Main.storyboard|SwiftResources/MainStoryboard.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Info.plist|SwiftResources/InfoPlist.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/ViewController.swift|SwiftResources/ViewControllerSwift.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/jsres/ios.js|SwiftResources/iOSjs.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/jsres/index.html|SwiftResources/HostHtml.txt",
            })
            {
                string[] parts = pair.Split('|');
                files[parts[0]] = new FileOutput()
                {
                    TrimBomIfPresent = true,
                    Type             = FileOutputType.Text,
                    TextContent      = this.LoadTextResource(parts[1], replacements),
                };
            }

            foreach (string filename in files.Keys)
            {
                output[this.ApplyReplacements(filename, replacements)] = files[filename];
            }
        }
Ejemplo n.º 5
0
        public override void ExportProject(
            Dictionary <string, FileOutput> output,
            IList <VariableDeclaration> globals,
            IList <StructDefinition> structDefinitions,
            IList <FunctionDefinition> functionDefinitions,
            IList <LibraryForExport> libraries,
            ResourceDatabase resourceDatabase,
            Options options,
            ILibraryNativeInvocationTranslatorProvider libraryNativeInvocationTranslatorProviderForPlatform)
        {
            options.SetOption(ExportOptionKey.JS_FILE_PREFIX, null);
            options.SetOption(ExportOptionKey.JS_FULL_PAGE, false); // iOS export has its own enforced fullscreen logic
            options.SetOption(ExportOptionKey.JS_HEAD_EXTRAS, string.Join(
                                  "\n",
                                  "<script type=\"text/javascript\" src=\"ios.js\"></script>",
                                  "<style type=\"text/css\">",
                                  "  body { margin:0px; background-color:#000; }",
                                  "  #crayon_host {",
                                  "    background-color:#000;",
                                  "    text-align:left;",
                                  "    width:100%;",
                                  "    height:100%;",
                                  "  }",
                                  "</style>"
                                  ));
            Dictionary <string, string> replacements = this.GenerateReplacementDictionary(options, resourceDatabase);

            Dictionary <string, FileOutput> files        = new Dictionary <string, FileOutput>();
            Dictionary <string, FileOutput> basicProject = new Dictionary <string, FileOutput>();

            this.ParentPlatform.ExportProject(
                basicProject,
                globals,
                structDefinitions,
                functionDefinitions,
                libraries,
                resourceDatabase,
                options,
                libraryNativeInvocationTranslatorProviderForPlatform);

            // TODO: not good. The library inclusions should automatically be populated in LangJavaScript platforms.
            // This is also done identically in the ChromeApp PlatformImpl.
            replacements["JS_LIB_INCLUSIONS"] = JavaScriptApp.PlatformImpl.GenerateJsLibInclusionHtml(basicProject.Keys);

            foreach (string filePath in basicProject.Keys)
            {
                files["%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/jsres/" + filePath] = basicProject[filePath];
            }

            // TODO: use this in the pbxproj file.
            string uuidSeed = options.GetStringOrNull(ExportOptionKey.GUID_SEED);


            OrientationParser orientations         = new OrientationParser(options);
            bool       useLandscapeForLaunchscreen = orientations.SupportsLandscapeLeft || orientations.SupportsLandscapeRight;
            FileOutput launchScreen;

            if (options.GetBool(ExportOptionKey.HAS_LAUNCHSCREEN))
            {
                launchScreen = new FileOutput()
                {
                    Type   = FileOutputType.Image,
                    Bitmap = new SystemBitmap(options.GetString(ExportOptionKey.LAUNCHSCREEN_PATH)),
                };
            }
            else
            {
                launchScreen = new FileOutput()
                {
                    Type   = FileOutputType.Image,
                    Bitmap = new SystemBitmap(typeof(JavaScriptAppIosTranslator).Assembly, "SwiftResources/" +
                                              (useLandscapeForLaunchscreen ? "launchhorizontal.png" : "launchvertical.png")),
                };
            }
            files["%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Assets.xcassets/Launchscreen.imageset/launchscreen.png"] = launchScreen;
            replacements["LAUNCH_SCREEN_WIDTH"]  = launchScreen.Bitmap.Width.ToString();
            replacements["LAUNCH_SCREEN_HEIGHT"] = launchScreen.Bitmap.Height.ToString();

            IconSetGenerator icons = new IconSetGenerator();

            if (options.GetBool(ExportOptionKey.HAS_ICON))
            {
                string       iconPath = options.GetString(ExportOptionKey.ICON_PATH);
                SystemBitmap icon     = new SystemBitmap(iconPath);
                icons.AddInputImage(icon);
            }

            Dictionary <int, SystemBitmap> iconImagesBySize = icons
                                                              .AddOutputSize(20 * 1)
                                                              .AddOutputSize(20 * 2)
                                                              .AddOutputSize(20 * 3)
                                                              .AddOutputSize(29 * 1)
                                                              .AddOutputSize(29 * 2)
                                                              .AddOutputSize(29 * 3)
                                                              .AddOutputSize(40 * 1)
                                                              .AddOutputSize(40 * 2)
                                                              .AddOutputSize(40 * 3)
                                                              .AddOutputSize(60 * 2)
                                                              .AddOutputSize(60 * 3)
                                                              .AddOutputSize(76 * 1)
                                                              .AddOutputSize(76 * 2)
                                                              .AddOutputSize(167) // 83.5 * 2
                                                              .GenerateWithDefaultFallback();

            foreach (int size in iconImagesBySize.Keys)
            {
                files["%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Assets.xcassets/AppIcon.appiconset/icon" + size + ".png"] = new FileOutput()
                {
                    Type   = FileOutputType.Image,
                    Bitmap = iconImagesBySize[size],
                };
            }

            foreach (string pair in new string[] {
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%.xcodeproj/project.pbxproj|SwiftResources/PbxProj.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/AppDelegate.swift|SwiftResources/AppDelegateSwift.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Assets.xcassets/AppIcon.appiconset/Contents.json|SwiftResources/IconSetContentJson.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Assets.xcassets/Launchscreen.imageset/Contents.json|SwiftResources/ImageSetContentJson.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Base.lproj/LaunchScreen.storyboard|SwiftResources/LaunchScreenStoryboard.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Base.lproj/Main.storyboard|SwiftResources/MainStoryboard.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/Info.plist|SwiftResources/InfoPlist.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/ViewController.swift|SwiftResources/ViewControllerSwift.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/jsres/ios.js|SwiftResources/iOSjs.txt",
                "%%%PROJECT_ID%%%/%%%PROJECT_ID%%%/jsres/index.html|SwiftResources/HostHtml.txt",
            })
            {
                string[] parts = pair.Split('|');
                files[parts[0]] = new FileOutput()
                {
                    TrimBomIfPresent = true,
                    Type             = FileOutputType.Text,
                    TextContent      = this.LoadTextResource(parts[1], replacements),
                };
            }

            foreach (string filename in files.Keys)
            {
                output[this.ApplyReplacements(filename, replacements)] = files[filename];
            }
        }