<commit_before>//
//  checkoutScanner.js
//
//  Created by <NAME> on 10/10/17.
//  Copyright 2017 High Fidelity, Inc.
//
//  Distributed under the Apache License, Version 2.0.
//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
//  This script acts on the scanner zone to pull up an item's marketplace page to enable purchasing.
/* global Selection, Render */
(function() {
    var highlightToggle = false;
    var mini = false;
    
    var TABLET = Tablet.getTablet("com.highfidelity.interface.tablet.system");
    var SHARED = Script.require('../attachmentZoneShared.js');
    var MARKET_PLACE_ITEM_URL_PREFIX = 'https://metaverse.highfidelity.com/marketplace';
    var MARKETPLACES_INJECT_SCRIPT_URL = ScriptDiscoveryService.defaultScriptsPath + 
        "/system/html/js/marketplacesInject.js";
    var SCAN_RADIUS = 0.15; // meters
    var SCAN_RADIUS_MINI = 0.07; // meters
    var OVERLAY_PREFIX = 'MP';
    var CHECKOUT_INTERVAL_MS = 500;
    var LIST_NAME = "highlightList3";
    var TRANSFORMS_SETTINGS = 'io.highfidelity.avatarStore.checkOut.tranforms';
    var SEARCH_RADIUS = 2;
    var SEARCH_RADIUS_MINI = 1;
    var HIGHLIGHT = Script.require('./ExternalOutlineConfig.js');
    var SCANNED_LOCAL_ROTATION = Quat.fromVec3Degrees({ x: 10, y: 140, z: 0 });
    var SCANNED_LOCAL_HEIGHT = 0.29;
    var OVERLAY_SPACING = 0.09;
    var MAKING_SURE_INTERVAL = 100; // Milliseconds
    var STOP_MAKING_SURE_TIMEOUT = 5000; // Milliseconds
    var PURCHASED_ITEM_SOUND = SoundCache.getSound(Script.resolvePath("../sounds/sound6.wav"));
    var SCANNED_ITEM_SOUND = SoundCache.getSound(Script.resolvePath("../sounds/sound8.wav"));
  
    var tableID;
    var interval;
    var scanPosition;
    var scannedMPOverlays = {};
    var prevID = 0;
    var matchingEntity;
    var overlayInScanner;
    var name;
    var highlightConfig = Render.getConfig("UpdateScene.HighlightStageSetup");
    var replicaStoredTransforms = {};
    var lastScannedOverlay;
    var lastScannedMPItem;
    var scanner;
  
    var Scanner = function() {
    };


    Scanner.prototype = {
        preload: function(entityID) {
            scanner = entityID;
            if (highlightToggle) {
                highlightConfig["selectionName"] = LIST_NAME; 
                Selection.clearSelectedItemsList(LIST_NAME);
                HIGHLIGHT.changeHighlight3(highlightConfig);
            }
            var sizeLimit = 0.2;
            if (Entities.getEntityProperties(entityID, 'dimensions.x').dimensions.x < sizeLimit) {
                mini = true;
            }
        },
      
        getTransformForMarketplaceItems: function() {
            return Settings.getValue(TRANSFORMS_SETTINGS, {});
        },

        onEntityAdded: function(entityID) {
            var newItemProperties = Entities.getEntityProperties(entityID, ['marketplaceID', 'clientOnly', 
                'owningAvatarID', 'lastEditedBy']);
            if ((newItemProperties.lastEditedBy === MyAvatar.sessionUUID || newItemProperties.lastEditedBy === 
                undefined) && newItemProperties.marketplaceID !== "") {
                if (lastScannedMPItem === newItemProperties.marketplaceID) {
                    scannerScript.replicaCheckedOut(lastScannedOverlay, entityID);
                    if (PURCHASED_ITEM_SOUND.downloaded) {
                        Audio.playSound(PURCHASED_ITEM_SOUND, {
                            position: MyAvatar.position,
                            volume: SHARED.AUDIO_VOLUME_LEVEL,
                            localOnly: true
                        });
                    }
                }
            }
        },
      
        getTransformsForMarketplaceItem: function(marketplaceID) {
            var transformItems = scannerScript.getTransformForMarketplaceItems();
            if (transformItems[marketplaceID] === undefined) {
                return {
                    certificateTransforms: {},
                    unsortedTransforms: [],
                    lastUsedUnsortedTransformIndex: -1
                };
            }
            return transformItems[marketplaceID];
        },
        
        addTransformForMarketplaceItem: function(marketplaceID, certificateID, transform) {
            if (marketplaceID === undefined) {
                return;
            }
            var marketplaceItemTransforms = scannerScript.getTransformForMarketplaceItems();
            var marketplaceItemTransform = scannerScript.getTransformsForMarketplaceItem(marketplaceID);
            if (certificateID !== undefined) {
                marketplaceItemTransform.certificateTransforms[certificateID] = transform;
            } else {
                marketplaceItemTransform.unsortedTransforms.push(transform);
            }
            marketplaceItemTransforms[marketplaceID] = marketplaceItemTransform;
            Settings.setValue(TRANSFORMS_SETTINGS, marketplaceItemTransforms);
        },

        replicaCheckedOut: function(replicaOverlayID, newEntityID) {
            if (replicaStoredTransforms[replicaOverlayID] === undefined) {
                Entities.deleteEntity(newEntityID);
                return;

            }
            var transform = replicaStoredTransforms[replicaOverlayID];
            var transformProperties = {
                parentID: MyAvatar.sessionUUID,
                parentJointIndex: MyAvatar.getJointIndex(transform.jointName),
                localPosition: transform.position,
                localRotation: transform.rotation,
                dimensions: transform.dimensions,
                velocity: {x: 0, y: 0, z: 0},
                dynamic: false
            };
            replicaStoredTransforms[replicaOverlayID] = transformProperties;

            Entities.editEntity(newEntityID, transformProperties);
        
            var makeSureInterval = Script.setInterval(function() {
                Entities.editEntity(newEntityID, transformProperties);
            }, MAKING_SURE_INTERVAL);
    
            Script.setTimeout(function() {
                makeSureInterval.stop();
            }, STOP_MAKING_SURE_TIMEOUT);
    
            var newEntityProperties = Entities.getEntityProperties(newEntityID, ['marketplaceID', 'certificateID']);
            var certificateID = undefined;
            if (newEntityProperties.certificateID !== "" && newEntityProperties.certificateID !== undefined) {
                certificateID = newEntityProperties.certificateID;

            }
            scannerScript.addTransformForMarketplaceItem(newEntityProperties.marketplaceID, certificateID, 
                transformProperties);
    
            Entities.deleteEntity(matchingEntity);
        },

        enterCheckout: function(entityID) {
            scannedMPOverlays = {};
            var newX;
            if (mini) {
                newX = 0.04;
            } else {
                newX = 0.03;
            }
            var newZ = -0.35; 
            var position1 = true;
            var position2 = false;
          
            interval = Script.setInterval(function() {
                print("scanner is searching");
                scanPosition = Entities.getEntityProperties(scanner, 'position').position;
                var overlays;
                if (mini) {
                    overlays = Overlays.findOverlays(scanPosition, SCAN_RADIUS_MINI);
                } else {
                    overlays = Overlays.findOverlays(scanPosition, SCAN_RADIUS);
                }
                if (overlays.length === 0 && overlayInScanner) {
                    if (highlightToggle) {
                        Selection.removeFromSelectedItemsList(LIST_NAME, "entity", matchingEntity);
                        Selection.removeFromSelectedItemsList(LIST_NAME, "overlay", overlayInScanner);
                        prevID = 0;
                    }

                    matchingEntity = null;
                    overlayInScanner = null;
                } else if ((overlays.length > 0) && (overlayInScanner) && 
                (overlays.toString().indexOf(overlayInScanner) === -1)) {
                    if (highlightToggle) {
                        Selection.removeFromSelectedItemsList(LIST_NAME, "entity", matchingEntity);
                        Selection.removeFromSelectedItemsList(LIST_NAME, "overlay", overlayInScanner);
                        prevID = 0;
                    }<commit_msg>Update checkoutScanner.js<commit_after>//
//  checkoutScanner.js
//
//  Created by <NAME> on 10/10/17.
//  Copyright 2017 High Fidelity, Inc.
//
//  Distributed under the Apache License, Version 2.0.
//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
//  This script acts on the scanner zone to pull up an item's marketplace page to enable purchasing.
/* global Selection, Render */
(function() {
    var highlightToggle = false;
    var mini = false;
    
    var TABLET = Tablet.getTablet("com.highfidelity.interface.tablet.system");
    var SHARED = Script.require('../attachmentZoneShared.js');
    var MARKET_PLACE_ITEM_URL_PREFIX = 'https://metaverse.highfidelity.com/marketplace';
    var MARKETPLACES_INJECT_SCRIPT_URL = ScriptDiscoveryService.defaultScriptsPath + 
        "/system/html/js/marketplacesInject.js";
    var SCAN_RADIUS = 0.15; // meters
    var SCAN_RADIUS_MINI = 0.07; // meters
    var OVERLAY_PREFIX = 'MP';
    var CHECKOUT_INTERVAL_MS = 500;
    var LIST_NAME = "highlightList3";
    var TRANSFORMS_SETTINGS = 'io.highfidelity.avatarStore.checkOut.tranforms';
    var SEARCH_RADIUS = 2;
    var SEARCH_RADIUS_MINI = 1;
    var HIGHLIGHT = Script.require('./ExternalOutlineConfig.js');
    var SCANNED_LOCAL_ROTATION = Quat.fromVec3Degrees({ x: 10, y: 140, z: 0 });
    var SCANNED_LOCAL_HEIGHT = 0.29;
    var OVERLAY_SPACING = 0.09;
    var MAKING_SURE_INTERVAL = 100; // Milliseconds
    var STOP_MAKING_SURE_TIMEOUT = 5000; // Milliseconds
    var PURCHASED_ITEM_SOUND = SoundCache.getSound(Script.resolvePath("../sounds/sound6.wav"));
    var SCANNED_ITEM_SOUND = SoundCache.getSound(Script.resolvePath("../sounds/sound8.wav"));
  
    var tableID;
    var interval;
    var scanPosition;
    var scannedMPOverlays = {};
    var prevID = 0;
    var matchingEntity;
    var overlayInScanner;
    var name;
    var highlightConfig = Render.getConfig("UpdateScene.HighlightStageSetup");
    var replicaStoredTransforms = {};
    var lastScannedOverlay;
    var lastScannedMPItem;
    var scanner;
  
    var Scanner = function() {
    };


    Scanner.prototype = {
        preload: function(entityID) {
            scanner = entityID;
            if (highlightToggle) {
                highlightConfig["selectionName"] = LIST_NAME; 
                Selection.clearSelectedItemsList(LIST_NAME);
                HIGHLIGHT.changeHighlight3(highlightConfig);
            }
            var sizeLimit = 0.2;
            if (Entities.getEntityProperties(entityID, 'dimensions.x').dimensions.x < sizeLimit) {
                mini = true;
            }
        },
      
        getTransformForMarketplaceItems: function() {
            return Settings.getValue(TRANSFORMS_SETTINGS, {});
        },

        onEntityAdded: function(entityID) {
            var newItemProperties = Entities.getEntityProperties(entityID, ['marketplaceID', 'clientOnly', 
                'owningAvatarID', 'lastEditedBy']);
            if ((newItemProperties.lastEditedBy === MyAvatar.sessionUUID || newItemProperties.lastEditedBy === 
                undefined) && newItemProperties.marketplaceID !== "") {
                if (lastScannedMPItem === newItemProperties.marketplaceID) {
                    scannerScript.replicaCheckedOut(lastScannedOverlay, entityID);
                    if (PURCHASED_ITEM_SOUND.downloaded) {
                        Audio.playSound(PURCHASED_ITEM_SOUND, {
                            position: MyAvatar.position,
                            volume: SHARED.AUDIO_VOLUME_LEVEL,
                            localOnly: true
                        });
                    }
                }
            }
        },
      
        getTransformsForMarketplaceItem: function(marketplaceID) {
            var transformItems = scannerScript.getTransformForMarketplaceItems();
            if (transformItems[marketplaceID] === undefined) {
                return {
                    certificateTransforms: {},
                    unsortedTransforms: [],
                    lastUsedUnsortedTransformIndex: -1
                };
            }
            return transformItems[marketplaceID];
        },
        
        addTransformForMarketplaceItem: function(marketplaceID, certificateID, transform) {
            if (marketplaceID === undefined) {
                return;
            }
            var marketplaceItemTransforms = scannerScript.getTransformForMarketplaceItems();
            var marketplaceItemTransform = scannerScript.getTransformsForMarketplaceItem(marketplaceID);
            if (certificateID !== undefined) {
                marketplaceItemTransform.certificateTransforms[certificateID] = transform;
            } else {
                marketplaceItemTransform.unsortedTransforms.push(transform);
            }
            marketplaceItemTransforms[marketplaceID] = marketplaceItemTransform;
            Settings.setValue(TRANSFORMS_SETTINGS, marketplaceItemTransforms);
        },

        replicaCheckedOut: function(replicaOverlayID, newEntityID) {
            if (replicaStoredTransforms[replicaOverlayID] === undefined) {
                Entities.deleteEntity(newEntityID);
                return;

            }
            var transform = replicaStoredTransforms[replicaOverlayID];
            var transformProperties = {
                parentID: MyAvatar.sessionUUID,
                parentJointIndex: MyAvatar.getJointIndex(transform.jointName),
                localPosition: transform.position,
                localRotation: transform.rotation,
                dimensions: transform.dimensions,
                velocity: {x: 0, y: 0, z: 0},
                dynamic: false
            };
            replicaStoredTransforms[replicaOverlayID] = transformProperties;

            Entities.editEntity(newEntityID, transformProperties);
        
            var makeSureInterval = Script.setInterval(function() {
                Entities.editEntity(newEntityID, transformProperties);
            }, MAKING_SURE_INTERVAL);
    
            Script.setTimeout(function() {
                makeSureInterval.stop();
            }, STOP_MAKING_SURE_TIMEOUT);
    
            var newEntityProperties = Entities.getEntityProperties(newEntityID, ['marketplaceID', 'certificateID']);
            var certificateID = undefined;
            if (newEntityProperties.certificateID !== "" && newEntityProperties.certificateID !== undefined) {
                certificateID = newEntityProperties.certificateID;

            }
            scannerScript.addTransformForMarketplaceItem(newEntityProperties.marketplaceID, certificateID, 
                transformProperties);
    
            Entities.deleteEntity(matchingEntity);
        },

        enterCheckout: function(entityID) {
            scannedMPOverlays = {};
            var newX;
            if (mini) {
                newX = 0.04;
            } else {
                newX = 0.02;
            }
            var newZ = -0.35; 
            var position1 = true;
            var position2 = false;
          
            interval = Script.setInterval(function() {
                print("scanner is searching");
                scanPosition = Entities.getEntityProperties(scanner, 'position').position;
                var overlays;
                if (mini) {
                    overlays = Overlays.findOverlays(scanPosition, SCAN_RADIUS_MINI);
                } else {
                    overlays = Overlays.findOverlays(scanPosition, SCAN_RADIUS);
                }
                if (overlays.length === 0 && overlayInScanner) {
                    if (highlightToggle) {
                        Selection.removeFromSelectedItemsList(LIST_NAME, "entity", matchingEntity);
                        Selection.removeFromSelectedItemsList(LIST_NAME, "overlay", overlayInScanner);
                        prevID = 0;
                    }

                    matchingEntity = null;
                    overlayInScanner = null;
                } else if ((overlays.length > 0) && (overlayInScanner) && 
                (overlays.toString().indexOf(overlayInScanner) === -1)) {
                    if (highlightToggle) {
                        Selection.removeFromSelectedItemsList(LIST_NAME, "entity", matchingEntity);
                        Selection.removeFromSelectedItemsList(LIST_NAME, "overlay", overlayInScanner);
                        prevID = 0;
                    }
{'fraction_non_alphanumeric': 0.08978162829337764, 'fraction_numerical': 0.008544979824353193, 'mean_word_length': 2.00035606195478, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2139173', 'n_tokens_mistral': 4685, 'n_tokens_neox': 4368, 'n_words': 773}