diff --git a/Gemfile b/Gemfile index 851fabc2..3df9dcfc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,7 @@ source 'https://rubygems.org' gemspec + +if RUBY_VERSION < "1.9.3" + # escape_utils 1.0.0 requires 1.9.3 and above + gem "escape_utils", "0.3.2" +end diff --git a/README.md b/README.md index f17de17b..80ab56c0 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,10 @@ We typically run on a pre-release version of Pygments, [pygments.rb](https://git ### Stats -The Language Graph you see on every repository is built by aggregating the languages of all repo's blobs. The top language in the graph determines the project's primary language. Collectively, these stats make up the [Top Languages](https://github.com/languages) page. +The Language Graph you see on every repository is built by aggregating the languages of each file in that repository. +The top language in the graph determines the project's primary language. Collectively, these stats make up the [Top Languages](https://github.com/languages) page. -The repository stats API can be used on a directory: +The repository stats API, accessed through `#languages`, can be used on a directory: ```ruby project = Linguist::Repository.from_directory(".") @@ -41,7 +42,7 @@ project.language.name #=> "Ruby" project.languages #=> { "Ruby" => 0.98, "Shell" => 0.02 } ``` -These stats are also printed out by the binary. Try running `linguist` on itself: +These stats are also printed out by the `linguist` binary. Try running `linguist` on itself: $ bundle exec linguist lib/ 100% Ruby @@ -82,18 +83,18 @@ To run the tests: ## Contributing -The majority of patches won't need to touch any Ruby code at all. The [master language list](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) is just a configuration file. +The majority of contributions won't need to touch any Ruby code at all. The [master language list](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) is just a YAML configuration file. We try to only add languages once they have some usage on GitHub, so please note in-the-wild usage examples in your pull request. Almost all bug fixes or new language additions should come with some additional code samples. Just drop them under [`samples/`](https://github.com/github/linguist/tree/master/samples) in the correct subdirectory and our test suite will automatically test them. In most cases you shouldn't need to add any new assertions. -To update the samples.json after adding new files to [`samples/`](https://github.com/github/linguist/tree/master/samples): +To update the `samples.json` after adding new files to [`samples/`](https://github.com/github/linguist/tree/master/samples): bundle exec rake samples ### Testing -Sometimes getting the tests running can be too much work, especially if you don't have much Ruby experience. It's okay, be lazy and let our build bot [Travis](http://travis-ci.org/#!/github/linguist) run the tests for you. Just open a pull request and the bot will start cranking away. +Sometimes getting the tests running can be too much work, especially if you don't have much Ruby experience. It's okay: be lazy and let our build bot [Travis](http://travis-ci.org/#!/github/linguist) run the tests for you. Just open a pull request and the bot will start cranking away. Here's our current build status, which is hopefully green: [![Build Status](https://secure.travis-ci.org/github/linguist.png?branch=master)](http://travis-ci.org/github/linguist) diff --git a/Rakefile b/Rakefile index 08ce419b..0b3d16a4 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,7 @@ require 'rake/clean' require 'rake/testtask' +require 'yaml' +require 'json' task :default => :test @@ -13,6 +15,13 @@ task :samples do File.open('lib/linguist/samples.json', 'w') { |io| io.write json } end +task :build_gem do + languages = YAML.load_file("lib/linguist/languages.yml") + File.write("lib/linguist/languages.json", JSON.dump(languages)) + `gem build github-linguist.gemspec` + File.delete("lib/linguist/languages.json") +end + namespace :classifier do LIMIT = 1_000 diff --git a/github-linguist.gemspec b/github-linguist.gemspec index a5213099..26bded1b 100644 --- a/github-linguist.gemspec +++ b/github-linguist.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'github-linguist' - s.version = '2.9.8' + s.version = '2.10.0' s.summary = "GitHub Language detection" s.authors = "GitHub" @@ -10,11 +10,12 @@ Gem::Specification.new do |s| s.executables << 'linguist' s.add_dependency 'charlock_holmes', '~> 0.6.6' - s.add_dependency 'escape_utils', '~> 0.3.1' + s.add_dependency 'escape_utils', '>= 0.3.1' s.add_dependency 'mime-types', '~> 1.19' - s.add_dependency 'pygments.rb', '~> 0.5.2' - s.add_development_dependency 'mocha' + s.add_dependency 'pygments.rb', '~> 0.5.4' + s.add_development_dependency 'json' + s.add_development_dependency 'mocha' s.add_development_dependency 'rake' s.add_development_dependency 'yajl-ruby' end diff --git a/lib/linguist/classifier.rb b/lib/linguist/classifier.rb index a9707b28..195087d8 100644 --- a/lib/linguist/classifier.rb +++ b/lib/linguist/classifier.rb @@ -15,8 +15,8 @@ module Linguist # # Returns nothing. # - # Set LINGUIST_DEBUG=1 or =2 to see probabilities per-token, - # per-language. See also dump_all_tokens, below. + # Set LINGUIST_DEBUG=1 or =2 to see probabilities per-token or + # per-language. See also #dump_all_tokens, below. def self.train!(db, language, data) tokens = Tokenizer.tokenize(data) @@ -151,10 +151,10 @@ module Linguist printf "%#{maxlen}s", "" puts " #" + languages.map { |lang| sprintf("%10s", lang) }.join - tokmap = Hash.new(0) - tokens.each { |tok| tokmap[tok] += 1 } + token_map = Hash.new(0) + tokens.each { |tok| token_map[tok] += 1 } - tokmap.sort.each { |tok, count| + token_map.sort.each { |tok, count| arr = languages.map { |lang| [lang, token_probability(tok, lang)] } min = arr.map { |a,b| b }.min minlog = Math.log(min) diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index ea0a40ad..0f32598f 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -75,14 +75,16 @@ module Linguist # Internal: Is the blob minified files? # - # Consider a file minified if it contains more than 5% spaces. + # Consider a file minified if the average line length is + # greater then 110c. + # # Currently, only JS and CSS files are detected by this method. # # Returns true or false. def minified_files? return unless ['.js', '.css'].include? extname - if data && data.length > 200 - (data.each_char.count{ |c| c <= ' ' } / data.length.to_f) < 0.05 + if lines.any? + (lines.inject(0) { |n, l| n += l.length } / lines.length) > 110 else false end @@ -191,8 +193,8 @@ module Linguist return false unless extname == '.h' return false unless lines.count > 2 - return lines[0].include?("/* DO NOT EDIT THIS FILE - it is machine generated */") - return lines[1].include?("#include ") + return lines[0].include?("/* DO NOT EDIT THIS FILE - it is machine generated */") && + lines[1].include?("#include ") end # node_modules/ can contain large amounts of files, in general not meant diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index 487f2724..49bbbbde 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -1,6 +1,10 @@ require 'escape_utils' require 'pygments' require 'yaml' +begin + require 'json' +rescue LoadError +end require 'linguist/classifier' require 'linguist/samples' @@ -487,7 +491,16 @@ module Linguist filenames = Samples::DATA['filenames'] popular = YAML.load_file(File.expand_path("../popular.yml", __FILE__)) - YAML.load_file(File.expand_path("../languages.yml", __FILE__)).each do |name, options| + languages_yml = File.expand_path("../languages.yml", __FILE__) + languages_json = File.expand_path("../languages.json", __FILE__) + + if File.exist?(languages_json) && defined?(JSON) + languages = JSON.load(File.read(languages_json)) + else + languages = YAML.load_file(languages_yml) + end + + languages.each do |name, options| options['extensions'] ||= [] options['interpreters'] ||= [] options['filenames'] ||= [] diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index ca3bec0c..3f8df97e 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -29,13 +29,13 @@ ABAP: type: programming lexer: ABAP primary_extension: .abap - + ANTLR: type: programming color: "#9DC3FF" lexer: ANTLR primary_extension: .g4 - + ASP: type: programming color: "#6a40fd" @@ -71,6 +71,7 @@ Ada: Agda: type: programming + color: "#467C91" primary_extension: .agda ApacheConf: @@ -123,6 +124,15 @@ AutoHotkey: - ahk primary_extension: .ahk +AutoIt: + type: programming + color: "#36699B" + aliases: + - au3 + - AutoIt3 + - AutoItScript + primary_extension: .au3 + Awk: type: programming lexer: Awk @@ -178,6 +188,11 @@ Brainfuck: extensions: - .bf +Brightscript: + type: programming + lexer: Text only + primary_extension: .brs + Bro: type: programming primary_extension: .bro @@ -378,11 +393,11 @@ D-ObjDump: type: data lexer: d-objdump primary_extension: .d-objdump - + DM: type: programming color: "#075ff1" - lexer: Text only + lexer: C++ primary_extension: .dm aliases: - byond @@ -404,6 +419,7 @@ Darcs Patch: Dart: type: programming + color: "#98BAD6" primary_extension: .dart DCPU-16 ASM: @@ -414,7 +430,7 @@ DCPU-16 ASM: - .dasm aliases: - dasm16 - + Diff: primary_extension: .diff @@ -463,7 +479,7 @@ Emacs Lisp: - elisp - emacs primary_extension: .el - filenames: + filenames: - .emacs extensions: - .emacs @@ -749,6 +765,8 @@ JSON: - .sublime_session - .sublime-settings - .sublime-workspace + filenames: + - composer.lock Jade: group: HTML @@ -946,15 +964,17 @@ Matlab: Max: type: programming color: "#ce279c" - lexer: Text only + lexer: JSON aliases: - max/msp - maxmsp search_term: max/msp - primary_extension: .mxt + primary_extension: .maxpat extensions: - .maxhelp - - .maxpat + - .maxproj + - .mxt + - .pat MiniD: # Legacy searchable: false @@ -995,6 +1015,12 @@ Nemerle: color: "#0d3c6e" primary_extension: .n +NetLogo: + type: programming + lexer: Common Lisp + color: "#ff2b2b" + primary_extension: .nlogo + Nginx: type: markup lexer: Nginx configuration file @@ -1488,6 +1514,7 @@ Tcsh: TeX: type: markup + color: "#3D6117" ace_mode: latex aliases: - latex @@ -1544,11 +1571,25 @@ Unified Parallel C: color: "#755223" primary_extension: .upc +UnrealScript: + type: programming + color: "#a54c4d" + lexer: Java + primary_extension: .uc + VHDL: type: programming lexer: vhdl color: "#543978" primary_extension: .vhdl + extensions: + - .vhd + - .vhf + - .vhi + - .vho + - .vhs + - .vht + - .vhw Vala: type: programming @@ -1620,6 +1661,7 @@ XML: - .grxml - .jelly - .kml + - .launch - .mxml - .plist - .pluginspec @@ -1629,6 +1671,7 @@ XML: - .rdf - .rss - .scxml + - .srdf - .svg - .tmCommand - .tmLanguage @@ -1637,12 +1680,14 @@ XML: - .tmTheme - .tml - .ui + - .urdf - .vxml - .wsdl - .wxi - .wxl - .wxs - .x3d + - .xacro - .xaml - .xlf - .xliff @@ -1653,6 +1698,7 @@ XML: filenames: - .classpath - .project + - phpunit.xml.dist XProc: type: programming @@ -1694,6 +1740,7 @@ YAML: primary_extension: .yml extensions: - .reek + - .rviz - .yaml eC: diff --git a/lib/linguist/samples.json b/lib/linguist/samples.json index f7b0d2e1..1c37ea3b 100644 --- a/lib/linguist/samples.json +++ b/lib/linguist/samples.json @@ -27,6 +27,9 @@ "Bluespec": [ ".bsv" ], + "Brightscript": [ + ".brs" + ], "C": [ ".c", ".h" @@ -149,9 +152,7 @@ ".script!" ], "JSON": [ - ".json", - ".maxhelp", - ".maxpat" + ".json" ], "Julia": [ ".jl" @@ -205,6 +206,8 @@ ".m" ], "Max": [ + ".maxhelp", + ".maxpat", ".mxt" ], "Monkey": [ @@ -216,6 +219,9 @@ "Nemerle": [ ".n" ], + "NetLogo": [ + ".nlogo" + ], "Nimrod": [ ".nim" ], @@ -377,6 +383,9 @@ "TypeScript": [ ".ts" ], + "UnrealScript": [ + ".uc" + ], "Verilog": [ ".v" ], @@ -471,8 +480,8 @@ ".gemrc" ] }, - "tokens_total": 420318, - "languages_total": 483, + "tokens_total": 424168, + "languages_total": 489, "tokens": { "ABAP": { "*/**": 1, @@ -2567,6 +2576,268 @@ "addRules": 1, "preempts": 1 }, + "Brightscript": { + "**": 17, + "Simple": 1, + "Grid": 2, + "Screen": 2, + "Demonstration": 1, + "App": 1, + "Copyright": 1, + "(": 32, + "c": 1, + ")": 31, + "Roku": 1, + "Inc.": 1, + "All": 3, + "Rights": 1, + "Reserved.": 1, + "************************************************************": 2, + "Sub": 2, + "Main": 1, + "set": 2, + "to": 10, + "go": 1, + "time": 1, + "get": 1, + "started": 1, + "while": 4, + "gridstyle": 7, + "<": 1, + "print": 7, + ";": 10, + "screen": 5, + "preShowGridScreen": 2, + "showGridScreen": 2, + "end": 2, + "End": 4, + "Set": 1, + "the": 17, + "configurable": 1, + "theme": 3, + "attributes": 2, + "for": 10, + "application": 1, + "Configure": 1, + "custom": 1, + "overhang": 1, + "and": 4, + "Logo": 1, + "are": 2, + "artwork": 2, + "colors": 1, + "offsets": 1, + "specific": 1, + "app": 1, + "******************************************************": 4, + "Screens": 1, + "can": 2, + "make": 1, + "slight": 1, + "adjustments": 1, + "default": 1, + "individual": 1, + "attributes.": 1, + "these": 1, + "greyscales": 1, + "theme.GridScreenBackgroundColor": 1, + "theme.GridScreenMessageColor": 1, + "theme.GridScreenRetrievingColor": 1, + "theme.GridScreenListNameColor": 1, + "used": 1, + "in": 3, + "theme.CounterTextLeft": 1, + "theme.CounterSeparator": 1, + "theme.CounterTextRight": 1, + "theme.GridScreenLogoHD": 1, + "theme.GridScreenLogoOffsetHD_X": 1, + "theme.GridScreenLogoOffsetHD_Y": 1, + "theme.GridScreenOverhangHeightHD": 1, + "theme.GridScreenLogoSD": 1, + "theme.GridScreenOverhangHeightSD": 1, + "theme.GridScreenLogoOffsetSD_X": 1, + "theme.GridScreenLogoOffsetSD_Y": 1, + "theme.GridScreenFocusBorderSD": 1, + "theme.GridScreenFocusBorderHD": 1, + "use": 1, + "your": 1, + "own": 1, + "description": 1, + "background": 1, + "theme.GridScreenDescriptionOffsetSD": 1, + "theme.GridScreenDescriptionOffsetHD": 1, + "return": 5, + "Function": 5, + "Perform": 1, + "any": 1, + "startup/initialization": 1, + "stuff": 1, + "prior": 1, + "style": 6, + "as": 2, + "string": 3, + "As": 3, + "Object": 2, + "m.port": 3, + "CreateObject": 2, + "screen.SetMessagePort": 1, + "screen.": 1, + "The": 1, + "will": 3, + "show": 1, + "retreiving": 1, + "categoryList": 4, + "getCategoryList": 1, + "[": 3, + "]": 4, + "+": 1, + "screen.setupLists": 1, + "categoryList.count": 2, + "screen.SetListNames": 1, + "StyleButtons": 3, + "getGridControlButtons": 1, + "screen.SetContentList": 2, + "i": 3, + "-": 15, + "getShowsForCategoryItem": 1, + "screen.Show": 1, + "true": 1, + "msg": 3, + "wait": 1, + "getmessageport": 1, + "does": 1, + "not": 2, + "work": 1, + "on": 1, + "gridscreen": 1, + "type": 2, + "if": 3, + "then": 3, + "msg.GetMessage": 1, + "msg.GetIndex": 3, + "msg.getData": 2, + "msg.isListItemFocused": 1, + "else": 1, + "msg.isListItemSelected": 1, + "row": 2, + "selection": 3, + "yes": 1, + "so": 2, + "we": 3, + "come": 1, + "back": 1, + "with": 2, + "new": 1, + ".Title": 1, + "endif": 1, + "**********************************************************": 1, + "this": 3, + "function": 1, + "passing": 1, + "an": 1, + "roAssociativeArray": 2, + "be": 2, + "sufficient": 1, + "springboard": 2, + "display": 2, + "add": 1, + "code": 1, + "create": 1, + "now": 1, + "do": 1, + "nothing": 1, + "Return": 1, + "list": 1, + "of": 5, + "categories": 1, + "filter": 1, + "all": 1, + "categories.": 1, + "just": 2, + "static": 1, + "data": 2, + "example.": 1, + "********************************************************************": 1, + "ContentMetaData": 1, + "objects": 1, + "shows": 1, + "category.": 1, + "For": 1, + "example": 1, + "cheat": 1, + "but": 2, + "ideally": 1, + "you": 1, + "dynamically": 1, + "content": 2, + "each": 1, + "category": 1, + "is": 1, + "dynamic": 1, + "s": 1, + "one": 3, + "small": 1, + "step": 1, + "a": 4, + "man": 1, + "giant": 1, + "leap": 1, + "mankind.": 1, + "http": 14, + "//upload.wikimedia.org/wikipedia/commons/1/1e/Apollo_11_first_step.jpg": 2, + "I": 2, + "have": 2, + "Dream": 1, + "PG": 1, + "dream": 1, + "that": 1, + "my": 1, + "four": 1, + "little": 1, + "children": 1, + "day": 1, + "live": 1, + "nation": 1, + "where": 1, + "they": 1, + "judged": 1, + "by": 2, + "color": 1, + "their": 2, + "skin": 1, + "character.": 1, + "//upload.wikimedia.org/wikipedia/commons/8/81/Martin_Luther_King_": 2, + "_March_on_Washington.jpg": 2, + "Flat": 6, + "Movie": 2, + "HD": 6, + "x2": 4, + "SD": 5, + "Netflix": 1, + "//upload.wikimedia.org/wikipedia/commons/4/43/Gold_star_on_blue.gif": 2, + "Landscape": 1, + "x3": 6, + "Channel": 1, + "Store": 1, + "//upload.wikimedia.org/wikipedia/commons/thumb/9/96/Dunkery_Hill.jpg/800px": 2, + "Dunkery_Hill.jpg": 2, + "Portrait": 1, + "x4": 1, + "posters": 3, + "//upload.wikimedia.org/wikipedia/commons/9/9f/Kane_George_Gurnett.jpg": 2, + "Square": 1, + "x1": 1, + "//upload.wikimedia.org/wikipedia/commons/thumb/d/de/SQUARE_SHAPE.svg/536px": 2, + "SQUARE_SHAPE.svg.png": 2, + "x9": 1, + "//upload.wikimedia.org/wikipedia/commons/thumb/2/22/": 2, + "%": 8, + "C3": 4, + "cran_TV_plat.svg/200px": 2, + "cran_TV_plat.svg.png": 2, + "}": 1, + "buttons": 1 + }, "C": { "#include": 150, "const": 358, @@ -22915,10 +23186,10 @@ "logger": 2 }, "JSON": { - "{": 143, - "}": 143, - "[": 165, - "]": 165, + "{": 17, + "}": 17, + "[": 2, + "]": 2, "true": 3 }, "Julia": { @@ -27193,30 +27464,30 @@ "Tender": 1 }, "Matlab": { - "function": 32, - "[": 309, + "function": 34, + "[": 311, "dx": 6, - "y": 22, - "]": 309, + "y": 25, + "]": 311, "adapting_structural_model": 2, - "(": 1357, + "(": 1379, "t": 32, - "x": 42, + "x": 46, "u": 3, "varargin": 25, - ")": 1358, - "%": 552, - "size": 8, + ")": 1380, + "%": 554, + "size": 11, "aux": 3, "{": 157, - "end": 147, + "end": 150, "}": 157, - ";": 891, + ";": 909, "m": 44, - "zeros": 60, + "zeros": 61, "b": 12, - "for": 77, - "i": 334, + "for": 78, + "i": 338, "if": 52, "+": 169, "elseif": 14, @@ -27232,7 +27503,7 @@ "*": 46, "aux.b": 3, "e": 14, - "-": 672, + "-": 673, "c2": 5, "Yc": 5, "parallel": 2, @@ -27252,7 +27523,7 @@ "n": 102, "|": 2, "&": 4, - "error": 14, + "error": 16, "sum": 2, "/length": 1, "bicycle": 7, @@ -27430,7 +27701,7 @@ "num2str": 10, "bikeData.handlingMetric.num": 1, "bikeData.handlingMetric.den": 1, - "w": 3, + "w": 6, "mag": 4, "phase": 2, "bode": 5, @@ -27510,7 +27781,7 @@ "Lateral": 1, "Deviation": 1, "paths.eps": 1, - "d": 3, + "d": 12, "like": 1, "plot.": 1, "names": 6, @@ -27606,6 +27877,23 @@ "minLine": 4, "min": 1, "speedInd": 12, + "cross_validation": 1, + "hyper_parameter": 3, + "num_data": 2, + "K": 4, + "indices": 2, + "crossvalind": 1, + "errors": 4, + "test_idx": 4, + "train_idx": 3, + "x_train": 2, + "y_train": 2, + "train": 1, + "x_test": 3, + "y_test": 3, + "calc_cost": 1, + "calc_error": 2, + "mean": 2, "value": 2, "isterminal": 2, "direction": 2, @@ -28116,6 +28404,12 @@ "command": 2, "line.": 2, "value2": 4, + "d_mean": 3, + "d_std": 3, + "normalize": 1, + "repmat": 2, + "std": 1, + "d./": 1, "overrideSettings": 3, "overrideNames": 2, "defaultNames": 2, @@ -28227,6 +28521,10 @@ "contents.colheaders": 1 }, "Max": { + "{": 126, + "}": 126, + "[": 163, + "]": 163, "max": 1, "v2": 1, ";": 39, @@ -28665,6 +28963,96 @@ "WriteLine": 1, "}": 2 }, + "NetLogo": { + "patches": 7, + "-": 28, + "own": 1, + "[": 17, + "living": 6, + ";": 12, + "indicates": 1, + "if": 2, + "the": 6, + "cell": 10, + "is": 1, + "live": 4, + "neighbors": 5, + "counts": 1, + "how": 1, + "many": 1, + "neighboring": 1, + "cells": 2, + "are": 1, + "alive": 1, + "]": 17, + "to": 6, + "setup": 2, + "blank": 1, + "clear": 2, + "all": 5, + "ask": 6, + "death": 5, + "reset": 2, + "ticks": 2, + "end": 6, + "random": 2, + "ifelse": 3, + "float": 1, + "<": 1, + "initial": 1, + "density": 1, + "birth": 4, + "set": 5, + "true": 1, + "pcolor": 2, + "fgcolor": 1, + "false": 1, + "bgcolor": 1, + "go": 1, + "count": 1, + "with": 2, + "Starting": 1, + "a": 1, + "new": 1, + "here": 1, + "ensures": 1, + "that": 1, + "finish": 1, + "executing": 2, + "first": 1, + "before": 1, + "any": 1, + "of": 2, + "them": 1, + "start": 1, + "second": 1, + "ask.": 1, + "This": 1, + "keeps": 1, + "in": 2, + "synch": 1, + "each": 2, + "other": 1, + "so": 1, + "births": 1, + "and": 1, + "deaths": 1, + "at": 1, + "generation": 1, + "happen": 1, + "lockstep.": 1, + "tick": 1, + "draw": 1, + "let": 1, + "erasing": 2, + "patch": 2, + "mouse": 5, + "xcor": 2, + "ycor": 2, + "while": 1, + "down": 1, + "display": 1 + }, "Nginx": { "user": 1, "www": 2, @@ -40508,6 +40896,431 @@ "tom.move": 1, "console.log": 1 }, + "UnrealScript": { + "//": 5, + "-": 220, + "class": 18, + "MutU2Weapons": 1, + "extends": 2, + "Mutator": 1, + "config": 18, + "(": 189, + "U2Weapons": 1, + ")": 189, + ";": 295, + "var": 30, + "string": 25, + "ReplacedWeaponClassNames0": 1, + "ReplacedWeaponClassNames1": 1, + "ReplacedWeaponClassNames2": 1, + "ReplacedWeaponClassNames3": 1, + "ReplacedWeaponClassNames4": 1, + "ReplacedWeaponClassNames5": 1, + "ReplacedWeaponClassNames6": 1, + "ReplacedWeaponClassNames7": 1, + "ReplacedWeaponClassNames8": 1, + "ReplacedWeaponClassNames9": 1, + "ReplacedWeaponClassNames10": 1, + "ReplacedWeaponClassNames11": 1, + "ReplacedWeaponClassNames12": 1, + "bool": 18, + "bConfigUseU2Weapon0": 1, + "bConfigUseU2Weapon1": 1, + "bConfigUseU2Weapon2": 1, + "bConfigUseU2Weapon3": 1, + "bConfigUseU2Weapon4": 1, + "bConfigUseU2Weapon5": 1, + "bConfigUseU2Weapon6": 1, + "bConfigUseU2Weapon7": 1, + "bConfigUseU2Weapon8": 1, + "bConfigUseU2Weapon9": 1, + "bConfigUseU2Weapon10": 1, + "bConfigUseU2Weapon11": 1, + "bConfigUseU2Weapon12": 1, + "//var": 8, + "byte": 4, + "bUseU2Weapon": 1, + "[": 125, + "]": 125, + "": 7, + "ReplacedWeaponClasses": 3, + "": 2, + "ReplacedWeaponPickupClasses": 1, + "": 3, + "ReplacedAmmoPickupClasses": 1, + "U2WeaponClasses": 2, + "//GE": 17, + "For": 3, + "default": 12, + "properties": 3, + "ONLY": 3, + "U2WeaponPickupClassNames": 1, + "U2AmmoPickupClassNames": 2, + "bIsVehicle": 4, + "bNotVehicle": 3, + "localized": 2, + "U2WeaponDisplayText": 1, + "U2WeaponDescText": 1, + "GUISelectOptions": 1, + "int": 10, + "FirePowerMode": 1, + "bExperimental": 3, + "bUseFieldGenerator": 2, + "bUseProximitySensor": 2, + "bIntegrateShieldReward": 2, + "IterationNum": 8, + "Weapons.Length": 1, + "const": 1, + "DamageMultiplier": 28, + "DamagePercentage": 3, + "bUseXMPFeel": 4, + "FlashbangModeString": 1, + "struct": 1, + "WeaponInfo": 2, + "{": 28, + "ReplacedWeaponClass": 1, + "Generated": 4, + "from": 6, + "ReplacedWeaponClassName.": 2, + "This": 3, + "is": 6, + "what": 1, + "we": 3, + "replace.": 1, + "ReplacedWeaponPickupClass": 1, + "UNUSED": 1, + "ReplacedAmmoPickupClass": 1, + "WeaponClass": 1, + "the": 31, + "weapon": 10, + "are": 1, + "going": 1, + "to": 4, + "put": 1, + "inside": 1, + "world.": 1, + "WeaponPickupClassName": 1, + "WeponClass.": 1, + "AmmoPickupClassName": 1, + "WeaponClass.": 1, + "bEnabled": 1, + "Structs": 1, + "can": 2, + "d": 1, + "thus": 1, + "still": 1, + "require": 1, + "bConfigUseU2WeaponX": 1, + "indicates": 1, + "that": 3, + "spawns": 1, + "a": 2, + "vehicle": 3, + "deployable": 1, + "turrets": 1, + ".": 2, + "These": 1, + "only": 2, + "work": 1, + "in": 4, + "gametypes": 1, + "duh.": 1, + "Opposite": 1, + "of": 1, + "works": 1, + "non": 1, + "gametypes.": 2, + "Think": 1, + "shotgun.": 1, + "}": 27, + "Weapons": 31, + "function": 5, + "PostBeginPlay": 1, + "local": 8, + "FireMode": 8, + "x": 65, + "//local": 3, + "ReplacedWeaponPickupClassName": 1, + "//IterationNum": 1, + "ArrayCount": 2, + "Level.Game.bAllowVehicles": 4, + "He": 1, + "he": 1, + "neat": 1, + "way": 1, + "get": 1, + "required": 1, + "number.": 1, + "for": 11, + "<": 9, + "+": 18, + ".bEnabled": 3, + "GetPropertyText": 5, + "needed": 1, + "use": 1, + "variables": 1, + "an": 1, + "array": 2, + "like": 1, + "fashion.": 1, + "//bUseU2Weapon": 1, + ".ReplacedWeaponClass": 5, + "DynamicLoadObject": 2, + "//ReplacedWeaponClasses": 1, + "//ReplacedWeaponPickupClassName": 1, + ".default.PickupClass": 1, + "if": 55, + ".ReplacedWeaponClass.default.FireModeClass": 4, + "None": 10, + "&&": 15, + ".default.AmmoClass": 1, + ".default.AmmoClass.default.PickupClass": 2, + ".ReplacedAmmoPickupClass": 2, + "break": 1, + ".WeaponClass": 7, + ".WeaponPickupClassName": 1, + ".WeaponClass.default.PickupClass": 1, + ".AmmoPickupClassName": 2, + ".bIsVehicle": 2, + ".bNotVehicle": 2, + "Super.PostBeginPlay": 1, + "ValidReplacement": 6, + "return": 47, + "CheckReplacement": 1, + "Actor": 1, + "Other": 23, + "out": 2, + "bSuperRelevant": 3, + "i": 12, + "WeaponLocker": 3, + "L": 2, + "xWeaponBase": 3, + ".WeaponType": 2, + "false": 3, + "true": 5, + "Weapon": 1, + "Other.IsA": 2, + "Other.Class": 2, + "Ammo": 1, + "ReplaceWith": 1, + "L.Weapons.Length": 1, + "L.Weapons": 2, + "//STARTING": 1, + "WEAPON": 1, + "xPawn": 6, + ".RequiredEquipment": 3, + "True": 2, + "Special": 1, + "handling": 1, + "Shield": 2, + "Reward": 2, + "integration": 1, + "ShieldPack": 7, + ".SetStaticMesh": 1, + "StaticMesh": 1, + ".Skins": 1, + "Shader": 2, + ".RepSkin": 1, + ".SetDrawScale": 1, + ".SetCollisionSize": 1, + ".PickupMessage": 1, + ".PickupSound": 1, + "Sound": 1, + "Super.CheckReplacement": 1, + "GetInventoryClassOverride": 1, + "InventoryClassName": 3, + "Super.GetInventoryClassOverride": 1, + "static": 2, + "FillPlayInfo": 1, + "PlayInfo": 3, + "": 1, + "Recs": 4, + "WeaponOptions": 17, + "Super.FillPlayInfo": 1, + ".static.GetWeaponList": 1, + "Recs.Length": 1, + ".ClassName": 1, + ".FriendlyName": 1, + "PlayInfo.AddSetting": 33, + "default.RulesGroup": 33, + "default.U2WeaponDisplayText": 33, + "event": 3, + "GetDescriptionText": 1, + "PropName": 35, + "default.U2WeaponDescText": 33, + "Super.GetDescriptionText": 1, + "PreBeginPlay": 1, + "float": 3, + "k": 29, + "Multiplier.": 1, + "Super.PreBeginPlay": 1, + "/100.0": 1, + "//log": 1, + "@k": 1, + "//Sets": 1, + "various": 1, + "settings": 1, + "match": 1, + "different": 1, + "games": 1, + ".default.DamagePercentage": 1, + "//Original": 1, + "U2": 3, + "compensate": 1, + "division": 1, + "errors": 1, + "Class": 105, + ".default.DamageMin": 12, + "*": 54, + ".default.DamageMax": 12, + ".default.Damage": 27, + ".default.myDamage": 4, + "//Dampened": 1, + "already": 1, + "no": 2, + "need": 1, + "rewrite": 1, + "else": 1, + "//General": 2, + "XMP": 4, + ".default.Spread": 1, + ".default.MaxAmmo": 7, + ".default.Speed": 8, + ".default.MomentumTransfer": 4, + ".default.ClipSize": 4, + ".default.FireLastReloadTime": 3, + ".default.DamageRadius": 4, + ".default.LifeSpan": 4, + ".default.ShakeRadius": 1, + ".default.ShakeMagnitude": 1, + ".default.MaxSpeed": 5, + ".default.FireRate": 3, + ".default.ReloadTime": 3, + "//3200": 1, + "too": 1, + "much": 1, + ".default.VehicleDamageScaling": 2, + "*k": 28, + "//Experimental": 1, + "options": 1, + "lets": 1, + "you": 2, + "Unuse": 1, + "EMPimp": 1, + "projectile": 1, + "and": 3, + "fire": 1, + "two": 1, + "CAR": 1, + "barrels": 1, + "//CAR": 1, + "nothing": 1, + "U2Weapons.U2AssaultRifleFire": 1, + "U2Weapons.U2AssaultRifleAltFire": 1, + "U2ProjectileConcussionGrenade": 1, + "U2Weapons.U2AssaultRifleInv": 1, + "U2Weapons.U2WeaponEnergyRifle": 1, + "U2Weapons.U2WeaponFlameThrower": 1, + "U2Weapons.U2WeaponPistol": 1, + "U2Weapons.U2AutoTurretDeploy": 1, + "U2Weapons.U2WeaponRocketLauncher": 1, + "U2Weapons.U2WeaponGrenadeLauncher": 1, + "U2Weapons.U2WeaponSniper": 2, + "U2Weapons.U2WeaponRocketTurret": 1, + "U2Weapons.U2WeaponLandMine": 1, + "U2Weapons.U2WeaponLaserTripMine": 1, + "U2Weapons.U2WeaponShotgun": 1, + "s": 7, + "Minigun.": 1, + "Enable": 5, + "Shock": 1, + "Lance": 1, + "Energy": 2, + "Rifle": 3, + "What": 7, + "should": 7, + "be": 8, + "replaced": 8, + "with": 9, + "Rifle.": 3, + "By": 7, + "it": 7, + "Bio": 1, + "Magnum": 2, + "Pistol": 1, + "Pistol.": 1, + "Onslaught": 1, + "Grenade": 1, + "Launcher.": 2, + "Shark": 2, + "Rocket": 4, + "Launcher": 1, + "Flak": 1, + "Cannon.": 1, + "Should": 1, + "Lightning": 1, + "Gun": 2, + "Widowmaker": 2, + "Sniper": 3, + "Classic": 1, + "here.": 1, + "Turret": 2, + "delpoyable": 1, + "deployable.": 1, + "Redeemer.": 1, + "Laser": 2, + "Trip": 2, + "Mine": 1, + "Mine.": 1, + "t": 2, + "replace": 1, + "Link": 1, + "matches": 1, + "vehicles.": 1, + "Crowd": 1, + "Pleaser": 1, + "Shotgun.": 1, + "have": 1, + "shields": 1, + "or": 2, + "damage": 1, + "filtering.": 1, + "If": 1, + "checked": 1, + "mutator": 1, + "produces": 1, + "Unreal": 4, + "II": 4, + "shield": 1, + "pickups.": 1, + "Choose": 1, + "between": 2, + "white": 1, + "overlay": 3, + "depending": 2, + "on": 2, + "player": 2, + "view": 1, + "style": 1, + "distance": 1, + "foolproof": 1, + "FM_DistanceBased": 1, + "Arena": 1, + "Add": 1, + "weapons": 1, + "other": 1, + "Fully": 1, + "customisable": 1, + "choose": 1, + "behaviour.": 1, + "US3HelloWorld": 1, + "GameInfo": 1, + "InitGame": 1, + "Options": 1, + "Error": 1, + "log": 1, + "defaultproperties": 1 + }, "Verilog": { "////////////////////////////////////////////////////////////////////////////////": 14, "//": 117, @@ -42825,6 +43638,7 @@ "Awk": 544, "BlitzBasic": 2065, "Bluespec": 1298, + "Brightscript": 579, "C": 58858, "C++": 21308, "Ceylon": 50, @@ -42858,7 +43672,7 @@ "Jade": 3, "Java": 8987, "JavaScript": 76934, - "JSON": 619, + "JSON": 41, "Julia": 247, "Kotlin": 155, "KRL": 25, @@ -42874,11 +43688,12 @@ "M": 23373, "Makefile": 50, "Markdown": 1, - "Matlab": 11787, - "Max": 136, + "Matlab": 11942, + "Max": 714, "Monkey": 207, "MoonScript": 1718, "Nemerle": 17, + "NetLogo": 243, "Nginx": 179, "Nimrod": 1, "NSIS": 725, @@ -42924,6 +43739,7 @@ "Turing": 44, "TXL": 213, "TypeScript": 109, + "UnrealScript": 2873, "Verilog": 3778, "VHDL": 42, "VimL": 20, @@ -42949,6 +43765,7 @@ "Awk": 1, "BlitzBasic": 3, "Bluespec": 2, + "Brightscript": 1, "C": 26, "C++": 19, "Ceylon": 1, @@ -42982,7 +43799,7 @@ "Jade": 1, "Java": 6, "JavaScript": 20, - "JSON": 5, + "JSON": 3, "Julia": 1, "Kotlin": 1, "KRL": 1, @@ -42998,11 +43815,12 @@ "M": 28, "Makefile": 2, "Markdown": 1, - "Matlab": 37, - "Max": 1, + "Matlab": 39, + "Max": 3, "Monkey": 1, "MoonScript": 1, "Nemerle": 1, + "NetLogo": 1, "Nginx": 1, "Nimrod": 1, "NSIS": 2, @@ -43048,6 +43866,7 @@ "Turing": 1, "TXL": 1, "TypeScript": 3, + "UnrealScript": 2, "Verilog": 13, "VHDL": 1, "VimL": 2, @@ -43062,5 +43881,5 @@ "Xtend": 2, "YAML": 1 }, - "md5": "f407022fe8de91114d556ad933c9acc2" + "md5": "647da23cd1eb02653f50ff9bfbb6e70d" } \ No newline at end of file diff --git a/lib/linguist/samples.rb b/lib/linguist/samples.rb index 27ba218e..a2e5ec21 100644 --- a/lib/linguist/samples.rb +++ b/lib/linguist/samples.rb @@ -1,4 +1,8 @@ -require 'yaml' +begin + require 'json' +rescue LoadError + require 'yaml' +end require 'linguist/md5' require 'linguist/classifier' @@ -14,7 +18,8 @@ module Linguist # Hash of serialized samples object if File.exist?(PATH) - DATA = YAML.load_file(PATH) + serializer = defined?(JSON) ? JSON : YAML + DATA = serializer.load(File.read(PATH)) end # Public: Iterate over each sample. diff --git a/lib/linguist/vendor.yml b/lib/linguist/vendor.yml index 1e106812..2bc71b72 100644 --- a/lib/linguist/vendor.yml +++ b/lib/linguist/vendor.yml @@ -139,7 +139,7 @@ # LICENSE, README, git config files - ^COPYING$ -- ^LICENSE$ +- LICENSE$ - gitattributes$ - gitignore$ - gitmodules$ diff --git a/samples/Brightscript/SimpleGrid.brs b/samples/Brightscript/SimpleGrid.brs new file mode 100644 index 00000000..b205d69a --- /dev/null +++ b/samples/Brightscript/SimpleGrid.brs @@ -0,0 +1,305 @@ +' ********************************************************* +' ** Simple Grid Screen Demonstration App +' ** Jun 2010 +' ** Copyright (c) 2010 Roku Inc. All Rights Reserved. +' ********************************************************* + +'************************************************************ +'** Application startup +'************************************************************ +Sub Main() + + 'initialize theme attributes like titles, logos and overhang color + initTheme() + + gridstyle = "Flat-Movie" + + 'set to go, time to get started + while gridstyle <> "" + print "starting grid style= ";gridstyle + screen=preShowGridScreen(gridstyle) + gridstyle = showGridScreen(screen, gridstyle) + end while + +End Sub + + +'************************************************************* +'** Set the configurable theme attributes for the application +'** +'** Configure the custom overhang and Logo attributes +'** These attributes affect the branding of the application +'** and are artwork, colors and offsets specific to the app +'************************************************************* + +Sub initTheme() + app = CreateObject("roAppManager") + app.SetTheme(CreateDefaultTheme()) +End Sub + +'****************************************************** +'** @return The default application theme. +'** Screens can make slight adjustments to the default +'** theme by getting it from here and then overriding +'** individual theme attributes. +'****************************************************** +Function CreateDefaultTheme() as Object + theme = CreateObject("roAssociativeArray") + + theme.ThemeType = "generic-dark" + + ' All these are greyscales + theme.GridScreenBackgroundColor = "#363636" + theme.GridScreenMessageColor = "#808080" + theme.GridScreenRetrievingColor = "#CCCCCC" + theme.GridScreenListNameColor = "#FFFFFF" + + ' Color values work here + theme.GridScreenDescriptionTitleColor = "#001090" + theme.GridScreenDescriptionDateColor = "#FF005B" + theme.GridScreenDescriptionRuntimeColor = "#5B005B" + theme.GridScreenDescriptionSynopsisColor = "#606000" + + 'used in the Grid Screen + theme.CounterTextLeft = "#FF0000" + theme.CounterSeparator = "#00FF00" + theme.CounterTextRight = "#0000FF" + + theme.GridScreenLogoHD = "pkg:/images/Overhang_Test_HD.png" + + theme.GridScreenLogoOffsetHD_X = "0" + theme.GridScreenLogoOffsetHD_Y = "0" + theme.GridScreenOverhangHeightHD = "99" + + theme.GridScreenLogoSD = "pkg:/images/Overhang_Test_SD43.png" + theme.GridScreenOverhangHeightSD = "66" + theme.GridScreenLogoOffsetSD_X = "0" + theme.GridScreenLogoOffsetSD_Y = "0" + + ' to use your own focus ring artwork + 'theme.GridScreenFocusBorderSD = "pkg:/images/GridCenter_Border_Movies_SD43.png" + 'theme.GridScreenBorderOffsetSD = "(-26,-25)" + 'theme.GridScreenFocusBorderHD = "pkg:/images/GridCenter_Border_Movies_HD.png" + 'theme.GridScreenBorderOffsetHD = "(-28,-20)" + + ' to use your own description background artwork + 'theme.GridScreenDescriptionImageSD = "pkg:/images/Grid_Description_Background_SD43.png" + 'theme.GridScreenDescriptionOffsetSD = "(125,170)" + 'theme.GridScreenDescriptionImageHD = "pkg:/images/Grid_Description_Background_HD.png" + 'theme.GridScreenDescriptionOffsetHD = "(190,255)" + + + return theme +End Function + +'****************************************************** +'** Perform any startup/initialization stuff prior to +'** initially showing the screen. +'****************************************************** +Function preShowGridScreen(style as string) As Object + + m.port=CreateObject("roMessagePort") + screen = CreateObject("roGridScreen") + screen.SetMessagePort(m.port) +' screen.SetDisplayMode("best-fit") + screen.SetDisplayMode("scale-to-fill") + + screen.SetGridStyle(style) + return screen + +End Function + + +'****************************************************** +'** Display the gird screen and wait for events from +'** the screen. The screen will show retreiving while +'** we fetch and parse the feeds for the show posters +'****************************************************** +Function showGridScreen(screen As Object, gridstyle as string) As string + + print "enter showGridScreen" + + categoryList = getCategoryList() + categoryList[0] = "GridStyle: " + gridstyle + screen.setupLists(categoryList.count()) + screen.SetListNames(categoryList) + StyleButtons = getGridControlButtons() + screen.SetContentList(0, StyleButtons) + for i = 1 to categoryList.count()-1 + screen.SetContentList(i, getShowsForCategoryItem(categoryList[i])) + end for + screen.Show() + + while true + print "Waiting for message" + msg = wait(0, m.port) + 'msg = wait(0, screen.GetMessagePort()) ' getmessageport does not work on gridscreen + print "Got Message:";type(msg) + if type(msg) = "roGridScreenEvent" then + print "msg= "; msg.GetMessage() " , index= "; msg.GetIndex(); " data= "; msg.getData() + if msg.isListItemFocused() then + print"list item focused | current show = "; msg.GetIndex() + else if msg.isListItemSelected() then + row = msg.GetIndex() + selection = msg.getData() + print "list item selected row= "; row; " selection= "; selection + + ' Did we get a selection from the gridstyle selection row? + if (row = 0) + ' yes, return so we can come back with new style + return StyleButtons[selection].Title + endif + + 'm.curShow = displayShowDetailScreen(showList[msg.GetIndex()]) + else if msg.isScreenClosed() then + return "" + end if + end If + end while + + +End Function + +'********************************************************** +'** When a poster on the home screen is selected, we call +'** this function passing an roAssociativeArray with the +'** ContentMetaData for the selected show. This data should +'** be sufficient for the springboard to display +'********************************************************** +Function displayShowDetailScreen(category as Object, showIndex as Integer) As Integer + + 'add code to create springboard, for now we do nothing + return 1 + +End Function + + +'************************************************************** +'** Return the list of categories to display in the filter +'** banner. The result is an roArray containing the names of +'** all of the categories. All just static data for the example. +'*************************************************************** +Function getCategoryList() As Object + + categoryList = [ "GridStyle", "Reality", "History", "News", "Comedy", "Drama"] + return categoryList + +End Function + + +'******************************************************************** +'** Given the category from the filter banner, return an array +'** of ContentMetaData objects (roAssociativeArray's) representing +'** the shows for the category. For this example, we just cheat and +'** create and return a static array with just the minimal items +'** set, but ideally, you'd go to a feed service, fetch and parse +'** this data dynamically, so content for each category is dynamic +'******************************************************************** +Function getShowsForCategoryItem(category As Object) As Object + + print "getting shows for category "; category + + showList = [ + { + Title: category + ": Header", + releaseDate: "1976", + length: 3600-600, + Description:"This row is category " + category, + hdBranded: true, + HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/4/43/Gold_star_on_blue.gif", + SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/4/43/Gold_star_on_blue.gif", + Description:"Short Synopsis #1", + Synopsis:"Length", + StarRating:10, + } + { + Title: category + ": Beverly Hillbillies", + releaseDate: "1969", + rating: "PG", + Description:"Come and listen to a story about a man named Jed: Poor mountaineer, barely kept his family fed. Then one day he was shootin at some food, and up through the ground came a bubblin crude. Oil that is, black gold, Texas tea.", + numEpisodes:42, + contentType:"season", + HDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/4/4e/The_Beverly_Hillbillies.jpg", + SDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/4/4e/The_Beverly_Hillbillies.jpg", + StarRating:80, + UserStarRating:40 + } + { + Title: category + ": Babylon 5", + releaseDate: "1996", + rating: "PG", + Description:"The show centers on the Babylon 5 space station: a focal point for politics, diplomacy, and conflict during the years 2257-2262.", + numEpisodes:102, + contentType:"season", + HDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/9/9d/Smb5-s4.jpg", + SDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/9/9d/Smb5-s4.jpg", + StarRating:80, + UserStarRating:40 + } + { + Title: category + ": John F. Kennedy", + releaseDate: "1961", + rating: "PG", + Description:"My fellow citizens of the world: ask not what America will do for you, but what together we can do for the freedom of man.", + HDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/5/52/Jfk_happy_birthday_1.jpg", + SDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/5/52/Jfk_happy_birthday_1.jpg", + StarRating:100 + } + { + Title: category + ": Man on the Moon", + releaseDate: "1969", + rating: "PG", + Description:"That's one small step for a man, one giant leap for mankind.", + HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/1/1e/Apollo_11_first_step.jpg", + SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/1/1e/Apollo_11_first_step.jpg", + StarRating:100 + } + { + Title: category + ": I have a Dream", + releaseDate: "1963", + rating: "PG", + Description:"I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their skin, but by the content of their character.", + HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/8/81/Martin_Luther_King_-_March_on_Washington.jpg", + SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/8/81/Martin_Luther_King_-_March_on_Washington.jpg", + StarRating:100 + } + ] + + return showList +End Function + +function getGridControlButtons() as object + buttons = [ + { Title: "Flat-Movie" + ReleaseDate: "HD:5x2 SD:5x2" + Description: "Flat-Movie (Netflix) style" + HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/4/43/Gold_star_on_blue.gif" + SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/4/43/Gold_star_on_blue.gif" + } + { Title: "Flat-Landscape" + ReleaseDate: "HD:5x3 SD:4x3" + Description: "Channel Store" + HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Dunkery_Hill.jpg/800px-Dunkery_Hill.jpg", + SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Dunkery_Hill.jpg/800px-Dunkery_Hill.jpg", + } + { Title: "Flat-Portrait" + ReleaseDate: "HD:5x2 SD:5x2" + Description: "3x4 style posters" + HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/9/9f/Kane_George_Gurnett.jpg", + SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/9/9f/Kane_George_Gurnett.jpg", + } + { Title: "Flat-Square" + ReleaseDate: "HD:7x3 SD:6x3" + Description: "1x1 style posters" + HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/d/de/SQUARE_SHAPE.svg/536px-SQUARE_SHAPE.svg.png", + SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/d/de/SQUARE_SHAPE.svg/536px-SQUARE_SHAPE.svg.png", + } + { Title: "Flat-16x9" + ReleaseDate: "HD:5x3 SD:4x3" + Description: "HD style posters" + HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/2/22/%C3%89cran_TV_plat.svg/200px-%C3%89cran_TV_plat.svg.png", + SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/2/22/%C3%89cran_TV_plat.svg/200px-%C3%89cran_TV_plat.svg.png", + } + ] + return buttons +End Function diff --git a/samples/Matlab/cross_validation.m b/samples/Matlab/cross_validation.m new file mode 100644 index 00000000..034182e5 --- /dev/null +++ b/samples/Matlab/cross_validation.m @@ -0,0 +1,31 @@ +function [ error ] = cross_validation(x,y,hyper_parameter) + + num_data = size(x,1); + + K = 10; + indices = crossvalind('Kfold', num_data, K); + + errors = zeros(K,1); + for i = 1:K + % get indices + test_idx = (indices == i); + train_idx = ~test_idx; + + % get training data + x_train = x(train_idx,:); + y_train = y(train_idx,:); + + % train + w = train(x_train, y_train, hyper_parameter); + + % get test data + x_test = x(test_idx,:); + y_test = y(test_idx,:); + + % calculate error + errors(i) = calc_cost(x_test, y_test, w, hyper_parameter); %calc_error + %errors(i) = calc_error(x_test, y_test, w); + end + + error = mean(errors); +end diff --git a/samples/Matlab/normalize.m b/samples/Matlab/normalize.m new file mode 100644 index 00000000..f4f33493 --- /dev/null +++ b/samples/Matlab/normalize.m @@ -0,0 +1,6 @@ +function [ d, d_mean, d_std ] = normalize( d ) + d_mean = mean(d); + d = d - repmat(d_mean, size(d,1), 1); + d_std = std(d); + d = d./ repmat(d_std, size(d,1), 1); +end diff --git a/samples/JSON/Hello.maxhelp b/samples/Max/Hello.maxhelp similarity index 100% rename from samples/JSON/Hello.maxhelp rename to samples/Max/Hello.maxhelp diff --git a/samples/JSON/Hello.maxpat b/samples/Max/Hello.maxpat similarity index 100% rename from samples/JSON/Hello.maxpat rename to samples/Max/Hello.maxpat diff --git a/samples/NetLogo/Life.nlogo b/samples/NetLogo/Life.nlogo new file mode 100644 index 00000000..cb28c1a3 --- /dev/null +++ b/samples/NetLogo/Life.nlogo @@ -0,0 +1,55 @@ +patches-own [ + living? ;; indicates if the cell is living + live-neighbors ;; counts how many neighboring cells are alive +] + +to setup-blank + clear-all + ask patches [ cell-death ] + reset-ticks +end + +to setup-random + clear-all + ask patches + [ ifelse random-float 100.0 < initial-density + [ cell-birth ] + [ cell-death ] ] + reset-ticks +end + +to cell-birth + set living? true + set pcolor fgcolor +end + +to cell-death + set living? false + set pcolor bgcolor +end + +to go + ask patches + [ set live-neighbors count neighbors with [living?] ] + ;; Starting a new "ask patches" here ensures that all the patches + ;; finish executing the first ask before any of them start executing + ;; the second ask. This keeps all the patches in synch with each other, + ;; so the births and deaths at each generation all happen in lockstep. + ask patches + [ ifelse live-neighbors = 3 + [ cell-birth ] + [ if live-neighbors != 2 + [ cell-death ] ] ] + tick +end + +to draw-cells + let erasing? [living?] of patch mouse-xcor mouse-ycor + while [mouse-down?] + [ ask patch mouse-xcor mouse-ycor + [ ifelse erasing? + [ cell-death ] + [ cell-birth ] ] + display ] +end + diff --git a/samples/UnrealScript/MutU2Weapons.uc b/samples/UnrealScript/MutU2Weapons.uc new file mode 100755 index 00000000..9c27aaf9 --- /dev/null +++ b/samples/UnrealScript/MutU2Weapons.uc @@ -0,0 +1,644 @@ +/* + * Copyright (c) 2008, 2013 Dainius "GreatEmerald" Masiliƫnas + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +//----------------------------------------------------------------------------- +// MutU2Weapons.uc +// Mutator class for replacing weapons +// GreatEmerald, 2008 +//----------------------------------------------------------------------------- + +class MutU2Weapons extends Mutator + config(U2Weapons); + +var() config string ReplacedWeaponClassNames0; +var() config string ReplacedWeaponClassNames1, ReplacedWeaponClassNames2, ReplacedWeaponClassNames3; +var() config string ReplacedWeaponClassNames4, ReplacedWeaponClassNames5, ReplacedWeaponClassNames6; +var() config string ReplacedWeaponClassNames7, ReplacedWeaponClassNames8, ReplacedWeaponClassNames9; +var() config string ReplacedWeaponClassNames10, ReplacedWeaponClassNames11, ReplacedWeaponClassNames12; +var() config bool bConfigUseU2Weapon0, bConfigUseU2Weapon1, bConfigUseU2Weapon2, bConfigUseU2Weapon3; +var() config bool bConfigUseU2Weapon4, bConfigUseU2Weapon5, bConfigUseU2Weapon6, bConfigUseU2Weapon7; +var() config bool bConfigUseU2Weapon8, bConfigUseU2Weapon9, bConfigUseU2Weapon10, bConfigUseU2Weapon11; +var() config bool bConfigUseU2Weapon12; +//var byte bUseU2Weapon[13]; +//var class ReplacedWeaponClasses[13]; +//var class ReplacedWeaponPickupClasses[13]; +//var class ReplacedAmmoPickupClasses[13]; +var class U2WeaponClasses[13]; //GE: For default properties ONLY! +//var string U2WeaponPickupClassNames[13]; +var string U2AmmoPickupClassNames[13]; //GE: For default properties ONLY! +var byte bIsVehicle[13], bNotVehicle[13]; //GE: For default properties ONLY! +var localized string U2WeaponDisplayText[33], U2WeaponDescText[33]; +//var localized string GUISelectOptions[4]; +//var config int FirePowerMode; +var config bool bExperimental; +var config bool bUseFieldGenerator; +var config bool bUseProximitySensor; +var config bool bIntegrateShieldReward; +var int IterationNum; //GE: Weapons.Length +const DamageMultiplier=1.818182; +var config int DamagePercentage; +var config bool bUseXMPFeel; +var config string FlashbangModeString; +struct WeaponInfo +{ + var class ReplacedWeaponClass; //GE: Generated from ReplacedWeaponClassName. This is what we replace. + //var class ReplacedWeaponPickupClass; //GE: UNUSED?! + var class ReplacedAmmoPickupClass; //GE: Generated from ReplacedWeaponClassName. + + var class WeaponClass; //GE: This is the weapon we are going to put inside the world. + var string WeaponPickupClassName; //GE: Generated from WeponClass. + var string AmmoPickupClassName; //GE: Generated from WeaponClass. + var bool bEnabled; //GE: Structs can't be defaultproperty'd, thus we still require bConfigUseU2WeaponX + var bool bIsVehicle; //GE: This indicates that the weapon spawns a vehicle (deployable turrets). These only work in vehicle gametypes, duh. + var bool bNotVehicle; //GE: Opposite of bIsVehicle, that is, only works in non-vehicle gametypes. Think shotgun. +}; +var WeaponInfo Weapons[13]; + +/* + * GE: Here we initialise the mutator. First of all, structs can't use defaultproperties (until UE3) and thus config, so here we need to initialise the structs. + */ +function PostBeginPlay() +{ + local int FireMode, x; + //local string ReplacedWeaponPickupClassName; + + //IterationNum = ArrayCount(ReplacedWeaponClasses) - int(Level.Game.bAllowVehicles); //GE: He he, neat way to get the required number. + IterationNum = ArrayCount(Weapons); + + for (x = 0; x < IterationNum; x++) + { + Weapons[x].bEnabled = bool(GetPropertyText("bConfigUseU2Weapon"$x)); //GE: GetPropertyText() is needed to use variables in an array-like fashion. + //bUseU2Weapon[x] = byte(bool(GetPropertyText("bConfigUseU2Weapon"$x))); + Weapons[x].ReplacedWeaponClass = class(DynamicLoadObject(GetPropertyText("ReplacedWeaponClassNames"$x),class'Class')); + //ReplacedWeaponClasses[x] = class(DynamicLoadObject(GetPropertyText("ReplacedWeaponClassNames"$x),class'Class')); + //ReplacedWeaponPickupClassName = string(ReplacedWeaponClasses[x].default.PickupClass); + for(FireMode = 0; FireMode<2; FireMode++) + { + if( (Weapons[x].ReplacedWeaponClass.default.FireModeClass[FireMode] != None) + && (Weapons[x].ReplacedWeaponClass.default.FireModeClass[FireMode].default.AmmoClass != None) + && (Weapons[x].ReplacedWeaponClass.default.FireModeClass[FireMode].default.AmmoClass.default.PickupClass != None) ) + { + Weapons[x].ReplacedAmmoPickupClass = class(Weapons[x].ReplacedWeaponClass.default.FireModeClass[FireMode].default.AmmoClass.default.PickupClass); + break; + } + } + Weapons[x].WeaponClass = U2WeaponClasses[x]; + Weapons[x].WeaponPickupClassName = string(Weapons[x].WeaponClass.default.PickupClass); + Weapons[x].AmmoPickupClassName = U2AmmoPickupClassNames[x]; + Weapons[x].bIsVehicle = bool(bIsVehicle[x]); + Weapons[x].bNotVehicle = bool(bNotVehicle[x]); + } + Super.PostBeginPlay(); +} + +/* + * GE: Utility function for checking if we can replace the item with the weapon/ammo of choice. + */ +function bool ValidReplacement(int x) +{ + if (Level.Game.bAllowVehicles) + return (Weapons[x].bEnabled && !Weapons[x].bNotVehicle ); + return (Weapons[x].bEnabled && !Weapons[x].bIsVehicle); +} + +/* + * GE: Here we replace things. + */ +function bool CheckReplacement( Actor Other, out byte bSuperRelevant ) +{ + local int x, i; + local WeaponLocker L; + + bSuperRelevant = 0; + if (xWeaponBase(Other) != None) + { + for (x = 0; x < IterationNum; x++) + { + if (ValidReplacement(x) && xWeaponBase(Other).WeaponType == Weapons[x].ReplacedWeaponClass) + { + xWeaponBase(Other).WeaponType = Weapons[x].WeaponClass; + return false; + } + } + return true; + } + if (Weapon(Other) != None) + { + if ( Other.IsA('BallLauncher') ) + return true; + for (x = 0; x < IterationNum; x++) + if (ValidReplacement(x) && Other.Class == Weapons[x].ReplacedWeaponClass) + return false; + return true; + } + /*if (WeaponPickup(Other) != None) //GE: This should never happen. + { + for (x = 0; x < IterationNum; x++) + { + if (Weapons[x].bEnabled && Other.Class == Weapons[x].ReplacedWeaponPickupClass) + { + ReplaceWith(Other, U2WeaponPickupClassNames[x]); + return false; + } + } + } */ + if (Ammo(Other) != None) + { + for (x = 0; x < IterationNum; x++) + { + if (ValidReplacement(x) && Other.Class == Weapons[x].ReplacedAmmoPickupClass) + { + ReplaceWith(Other, Weapons[x].AmmoPickupClassName); + return false; + } + } + return true; + } + if (WeaponLocker(Other) != None) + { + L = WeaponLocker(Other); + for (x = 0; x < IterationNum; x++) + if (ValidReplacement(x)) + for (i = 0; i < L.Weapons.Length; i++) + if (L.Weapons[i].WeaponClass == Weapons[x].ReplacedWeaponClass) + L.Weapons[i].WeaponClass = Weapons[x].WeaponClass; + return true; + } + + //STARTING WEAPON + if( xPawn(Other) != None ) + xPawn(Other).RequiredEquipment[0] = string(Weapons[1].WeaponClass); + if( xPawn(Other) != None && bUseFieldGenerator == True && Level.Game.bAllowVehicles) + xPawn(Other).RequiredEquipment[2] = "U2Weapons.U2WeaponFieldGenerator"; + if( xPawn(Other) != None && bUseProximitySensor == True && Level.Game.bAllowVehicles) + xPawn(Other).RequiredEquipment[3] = "U2Weapons.U2ProximitySensorDeploy"; + + //GE: Special handling - Shield Reward integration + if (bIntegrateShieldReward && Other.IsA('ShieldReward')) + { + ShieldPack(Other).SetStaticMesh(StaticMesh'XMPWorldItemsM.items.Pickup_TD_001'); + ShieldPack(Other).Skins[0] = Shader'U2343T.Pickups.Energy_Pickup_B_FX_01'; + ShieldPack(Other).RepSkin = Shader'U2343T.Pickups.Energy_Pickup_B_FX_01'; + ShieldPack(Other).SetDrawScale(0.35); + ShieldPack(Other).SetCollisionSize(27.0, 4.0); + ShieldPack(Other).PickupMessage = "You got an Energy Pickup."; + ShieldPack(Other).PickupSound = Sound'U2A.Powerups.EnergyPowerUp'; + } + + return Super.CheckReplacement(Other,bSuperRelevant); +} + +/* + * GE: This is for further replacement, I think... + */ +function string GetInventoryClassOverride(string InventoryClassName) +{ + local int x; + + for (x = 0; x < IterationNum; x++) + { + if (InventoryClassName ~= string(Weapons[x].ReplacedWeaponClass) && ValidReplacement(x)) + return string(Weapons[x].WeaponClass); + } + + return Super.GetInventoryClassOverride(InventoryClassName); +} + +/* + * GE: Configuration options. + */ +static function FillPlayInfo(PlayInfo PlayInfo) +{ + local array Recs; + local string WeaponOptions; + local int i; + + Super.FillPlayInfo(PlayInfo); + + class'CacheManager'.static.GetWeaponList(Recs); + for (i = 0; i < Recs.Length; i++) + { + if (WeaponOptions != "") + WeaponOptions $= ";"; + + WeaponOptions $= Recs[i].ClassName $ ";" $ Recs[i].FriendlyName; + } + + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon0", default.U2WeaponDisplayText[0], 0, 3, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames0", default.U2WeaponDisplayText[1], 0, 4, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon1", default.U2WeaponDisplayText[2], 0, 5, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames1", default.U2WeaponDisplayText[3], 0, 6, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon2", default.U2WeaponDisplayText[6], 0, 7, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames2", default.U2WeaponDisplayText[7], 0, 8, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon3", default.U2WeaponDisplayText[8], 0, 9, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames3", default.U2WeaponDisplayText[9], 0, 10, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon4", default.U2WeaponDisplayText[10], 0, 11, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames4", default.U2WeaponDisplayText[11], 0, 12, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon5", default.U2WeaponDisplayText[12], 0, 13, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames5", default.U2WeaponDisplayText[13], 0, 14, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon6", default.U2WeaponDisplayText[14], 0, 15, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames6", default.U2WeaponDisplayText[15], 0, 16, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon7", default.U2WeaponDisplayText[16], 0, 17, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames7", default.U2WeaponDisplayText[17], 0, 18, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon8", default.U2WeaponDisplayText[18], 0, 19, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames8", default.U2WeaponDisplayText[19], 0, 20, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon9", default.U2WeaponDisplayText[20], 0, 21, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames9", default.U2WeaponDisplayText[21], 0, 22, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon10", default.U2WeaponDisplayText[22], 0, 23, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames10", default.U2WeaponDisplayText[23], 0, 24, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon11", default.U2WeaponDisplayText[24], 0, 25, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames11", default.U2WeaponDisplayText[25], 0, 26, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bConfigUseU2Weapon12", default.U2WeaponDisplayText[26], 0, 27, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "ReplacedWeaponClassNames12", default.U2WeaponDisplayText[27], 0, 28, "Select", WeaponOptions); + PlayInfo.AddSetting(default.RulesGroup, "bUseXMPFeel", default.U2WeaponDisplayText[4], 0, 29, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "DamagePercentage", default.U2WeaponDisplayText[30], 0, 30, "Text", "3;0:100"); + PlayInfo.AddSetting(default.RulesGroup, "bExperimental", default.U2WeaponDisplayText[5], 0, 31, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "bUseFieldGenerator", default.U2WeaponDisplayText[28], 0, 32, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "bUseProximitySensor", default.U2WeaponDisplayText[29], 0, 33, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "bIntegrateShieldReward", default.U2WeaponDisplayText[31], 0, 34, "Check"); + PlayInfo.AddSetting(default.RulesGroup, "FlashbangModeString", default.U2WeaponDisplayText[32], 0, 35, "Select", "FM_None;None;FM_Directional;Direction-based;FM_DistanceBased;Distance-based"); +} + +/* + * GE: Configuration tooltips. + */ +static event string GetDescriptionText(string PropName) +{ + if (PropName == "bConfigUseU2Weapon0") + return default.U2WeaponDescText[0]; + if (PropName == "ReplacedWeaponClassNames0") + return default.U2WeaponDescText[1]; + if (PropName == "bConfigUseU2Weapon1") + return default.U2WeaponDescText[2]; + if (PropName == "ReplacedWeaponClassNames1") + return default.U2WeaponDescText[3]; + if (PropName == "bConfigUseU2Weapon2") + return default.U2WeaponDescText[6]; + if (PropName == "ReplacedWeaponClassNames2") + return default.U2WeaponDescText[7]; + if (PropName == "bConfigUseU2Weapon3") + return default.U2WeaponDescText[8]; + if (PropName == "ReplacedWeaponClassNames3") + return default.U2WeaponDescText[9]; + if (PropName == "bConfigUseU2Weapon4") + return default.U2WeaponDescText[10]; + if (PropName == "ReplacedWeaponClassNames4") + return default.U2WeaponDescText[11]; + if (PropName == "bConfigUseU2Weapon5") + return default.U2WeaponDescText[12]; + if (PropName == "ReplacedWeaponClassNames5") + return default.U2WeaponDescText[13]; + if (PropName == "bConfigUseU2Weapon6") + return default.U2WeaponDescText[14]; + if (PropName == "ReplacedWeaponClassNames6") + return default.U2WeaponDescText[15]; + if (PropName == "bConfigUseU2Weapon7") + return default.U2WeaponDescText[16]; + if (PropName == "ReplacedWeaponClassNames7") + return default.U2WeaponDescText[17]; + if (PropName == "bConfigUseU2Weapon8") + return default.U2WeaponDescText[18]; + if (PropName == "ReplacedWeaponClassNames8") + return default.U2WeaponDescText[19]; + if (PropName == "bConfigUseU2Weapon9") + return default.U2WeaponDescText[20]; + if (PropName == "ReplacedWeaponClassNames9") + return default.U2WeaponDescText[21]; + if (PropName == "bConfigUseU2Weapon10") + return default.U2WeaponDescText[22]; + if (PropName == "ReplacedWeaponClassNames10") + return default.U2WeaponDescText[23]; + if (PropName == "bConfigUseU2Weapon11") + return default.U2WeaponDescText[24]; + if (PropName == "ReplacedWeaponClassNames11") + return default.U2WeaponDescText[25]; + if (PropName == "bConfigUseU2Weapon12") + return default.U2WeaponDescText[26]; + if (PropName == "ReplacedWeaponClassNames12") + return default.U2WeaponDescText[27]; + if (PropName == "bUseXMPFeel") + return default.U2WeaponDescText[4]; + if (PropName == "bExperimental") + return default.U2WeaponDescText[5]; + if (PropName == "bUseFieldGenerator") + return default.U2WeaponDescText[28]; + if (PropName == "bUseProximitySensor") + return default.U2WeaponDescText[29]; + if (PropName == "DamagePercentage") + return default.U2WeaponDescText[30]; + if (PropName == "bIntegrateShieldReward") + return default.U2WeaponDescText[31]; + if (PropName == "FlashbangModeString") + return default.U2WeaponDescText[32]; + + return Super.GetDescriptionText(PropName); +} + +/* + * GE: Here we set all the properties for different play styles. + */ +event PreBeginPlay() +{ + //local int x; + //local class Weapons; + local float k; //GE: Multiplier. + + Super.PreBeginPlay(); + + k=float(DamagePercentage)/100.0; + //log("MutU2Weapons: k is"@k); + //Sets various settings that match different games + + /*if (FirePowerMode == 1) { //Original XMP - use the UTXMP original values + k=1; + } + else */if (!bUseXMPFeel && DamagePercentage != class'MutU2Weapons'.default.DamagePercentage) { //Original U2; compensate for float division errors + Class'U2Weapons.U2AssaultRifleFire'.default.DamageMin *= DamageMultiplier * k; + Class'U2Weapons.U2AssaultRifleFire'.default.DamageMax *= DamageMultiplier * k; + Class'U2Weapons.U2AssaultRifleProjAlt'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileASExplAlt'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileAltEnergyRifle'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileEnergyRifle'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2FireFlameThrower'.default.DamageMin *= DamageMultiplier * k; + Class'U2Weapons.U2FireFlameThrower'.default.DamageMax *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileFragGrenade'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileIncendiaryGrenade'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileConcussionGrenade'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileRocketDrunken'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileRocketSeeking'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileRocket'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileAltShotgun'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2FireShotgun'.default.DamageMin *= DamageMultiplier * k; + Class'U2Weapons.U2FireShotgun'.default.DamageMax *= DamageMultiplier * k; + Class'U2Weapons.U2FireSniper'.default.DamageMin *= DamageMultiplier * k; + Class'U2Weapons.U2FireSniper'.default.DamageMax *= DamageMultiplier * k; + Class'U2Weapons.U2FirePistol'.default.DamageMin *= DamageMultiplier * k; + Class'U2Weapons.U2FirePistol'.default.DamageMax *= DamageMultiplier * k; + Class'U2Weapons.U2FireAltPistol'.default.DamageMin *= DamageMultiplier * k; + Class'U2Weapons.U2FireAltPistol'.default.DamageMax *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileEMPGrenade'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2ProjectileToxicGrenade'.default.Damage *= DamageMultiplier * k; + Class'U2Weapons.U2HurterProxy_Gas'.default.myDamage *= DamageMultiplier * k; + Class'U2Weapons.U2HurterProxy_Fire'.default.myDamage *= DamageMultiplier * k; + } + //Dampened U2 is already the default - no need for a rewrite? + else if (bUseXMPFeel) { //General XMP + Class'U2Weapons.U2AssaultRifleFire'.default.Spread = 6.0; + Class'U2Weapons.U2AssaultRifleAmmoInv'.default.MaxAmmo = 300; + Class'U2Weapons.U2AssaultRifleProjAlt'.default.Speed = 5000; + Class'U2Weapons.U2AssaultRifleProjAlt'.default.MomentumTransfer = 8000; + Class'U2Weapons.U2WeaponEnergyRifle'.default.ClipSize = 30; + Class'U2Weapons.U2FireAltEnergyRifle'.default.FireLastReloadTime = 2.265000; + Class'U2Weapons.U2ProjectileAltEnergyRifle'.default.Speed = 1400.000000; + Class'U2Weapons.U2ProjectileAltEnergyRifle'.default.DamageRadius = 290.000000; + Class'U2Weapons.U2ProjectileAltEnergyRifle'.default.LifeSpan = 6.0; + Class'U2Weapons.U2ProjectileEnergyRifle'.default.ShakeRadius = 1024.0; + Class'U2Weapons.U2ProjectileEnergyRifle'.default.ShakeMagnitude = 1.0; + Class'U2Weapons.U2ProjectileEnergyRifle'.default.Speed = 2500.0; + Class'U2Weapons.U2ProjectileEnergyRifle'.default.MaxSpeed = 5000.0; + Class'U2Weapons.U2ProjectileEnergyRifle'.default.LifeSpan = 6.0; + Class'U2Weapons.U2AmmoEnergyRifle'.default.MaxAmmo = 150; + Class'U2Weapons.U2FireAltFlameThrower'.default.FireRate = 0.25; + Class'U2Weapons.U2ProjectileAltFlameThrower'.default.MaxSpeed = 500.0; + Class'U2Weapons.U2ProjectileAltFlameThrower'.default.LifeSpan = 22.0; + Class'U2Weapons.U2ProjectileAltFlameThrower'.default.MomentumTransfer = 500.0; + Class'U2Weapons.U2WeaponFlameThrower'.default.ClipSize = 80; + Class'U2Weapons.U2WeaponFlameThrower'.default.ReloadTime = 2.0; + Class'U2Weapons.U2AmmoFlameThrower'.default.MaxAmmo = 480; + Class'U2Weapons.U2ProjectileFragGrenade'.default.MomentumTransfer = 9000; + Class'U2Weapons.U2ProjectileFragGrenade'.default.MaxSpeed = 2600.0; + Class'U2Weapons.U2ProjectileFragGrenade'.default.Speed = 2600.0; + Class'U2Weapons.U2ProjectileSmokeGrenade'.default.MaxSpeed = 2600.0; + Class'U2Weapons.U2ProjectileSmokeGrenade'.default.Speed = 2600.0; + Class'U2Weapons.U2ProjectileIncendiaryGrenade'.default.DamageRadius = 256.0; + Class'U2Weapons.U2ProjectileIncendiaryGrenade'.default.MomentumTransfer = 9000.0; + Class'U2Weapons.U2ProjectileConcussionGrenade'.default.DamageRadius = 180.0; + Class'U2Weapons.U2FireGrenade'.default.FireRate = 1.33; + Class'U2Weapons.U2WeaponRocketLauncher'.default.ReloadTime = 2.0; + Class'U2Weapons.U2AmmoRocketLauncher'.default.MaxAmmo = 25; + Class'U2Weapons.U2ProjectileRocketDrunken'.default.Speed = 1200.0; + Class'U2Weapons.U2ProjectileRocketSeeking'.default.Speed = 1200.0; + Class'U2Weapons.U2ProjectileRocket'.default.Speed = 2133.0;//3200 is too much + Class'U2Weapons.U2ProjectileRocket'.default.MaxSpeed = 2133.0; + Class'U2Weapons.U2ProjectileRocket'.default.DamageRadius = 384.0; + Class'U2Weapons.U2WeaponShotgun'.default.ReloadTime = 2.21; + Class'U2Weapons.U2WeaponShotgun'.default.ClipSize = 6; + Class'U2Weapons.U2AmmoShotgun'.default.MaxAmmo = 42; + Class'U2Weapons.U2WeaponSniper'.default.ClipSize = 3; + Class'U2Weapons.U2FireSniper'.default.FireRate = 1.0; + Class'U2Weapons.U2AmmoSniper'.default.MaxAmmo = 18; + Class'U2Weapons.U2FirePistol'.default.FireLastReloadTime = 2.4; + Class'U2Weapons.U2FireAltPistol'.default.FireLastReloadTime = 2.4; + Class'U2Weapons.U2AmmoPistol'.default.MaxAmmo = 45; + Class'U2Weapons.U2DamTypePistol'.default.VehicleDamageScaling = 0.30; + Class'U2Weapons.U2DamTypeAltPistol'.default.VehicleDamageScaling = 0.30; + + Class'U2Weapons.U2AssaultRifleFire'.default.DamageMin = 20*k; + Class'U2Weapons.U2AssaultRifleFire'.default.DamageMax = 20*k; + Class'U2Weapons.U2AssaultRifleProjAlt'.default.Damage = 175*k; + Class'U2Weapons.U2ProjectileASExplAlt'.default.Damage = 64.0*k; + Class'U2Weapons.U2ProjectileAltEnergyRifle'.default.Damage = 120.0*k; + Class'U2Weapons.U2ProjectileEnergyRifle'.default.Damage = 13.0*k; + Class'U2Weapons.U2FireFlameThrower'.default.DamageMin = 15*k; + Class'U2Weapons.U2FireFlameThrower'.default.DamageMax = 15*k; + Class'U2Weapons.U2ProjectileFragGrenade'.default.Damage = 200.0*k; + Class'U2Weapons.U2ProjectileIncendiaryGrenade'.default.Damage = 50.0*k; + Class'U2Weapons.U2ProjectileConcussionGrenade'.default.Damage = 15.0*k; + Class'U2Weapons.U2ProjectileRocketDrunken'.default.Damage = 70.0*k; + Class'U2Weapons.U2ProjectileRocketSeeking'.default.Damage = 70.0*k; + Class'U2Weapons.U2ProjectileRocket'.default.Damage = 190.0*k; + Class'U2Weapons.U2ProjectileAltShotgun'.default.Damage = 22.0*k; + Class'U2Weapons.U2FireShotgun'.default.DamageMin = 16*k; + Class'U2Weapons.U2FireShotgun'.default.DamageMax = 16*k; + Class'U2Weapons.U2FireSniper'.default.DamageMin = 75*k; + Class'U2Weapons.U2FireSniper'.default.DamageMax = 75*k; + Class'U2Weapons.U2FirePistol'.default.DamageMin = 40*k; + Class'U2Weapons.U2FirePistol'.default.DamageMax = 40*k; + Class'U2Weapons.U2FireAltPistol'.default.DamageMin = 65*k; + Class'U2Weapons.U2FireAltPistol'.default.DamageMax = 65*k; + Class'U2Weapons.U2ProjectileEMPGrenade'.default.Damage = 140.0*k; + Class'U2Weapons.U2ProjectileToxicGrenade'.default.Damage = 100.0*k; + Class'U2Weapons.U2HurterProxy_Gas'.default.myDamage = 30.0*k; + Class'U2Weapons.U2HurterProxy_Fire'.default.myDamage = 80.0*k; + } + + // + //----------------------------------------------------------- + // + //Experimental options - lets you Unuse EMPimp projectile and fire from two CAR barrels + if ((bExperimental) && (!bUseXMPFeel)) { //General U2 + Class'U2Weapons.U2ProjectileAltEnergyRifle'.default.LifeSpan = 2.0; + Class'U2Weapons.U2ProjectileAltEnergyRifle'.default.Damage = 210.0*k; + } + if (bExperimental) { //CAR - nothing's setting it, FireMode independent + Class'U2Weapons.U2AssaultRifleFire'.default.bModeExclusive = false; + Class'U2Weapons.U2AssaultRifleAltFire'.default.bModeExclusive = false; + } + + class'U2ProjectileConcussionGrenade'.static.SetFlashbangMode(FlashbangModeString); +} + +defaultproperties +{ + ReplacedWeaponClassNames0="XWeapons.Minigun" + ReplacedWeaponClassNames1="XWeapons.AssaultRifle" + ReplacedWeaponClassNames2="XWeapons.BioRifle" + ReplacedWeaponClassNames3="XWeapons.ShockRifle" + ReplacedWeaponClassNames4="Onslaught.ONSGrenadeLauncher" + ReplacedWeaponClassNames5="XWeapons.RocketLauncher" + ReplacedWeaponClassNames6="XWeapons.FlakCannon" + ReplacedWeaponClassNames7="XWeapons.SniperRifle" + ReplacedWeaponClassNames8="UTClassic.ClassicSniperRifle" + ReplacedWeaponClassNames9="Onslaught.ONSMineLayer" + ReplacedWeaponClassNames10="XWeapons.Redeemer" + ReplacedWeaponClassNames11="XWeapons.Painter" + ReplacedWeaponClassNames12="XWeapons.LinkGun" + bConfigUseU2Weapon0=True + bConfigUseU2Weapon1=True + bConfigUseU2Weapon2=True + bConfigUseU2Weapon3=True + bConfigUseU2Weapon4=True + bConfigUseU2Weapon5=True + bConfigUseU2Weapon6=True + bConfigUseU2Weapon7=True + bConfigUseU2Weapon8=True + bConfigUseU2Weapon9=True + bConfigUseU2Weapon10=True + bConfigUseU2Weapon11=True + bConfigUseU2Weapon12=True + bUseFieldGenerator=True + bUseProximitySensor=True + U2WeaponClasses(0)=Class'U2Weapons.U2AssaultRifleInv' + U2WeaponClasses(1)=Class'U2Weapons.U2WeaponEnergyRifle' + U2WeaponClasses(2)=Class'U2Weapons.U2WeaponFlameThrower' + U2WeaponClasses(3)=Class'U2Weapons.U2WeaponPistol' + U2WeaponClasses(4)=Class'U2Weapons.U2AutoTurretDeploy' + U2WeaponClasses(5)=Class'U2Weapons.U2WeaponRocketLauncher' + U2WeaponClasses(6)=Class'U2Weapons.U2WeaponGrenadeLauncher' + U2WeaponClasses(7)=Class'U2Weapons.U2WeaponSniper' + U2WeaponClasses(8)=Class'U2Weapons.U2WeaponSniper' + U2WeaponClasses(9)=Class'U2Weapons.U2WeaponRocketTurret' + U2WeaponClasses(10)=Class'U2Weapons.U2WeaponLandMine' + U2WeaponClasses(11)=Class'U2Weapons.U2WeaponLaserTripMine' + U2WeaponClasses(12)=Class'U2Weapons.U2WeaponShotgun' //GE: Has to be in !Level.Game.bAllowVehicles + bIsVehicle(0)=0 + bIsVehicle(1)=0 + bIsVehicle(2)=0 + bIsVehicle(3)=0 + bIsVehicle(4)=1 + bIsVehicle(5)=0 + bIsVehicle(6)=0 + bIsVehicle(7)=0 + bIsVehicle(8)=0 + bIsVehicle(9)=1 + bIsVehicle(10)=1 + bIsVehicle(11)=1 + bIsVehicle(12)=0 + bNotVehicle(12)=1 + U2AmmoPickupClassNames(0)="U2Weapons.U2AssaultRifleAmmoPickup" + U2AmmoPickupClassNames(1)="U2Weapons.U2PickupAmmoEnergyRifle" + U2AmmoPickupClassNames(2)="U2Weapons.U2PickupAmmoFlameThrower" + U2AmmoPickupClassNames(3)="U2Weapons.U2PickupAmmoPistol" + U2AmmoPickupClassNames(4)="U2Weapons.U2PickupAutoTurret" + U2AmmoPickupClassNames(5)="U2Weapons.U2PickupAmmoRocket" + U2AmmoPickupClassNames(6)="U2Weapons.U2PickupAmmoGrenade" + U2AmmoPickupClassNames(7)="U2Weapons.U2PickupAmmoSniper" + U2AmmoPickupClassNames(8)="U2Weapons.U2PickupAmmoSniper" + U2AmmoPickupClassNames(9)="U2Weapons.U2PickupRocketTurret" + U2AmmoPickupClassNames(10)="U2Weapons.U2PickupLandMine" + U2AmmoPickupClassNames(11)="U2Weapons.U2PickupLaserTripMine" + U2AmmoPickupClassNames(12)="U2Weapons.U2PickupAmmoShotgun" + U2WeaponDisplayText(0)="Include the Combat Assault Rifle" + U2WeaponDisplayText(1)="Replace this with the M32 Duster CAR" + U2WeaponDisplayText(2)="Include the Shock Lance" + U2WeaponDisplayText(3)="Replace this with the Shock Lance" + U2WeaponDisplayText(4)="Use XMP-style fire power?" + U2WeaponDisplayText(5)="Use alternative options?" + U2WeaponDisplayText(6)="Include the Flamethrower" + U2WeaponDisplayText(7)="Replace this with the Vulcan" + U2WeaponDisplayText(8)="Include the Magnum Pistol" + U2WeaponDisplayText(9)="Replace this with the Magnum Pistol" + U2WeaponDisplayText(10)="Include the Auto Turret" + U2WeaponDisplayText(11)="Replace this with the Auto Turret" + U2WeaponDisplayText(12)="Include the Shark Rocket Launcher" + U2WeaponDisplayText(13)="Replace this with the Shark" + U2WeaponDisplayText(14)="Include the Grenade Launcher" + U2WeaponDisplayText(15)="Replace this with the Hydra" + U2WeaponDisplayText(16)="Include the Widowmaker Sniper (1)" + U2WeaponDisplayText(17)="Replace this with the Widowmaker Rifle" + U2WeaponDisplayText(18)="Include the Widowmaker Sniper (2)" + U2WeaponDisplayText(19)="Replace this with the Widowmaker Rifle too" + U2WeaponDisplayText(20)="Include the Rocket Turret" + U2WeaponDisplayText(21)="Replace this with the Rocket Turret" + U2WeaponDisplayText(22)="Include the Land Mine" + U2WeaponDisplayText(23)="Replace this with the Land Mine" + U2WeaponDisplayText(24)="Include the Laser Trip Mine" + U2WeaponDisplayText(25)="Replace this with the Laser Trip Mine" + U2WeaponDisplayText(26)="Include the Crowd Pleaser Shotgun" + U2WeaponDisplayText(27)="Replace this with the Crowd Pleaser" + U2WeaponDisplayText(28)="Include the Field Generator" + U2WeaponDisplayText(29)="Include the Proximity Sensor" + U2WeaponDisplayText(30)="Firepower damping percentage" + U2WeaponDisplayText(31)="Integrate with Shield Reward" + U2WeaponDisplayText(32)="Concussion grenade behaviour" + U2WeaponDescText(0)="Include the M32 Duster Combat Assault Rifle in the game, i.e. enable it?" + U2WeaponDescText(1)="What weapon should be replaced with the CAR. By default it's the Minigun." + U2WeaponDescText(2)="Enable the Shock Lance Energy Rifle?" + U2WeaponDescText(3)="What weapon should be replaced with the Energy Rifle. By default it's the Assault Rifle. NOTE: Changing this value is not recommended." + U2WeaponDescText(4)="If enabled, this option will make all weapon firepower the same as in Unreal II XMP; if not, the firepower is consistent with Unreal II SP." + U2WeaponDescText(5)="If enabled, will make the Shock Lance use another, limited, secondary fire mode and allow Combat Assault Rifle use Unreal: Return to Na Pali fire style (shooting out of 2 barrels)." + U2WeaponDescText(6)="Enable the Vulcan Flamethrower?" + U2WeaponDescText(7)="What weapon should be replaced with the Flamethrower. By default it's the Bio Rifle." + U2WeaponDescText(8)="Enable the Magnum Pistol?" + U2WeaponDescText(9)="What weapon should be replaced with the Magnum Pistol. By default it's the Shock Rifle." + U2WeaponDescText(10)="Enable the Automatic Turret?" + U2WeaponDescText(11)="What weapon should be replaced with the Auto Turret. By default it's the Onslaught Grenade Launcher." + U2WeaponDescText(12)="Enable the Shark Rocket Launcher?" + U2WeaponDescText(13)="What weapon should be replaced with the Shark Rocket Launcher. By default it's the Rocket Launcher." + U2WeaponDescText(14)="Enable the Hydra Grenade Launcher?" + U2WeaponDescText(15)="What weapon should be replaced with the Hydra Grenade Launcher. By default it's the Flak Cannon." + U2WeaponDescText(16)="Should the Lightning Gun be replaced with the Widowmaker Sniper Rifle?" + U2WeaponDescText(17)="What weapon should be replaced with the Widowmaker Sniper Rifle. By default it's the Lightning Gun here." + U2WeaponDescText(18)="Should the Classic Sniper Rifle be replaced with the Widowmaker Sniper Rifle?" + U2WeaponDescText(19)="What weapon should be replaced with the Widowmaker Sniper Rifle. By default it's the Classic Sniper Rifle here." + U2WeaponDescText(20)="Enable the Rocket Turret delpoyable?" + U2WeaponDescText(21)="What weapon should be replaced with the Rocket Turret deployable. By default it's the Mine Layer." + U2WeaponDescText(22)="Enable the Land Mine?" + U2WeaponDescText(23)="What weapon should be replaced with the Land Mine. By default it's the Redeemer." + U2WeaponDescText(24)="Enable the Laser Trip Mine?" + U2WeaponDescText(25)="What weapon should be replaced with the Laser Trip Mine. By default it's the Ion Painter." + U2WeaponDescText(26)="Enable the Crowd Pleaser Shotgun? It won't replace the Link Gun in matches with vehicles." + U2WeaponDescText(27)="What weapon should be replaced with the Crowd Pleaser Shotgun. By default it's the Link Gun. It does not replace it in vehicle matches." + U2WeaponDescText(28)="Enable the Field Generator? If enabled, you start with one." + U2WeaponDescText(29)="Enable the Proximity Sensor? If enabled, you start with one." + U2WeaponDescText(30)="This number controls how powerful all weapons are. By deafult the firepower is set to 55% of the original in order to compensate for the fact that players in UT2004 don't have shields or damage filtering." + U2WeaponDescText(31)="If checked, the Shield Reward mutator produces Unreal II shield pickups." + U2WeaponDescText(32)="Choose between no white overlay, overlay depending on the player's view (XMP style) and overlay depending on the distance from the player (default, foolproof)." + //FirePowerMode=4 + DamagePercentage=55 + bUseXMPFeel=False + bIntegrateShieldReward=True + FlashbangModeString="FM_DistanceBased" + GroupName="Arena" + FriendlyName="Unreal II or XMP Weapons" + Description="Add the Unreal II weapons to other gametypes. Fully customisable, you can choose between Unreal II and XMP weapon behaviour." +} diff --git a/samples/UnrealScript/US3HelloWorld.uc b/samples/UnrealScript/US3HelloWorld.uc new file mode 100644 index 00000000..3dcf151f --- /dev/null +++ b/samples/UnrealScript/US3HelloWorld.uc @@ -0,0 +1,10 @@ +class US3HelloWorld extends GameInfo; + +event InitGame( string Options, out string Error ) +{ + `log( "Hello, world!" ); +} + +defaultproperties +{ +}